TestPermissionsAllKeyValidation tests the special 'all' key validation
(t *testing.T)
| 300 | |
| 301 | // TestPermissionsAllKeyValidation tests the special 'all' key validation |
| 302 | func TestPermissionsAllKeyValidation(t *testing.T) { |
| 303 | tests := []struct { |
| 304 | name string |
| 305 | permissions string |
| 306 | expectValid bool |
| 307 | description string |
| 308 | }{ |
| 309 | { |
| 310 | name: "all: read is valid", |
| 311 | permissions: "permissions:\n all: read", |
| 312 | expectValid: true, |
| 313 | description: "all: read grants read access to all scopes", |
| 314 | }, |
| 315 | { |
| 316 | name: "all: write is invalid", |
| 317 | permissions: "permissions:\n all: write", |
| 318 | expectValid: false, |
| 319 | description: "all: write is not allowed for security reasons", |
| 320 | }, |
| 321 | { |
| 322 | name: "all: read with other read permissions", |
| 323 | permissions: "permissions:\n all: read\n contents: read", |
| 324 | expectValid: true, |
| 325 | description: "all: read can be combined with other read permissions", |
| 326 | }, |
| 327 | { |
| 328 | name: "all: read with none permission is invalid", |
| 329 | permissions: "permissions:\n all: read\n contents: none", |
| 330 | expectValid: false, |
| 331 | description: "all: read cannot be combined with : none", |
| 332 | }, |
| 333 | } |
| 334 | |
| 335 | for _, tt := range tests { |
| 336 | t.Run(tt.name, func(t *testing.T) { |
| 337 | parser := NewPermissionsParser(tt.permissions) |
| 338 | |
| 339 | if tt.expectValid { |
| 340 | // For valid cases, check that parser processed them correctly |
| 341 | if parser.hasAll && parser.allLevel != "read" { |
| 342 | t.Errorf("%s: expected hasAll with level 'read', got level %q", tt.description, parser.allLevel) |
| 343 | } |
| 344 | } else { |
| 345 | // For invalid cases, the parser should not set hasAll for 'all: write' |
| 346 | // or should have empty parsedPerms for 'all: read' + ': none' combination |
| 347 | if parser.hasAll && len(parser.parsedPerms) == 0 { |
| 348 | // This might indicate the combination was rejected |
| 349 | return |
| 350 | } |
| 351 | if strings.Contains(tt.permissions, "all: write") && parser.hasAll { |
| 352 | t.Errorf("%s: 'all: write' should not be accepted", tt.description) |
| 353 | } |
| 354 | } |
| 355 | }) |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | // TestPermissionsScopeEnumValidation tests valid permission scope names |
nothing calls this directly
no test coverage detected