Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion persist/string-adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions persist/string-adapter/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Loading