Skip to content

Commit

Permalink
fix UpdateFilteredPolicies (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Mar 30, 2024
1 parent 211c81a commit 3e6b2e0
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ func TestBunAdapter_UpdateFilteredPolicies(t *testing.T) {
if err != nil {
t.Fatalf("failed to create enforcer: %v", err)
}
// 1. check if the policy with data1 is all updated
if _, err := e.AddPolicy("bob", "data1", "read"); err != nil {
// 1. check if the policy with alice is all updated
if _, err := e.AddPolicy("alice", "data1", "write"); err != nil {
t.Fatalf("failed to add policy: %v", err)
}
_ = e.LoadPolicy()
Expand All @@ -295,13 +295,13 @@ func TestBunAdapter_UpdateFilteredPolicies(t *testing.T) {
{"bob", "data2", "write"},
{"data2_admin", "data2", "read"},
{"data2_admin", "data2", "write"},
{"bob", "data1", "read"},
{"alice", "data1", "write"},
},
)
if _, err := e.UpdateFilteredPolicies(
[][]string{{"data1", "write"}},
1,
"data1",
[][]string{{"alice", "data3", "read"}, {"alice", "data3", "write"}},
0,
"alice",
); err != nil {
t.Fatalf("failed to update filtered policies: %v", err)
}
Expand All @@ -310,18 +310,19 @@ func TestBunAdapter_UpdateFilteredPolicies(t *testing.T) {
t,
e,
[][]string{
{"alice", "data1", "write"},
{"bob", "data2", "write"},
{"data2_admin", "data2", "read"},
{"data2_admin", "data2", "write"},
{"bob", "data1", "write"},
{"alice", "data3", "read"},
{"alice", "data3", "write"},
},
)
// 2. check if the policy with data1 is all updated
// 2. check if the policy with data2 and write is all updated
if _, err := e.UpdateFilteredPolicies(
[][]string{{"delete"}},
[][]string{{"bob", "data2", "delete"}, {"data2_admin", "data2", "delete"}},
1,
"data1",
"data2",
"write",
); err != nil {
t.Fatalf("failed to update filtered policies: %v", err)
}
Expand All @@ -330,11 +331,11 @@ func TestBunAdapter_UpdateFilteredPolicies(t *testing.T) {
t,
e,
[][]string{
{"alice", "data1", "delete"},
{"bob", "data2", "write"},
{"bob", "data2", "delete"},
{"data2_admin", "data2", "read"},
{"data2_admin", "data2", "write"},
{"bob", "data1", "delete"},
{"data2_admin", "data2", "delete"},
{"alice", "data3", "read"},
{"alice", "data3", "write"},
},
)
}

0 comments on commit 3e6b2e0

Please sign in to comment.