-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathplugin_test.lua
More file actions
40 lines (36 loc) · 1.5 KB
/
plugin_test.lua
File metadata and controls
40 lines (36 loc) · 1.5 KB
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
39
40
local http = require("socket.http")
local function isAuthorized(page, username, HTTPMethod)
local headers = {
["user"] = username,
["host"] = "example.com"
}
local _, code, _, _ = http.request{url = "http://127.0.0.1:8000" .. page, headers = headers, method = HTTPMethod}
if code == 403 then
return false
else
return true
end
end
describe("Plugin Tests", function ()
it("Homepage Tests", function ()
assert.is.True(isAuthorized("/", "anonymous", "GET"))
assert.is.True(isAuthorized("/", "alice", "GET"))
assert.is.False(isAuthorized("/", "anonymous", "POST"))
assert.is.True(isAuthorized("/", "alice", "POST"))
assert.is.True(isAuthorized("/", "alice", "PUT"))
end)
it("Resource Tests", function ()
assert.is.False(isAuthorized("/resource1", "anonymous", "GET"))
assert.is.True(isAuthorized("/resource1", "alice", "GET"))
assert.is.False(isAuthorized("/resource1", "anonymous", "POST"))
assert.is.True(isAuthorized("/resource1", "alice", "POST"))
assert.is.False(isAuthorized("/dataset1/res1", "anonymous", "GET"))
assert.is.True(isAuthorized("/dataset1/res1", "alice", "GET"))
end)
it("RBAC Tests", function ()
assert.is.True(isAuthorized("/", "admin", "GET"))
assert.is.True(isAuthorized("/", "alice", "GET"))
assert.is.True(isAuthorized("/res", "admin", "POST"))
assert.is.True(isAuthorized("/res", "alice", "POST"))
end)
end)