Skip to content

Commit b58a568

Browse files
committed
docs: add rebac model examples and tests
1 parent 992f818 commit b58a568

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

examples/rebac_model.conf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[request_definition]
2+
r = sub, obj, act
3+
4+
[policy_definition]
5+
p = role, obj_type, act
6+
7+
[role_definition]
8+
g = _, _, _
9+
g2 = _, _
10+
11+
[policy_effect]
12+
e = some(where (p.eft == allow))
13+
14+
[matchers]
15+
m = g(r.sub, r.obj, p.role) && g2(r.obj, p.obj_type) && r.act == p.act

examples/rebac_policy.csv

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
p, collaborator, doc, read
2+
3+
g, alice, doc1, collaborator
4+
g, bob, doc2, collaborator
5+
6+
g2, doc1, doc
7+
g2, doc2, doc

model_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,3 +680,21 @@ func TestTemporalRolesModelWithDomain(t *testing.T) {
680680
testDomainEnforce(t, e, "alice", "domain_not_exist", "data8", "read", false)
681681
testDomainEnforce(t, e, "alice", "domain_not_exist", "data8", "write", false)
682682
}
683+
684+
func TestReBACModel(t *testing.T) {
685+
e, _ := NewEnforcer("examples/rebac_model.conf", "examples/rebac_policy.csv")
686+
687+
testEnforce(t, e, "alice", "doc1", "read", true)
688+
testEnforce(t, e, "alice", "doc1", "write", false)
689+
testEnforce(t, e, "alice", "doc2", "read", false)
690+
testEnforce(t, e, "alice", "doc2", "write", false)
691+
testEnforce(t, e, "alice", "doc3", "read", false)
692+
testEnforce(t, e, "alice", "doc3", "write", false)
693+
694+
testEnforce(t, e, "bob", "doc1", "read", false)
695+
testEnforce(t, e, "bob", "doc1", "write", false)
696+
testEnforce(t, e, "bob", "doc2", "read", true)
697+
testEnforce(t, e, "bob", "doc2", "write", false)
698+
testEnforce(t, e, "bob", "doc3", "read", false)
699+
testEnforce(t, e, "bob", "doc3", "write", false)
700+
}

0 commit comments

Comments
 (0)