MCPcopy
hub / github.com/apache/casbin / TestConstraintParsingError

Function TestConstraintParsingError

constraint_test.go:258–286  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

256}
257
258func TestConstraintParsingError(t *testing.T) {
259 modelText := `
260[request_definition]
261r = sub, obj, act
262
263[policy_definition]
264p = sub, obj, act
265
266[role_definition]
267g = _, _
268
269[constraint_definition]
270c = invalidFunction("role1", "role2")
271
272[policy_effect]
273e = some(where (p.eft == allow))
274
275[matchers]
276m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act
277`
278
279 _, err := model.NewModelFromString(modelText)
280 if err == nil {
281 t.Fatal("Expected parsing error for invalid constraint, got nil")
282 }
283 if !strings.Contains(err.Error(), "constraint parsing error") {
284 t.Fatalf("Expected constraint parsing error, got: %v", err)
285 }
286}
287
288func TestConstraintRollback(t *testing.T) {
289 modelText := `

Callers

nothing calls this directly

Calls 2

NewModelFromStringFunction · 0.92
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…