Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,30 @@ jobs:

- name: Install dependencies
run: |
luarocks install lualogging
luarocks install lrexlib-pcre2
luarocks install luaposix
luarocks install luasocket
luarocks install busted
luarocks install busted-htest
until luarocks install lualogging
do
sleep 1
done
until luarocks install lrexlib-pcre2
do
sleep 1
done
until luarocks install luaposix
do
sleep 1
done
until luarocks install luasocket
do
sleep 1
done
until luarocks install busted
do
sleep 1
done
until luarocks install busted-htest
do
sleep 1
done

- name: Run Benchmark
run: |
Expand Down
14 changes: 14 additions & 0 deletions examples/keymatch4_model.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[request_definition]
r = sub, obj, act

[policy_definition]
p = sub, obj, act

[role_definition]
g = _, _

[policy_effect]
e = some(where (p.eft == allow))

[matchers]
m = g(r.sub, p.sub) && keyMatch4(r.obj, p.obj) && regexMatch(r.act, p.act)
4 changes: 4 additions & 0 deletions examples/keymatch4_policy.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
p, alice, /parent/{id}/child/{id}, GET|POST
p, bob, /parent/{id}/child/{another_id}, GET|POST
g, alice, alice
g, bob, bob
6 changes: 4 additions & 2 deletions src/main/CoreEnforcer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@ function CoreEnforcer:enforceEx(...)
res, err = luaxp.evaluate(tExpString, context)
end
if err then
error("evaluation error: " .. err.message)
local errMsg = type(err) == "table" and err.message or tostring(err)
error("evaluation error: " .. errMsg)
end

local c = true
Expand Down Expand Up @@ -491,7 +492,8 @@ function CoreEnforcer:enforceEx(...)

local res, err = luaxp.run(compiledExpression, context)
if err then
error("evaluation error: " .. err.message)
local errMsg = type(err) == "table" and err.message or tostring(err)
error("evaluation error: " .. errMsg)
end

if res then
Expand Down
15 changes: 15 additions & 0 deletions tests/main/enforcer_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ describe("Enforcer tests", function ()
assert.is.True(e:enforce("alice", "/alice_data2/123/using/456", "GET"))
end)

it("keyMatch4 test", function ()
local model = path .. "/examples/keymatch4_model.conf"
local policy = path .. "/examples/keymatch4_policy.csv"

local e = Enforcer:new(model, policy)
-- Test alice with matching IDs (same placeholder value)
assert.is.True(e:enforce("alice", "/parent/123/child/123", "GET"))
assert.is.True(e:enforce("alice", "/parent/456/child/456", "POST"))
-- Test alice with non-matching IDs (different placeholder values)
assert.is.False(e:enforce("alice", "/parent/123/child/456", "GET"))
-- Test bob with different IDs (different placeholders, should work)
assert.is.True(e:enforce("bob", "/parent/123/child/456", "GET"))
assert.is.True(e:enforce("bob", "/parent/789/child/012", "POST"))
end)

it("priority test", function ()
local model = path .. "/examples/priority_model.conf"
local policy = path .. "/examples/priority_policy.csv"
Expand Down
Loading