(t *testing.T)
| 191 | } |
| 192 | |
| 193 | func TestPermissionAPI(t *testing.T) { |
| 194 | e := newTestEngine(t, "file", "../examples/basic_without_resources_policy.csv", |
| 195 | "../examples/basic_without_resources_model.conf") |
| 196 | |
| 197 | testEnforceWithoutUsers(t, e, "alice", "read", true) |
| 198 | testEnforceWithoutUsers(t, e, "alice", "write", false) |
| 199 | testEnforceWithoutUsers(t, e, "bob", "read", false) |
| 200 | testEnforceWithoutUsers(t, e, "bob", "write", true) |
| 201 | |
| 202 | testGetPermissions(t, e, "alice", [][]string{{"alice", "read"}}) |
| 203 | testGetPermissions(t, e, "bob", [][]string{{"bob", "write"}}) |
| 204 | |
| 205 | testHasPermission(t, e, "alice", []string{"read"}, true) |
| 206 | testHasPermission(t, e, "alice", []string{"write"}, false) |
| 207 | testHasPermission(t, e, "bob", []string{"read"}, false) |
| 208 | testHasPermission(t, e, "bob", []string{"write"}, true) |
| 209 | |
| 210 | _, err := e.s.DeletePermission(e.ctx, &pb.PermissionRequest{EnforcerHandler: e.h, Permissions: []string{"read"}}) |
| 211 | assert.NoError(t, err) |
| 212 | |
| 213 | testEnforceWithoutUsers(t, e, "alice", "read", false) |
| 214 | testEnforceWithoutUsers(t, e, "alice", "write", false) |
| 215 | testEnforceWithoutUsers(t, e, "bob", "read", false) |
| 216 | testEnforceWithoutUsers(t, e, "bob", "write", true) |
| 217 | |
| 218 | _, err = e.s.AddPermissionForUser(e.ctx, &pb.PermissionRequest{EnforcerHandler: e.h, User: "bob", Permissions: []string{"read"}}) |
| 219 | assert.NoError(t, err) |
| 220 | |
| 221 | testEnforceWithoutUsers(t, e, "alice", "read", false) |
| 222 | testEnforceWithoutUsers(t, e, "alice", "write", false) |
| 223 | testEnforceWithoutUsers(t, e, "bob", "read", true) |
| 224 | testEnforceWithoutUsers(t, e, "bob", "write", true) |
| 225 | |
| 226 | _, err = e.s.DeletePermissionForUser(e.ctx, &pb.PermissionRequest{EnforcerHandler: e.h, User: "bob", Permissions: []string{"read"}}) |
| 227 | assert.NoError(t, err) |
| 228 | |
| 229 | testEnforceWithoutUsers(t, e, "alice", "read", false) |
| 230 | testEnforceWithoutUsers(t, e, "alice", "write", false) |
| 231 | testEnforceWithoutUsers(t, e, "bob", "read", false) |
| 232 | testEnforceWithoutUsers(t, e, "bob", "write", true) |
| 233 | |
| 234 | _, err = e.s.DeletePermissionsForUser(e.ctx, &pb.PermissionRequest{EnforcerHandler: e.h, User: "bob"}) |
| 235 | assert.NoError(t, err) |
| 236 | |
| 237 | testEnforceWithoutUsers(t, e, "alice", "read", false) |
| 238 | testEnforceWithoutUsers(t, e, "alice", "write", false) |
| 239 | testEnforceWithoutUsers(t, e, "bob", "read", false) |
| 240 | testEnforceWithoutUsers(t, e, "bob", "write", false) |
| 241 | } |
| 242 | |
| 243 | func testGetDomains(t *testing.T, e *testEngine, name string, res []string) { |
| 244 | t.Helper() |
nothing calls this directly
no test coverage detected