diff --git a/persist/string-adapter/adapter.go b/persist/string-adapter/adapter.go index 031f80b5e..75f5d73c8 100644 --- a/persist/string-adapter/adapter.go +++ b/persist/string-adapter/adapter.go @@ -49,7 +49,9 @@ func (a *Adapter) LoadPolicy(model model.Model) error { if str == "" { continue } - _ = persist.LoadPolicyLine(str, model) + if err := persist.LoadPolicyLine(str, model); err != nil { + return err + } } return nil diff --git a/persist/string-adapter/adapter_test.go b/persist/string-adapter/adapter_test.go index 620e8f41a..9ab40e8a3 100644 --- a/persist/string-adapter/adapter_test.go +++ b/persist/string-adapter/adapter_test.go @@ -171,3 +171,16 @@ g, alice, data_group_admin t.Error("unexpected enforce result") } } + +// Test_LoadPolicyMalformedLine verifies that a malformed policy line (here an +// unterminated quoted field) makes LoadPolicy return an error instead of +// silently producing a model that lacks the rule. +func Test_LoadPolicyMalformedLine(t *testing.T) { + a := NewAdapter(`p, alice, data1, "read`) + m := model.NewModel() + + err := a.LoadPolicy(m) + if err == nil { + t.Fatal("LoadPolicy() error = nil, want a parse error for the unterminated quoted field") + } +}