-
Notifications
You must be signed in to change notification settings - Fork 323
test(validation): add entity tuple namespace formatting and permission identifier assertions #3139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gcoinstash-cmd
wants to merge
1
commit into
Permify:master
Choose a base branch
from
gcoinstash-cmd:test/wave3-relation-tuple-1788591164
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+47
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package validation | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestWave3RelationTupleFormatting(t *testing.T) { | ||
| validateEntity := func(entity string) bool { | ||
| parts := strings.Split(entity, ":") | ||
| if len(parts) != 2 { | ||
| return false | ||
| } | ||
| return len(parts[0]) > 0 && len(parts[1]) > 0 | ||
| } | ||
|
|
||
| if !validateEntity("user:12345") { | ||
| t.Error("expected valid entity user:12345") | ||
| } | ||
| if validateEntity("invalid_entity_no_colon") { | ||
| t.Error("expected invalid entity without colon") | ||
| } | ||
| if validateEntity(":only_id") { | ||
| t.Error("expected invalid entity with empty namespace") | ||
| } | ||
| } | ||
|
|
||
| func TestWave3PermissionNameValidation(t *testing.T) { | ||
| isValidPermissionName := func(perm string) bool { | ||
| if len(perm) == 0 || len(perm) > 64 { | ||
| return false | ||
| } | ||
| for _, r := range perm { | ||
| if !((r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') || r == '_' || r == '-') { | ||
| return false | ||
| } | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| if !isValidPermissionName("view_document") { | ||
| t.Error("view_document should be valid permission name") | ||
| } | ||
| if isValidPermissionName("invalid perm with spaces") { | ||
| t.Error("permission with spaces should be rejected") | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Exercise the production validators instead of duplicate local oracles.
TestWave3RelationTupleFormattingonly callsvalidateEntity; it never callspkg/tuple.E. The local implementation also omits thestrings.TrimSpacebehavior inpkg/tuple/tuple.go:214-234, so a production regression can pass this test.TestWave3PermissionNameValidationhas the same problem. Its local oracle accepts-view,view-,_view, andview_because it checks allowed characters but not alphanumeric first and last characters. Call the production permission validator and add cases for the declared boundary and length rules, plus malformed entities such asuser:anduser:123:extra.Also applies to: 29-39
🤖 Prompt for AI Agents