fix: propagate policy parse errors in string adapter LoadPolicy - #1755
Draft
zjncs wants to merge 1 commit into
Draft
fix: propagate policy parse errors in string adapter LoadPolicy#1755zjncs wants to merge 1 commit into
zjncs wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
stringadapter.Adapter.LoadPolicydiscards the error returned bypersist.LoadPolicyLine:A malformed line (e.g. an unterminated quoted field:
p, alice, data1, "read) is therefore silently skipped:LoadPolicyreturnsnil, the model simply lacks the rule, andEnforcereturnsfalsewith no error — the caller has no way to notice the typo'd policy.The file adapter propagates the same error (
persist/file-adapter/adapter.goloadPolicyFilereturnshandler(line, model)errors), andLoadPolicyLine/LoadPolicyArrayreturn errors precisely so callers can report malformed policies (see also #1106). This PR aligns the string adapter with that contract by returning the error.Testing
Test_LoadPolicyMalformedLineinpersist/string-adapter/adapter_test.go: an adapter line with an unterminated quoted field must makeLoadPolicyreturn an error.LoadPolicy() error = nil, want a parse error for the unterminated quoted fieldTest_KeyMatchRbac,Test_SavePolicyRoundTripWithCommas,Test_StringRbac) still pass, and the fullgo test ./...suite passes (8 packages, no failures).go vet ./persist/string-adapter/clean.Behavior change is limited to inputs that previously produced a silently-wrong model; well-formed input loads exactly as before.
This PR was prepared with AI assistance (GitHub Copilot / ZCode autonomous agent). All findings were verified manually against the codebase before submission.