TestExtractTokenParams_Scopes tests OAuth2 scope parameter parsing to ensure RFC 6749 compliance where scopes are space-delimited
(t *testing.T)
| 20 | // TestExtractTokenParams_Scopes tests OAuth2 scope parameter parsing |
| 21 | // to ensure RFC 6749 compliance where scopes are space-delimited |
| 22 | func TestExtractTokenParams_Scopes(t *testing.T) { |
| 23 | t.Parallel() |
| 24 | |
| 25 | testCases := []struct { |
| 26 | name string |
| 27 | scopeParam string // Raw query param value (before URL encoding) |
| 28 | expectedScopes []string // Expected parsed scope slice |
| 29 | description string // Test case description |
| 30 | }{ |
| 31 | { |
| 32 | name: "SpaceSeparatedTwoScopes", |
| 33 | scopeParam: "coder:workspace.create coder:workspace.operate", |
| 34 | expectedScopes: []string{"coder:workspace.create", "coder:workspace.operate"}, |
| 35 | description: "RFC 6749 compliant: space-separated scopes", |
| 36 | }, |
| 37 | { |
| 38 | name: "SpaceSeparatedThreeScopes", |
| 39 | scopeParam: "scope1 scope2 scope3", |
| 40 | expectedScopes: []string{"scope1", "scope2", "scope3"}, |
| 41 | description: "Multiple space-separated scopes", |
| 42 | }, |
| 43 | { |
| 44 | name: "SingleScope", |
| 45 | scopeParam: "coder:workspace.create", |
| 46 | expectedScopes: []string{"coder:workspace.create"}, |
| 47 | description: "Single scope without spaces", |
| 48 | }, |
| 49 | { |
| 50 | name: "EmptyScope", |
| 51 | scopeParam: "", |
| 52 | expectedScopes: []string{}, |
| 53 | description: "Empty scope parameter", |
| 54 | }, |
| 55 | { |
| 56 | name: "MultipleSpaces", |
| 57 | scopeParam: "scope1 scope2 scope3", |
| 58 | expectedScopes: []string{"scope1", "scope2", "scope3"}, |
| 59 | description: "Multiple consecutive spaces should be handled gracefully", |
| 60 | }, |
| 61 | { |
| 62 | name: "LeadingAndTrailingSpaces", |
| 63 | scopeParam: " scope1 scope2 ", |
| 64 | expectedScopes: []string{"scope1", "scope2"}, |
| 65 | description: "Leading and trailing spaces should be trimmed", |
| 66 | }, |
| 67 | { |
| 68 | name: "ColonInScope", |
| 69 | scopeParam: "coder:workspace:read coder:workspace:write", |
| 70 | expectedScopes: []string{"coder:workspace:read", "coder:workspace:write"}, |
| 71 | description: "Scopes with colons (common pattern)", |
| 72 | }, |
| 73 | { |
| 74 | name: "DotInScope", |
| 75 | scopeParam: "workspace.create workspace.delete", |
| 76 | expectedScopes: []string{"workspace.create", "workspace.delete"}, |
| 77 | description: "Scopes with dots (common pattern)", |
| 78 | }, |
| 79 | { |
nothing calls this directly
no test coverage detected