summaryrefslogtreecommitdiff
path: root/tests/test-access.lua
blob: 1afa71ed5d8190c3d7255301c5e3789a965b2a4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
-- See LICENSE file for copyright and license details.
local l = require "luxio"
local sio = require "luxio.simple"

local path = "ENOENTpath"

local r, errno = l.access(path, l.F_OK)
if r == -1 then
	io.stderr:write(("%s does not exist (PASS)\n"):format(path))
end

path = "luxio-test-access-test-file"

local r, errno = l.open(path, l.O_CREAT, sio.tomode("-rw-r--r--"))
if r == -1 then
	io.stderr:write(("open: %s (FAIL)\n"):format(l.strerror(errno)))
	os.exit(l.EXIT_FAILURE)
end

local r, errno = l.access(path, l.bit.bor(l.R_OK, l.W_OK))

if r == -1 then
	io.stderr:write(("access: %s (FAIL)\n"):format(l.strerror(errno)))
	os.exit(l.EXIT_FAILURE)
end

print(("Running user has read and write access to %s (PASS)"):format(path))

local r, errno = l.access(path, l.bit.bor(l.X_OK))
if r == 0 then
	io.stderr:write("Running user should not have execute perms")
	os.exit(l.EXIT_FAILURE)
end

print(("Running does not have execute access to %s (PASS)"):format(path))

-- Ignore errors here, but try and clean up
l.unlink(path)