(t *testing.T)
| 82 | } |
| 83 | |
| 84 | func TestABACModel(t *testing.T) { |
| 85 | s := NewServer() |
| 86 | ctx := context.Background() |
| 87 | |
| 88 | modelText, err := os.ReadFile("../examples/abac_model.conf") |
| 89 | if err != nil { |
| 90 | t.Error(err) |
| 91 | } |
| 92 | |
| 93 | resp, err := s.NewEnforcer(ctx, &pb.NewEnforcerRequest{ModelText: string(modelText), AdapterHandle: -1, EnableAcceptJsonRequest: false}) |
| 94 | if err != nil { |
| 95 | t.Error(err) |
| 96 | } |
| 97 | type ABACModel struct { |
| 98 | Name string |
| 99 | Owner string |
| 100 | } |
| 101 | e := resp.Handler |
| 102 | |
| 103 | data1, _ := MakeABAC(ABACModel{Name: "data1", Owner: "alice"}) |
| 104 | data2, _ := MakeABAC(ABACModel{Name: "data2", Owner: "bob"}) |
| 105 | |
| 106 | testModel(t, s, e, "alice", data1, "read", true) |
| 107 | testModel(t, s, e, "alice", data1, "write", true) |
| 108 | testModel(t, s, e, "alice", data2, "read", false) |
| 109 | testModel(t, s, e, "alice", data2, "write", false) |
| 110 | testModel(t, s, e, "bob", data1, "read", false) |
| 111 | testModel(t, s, e, "bob", data1, "write", false) |
| 112 | testModel(t, s, e, "bob", data2, "read", true) |
| 113 | testModel(t, s, e, "bob", data2, "write", true) |
| 114 | |
| 115 | } |
| 116 | |
| 117 | func testModel(t *testing.T, s *Server, enforcerHandler int32, sub string, obj string, act string, res bool) { |
| 118 | t.Helper() |
nothing calls this directly
no test coverage detected