(t *testing.T)
| 25 | } |
| 26 | |
| 27 | func TestWithPATScopes(t *testing.T) { |
| 28 | logger := slog.Default() |
| 29 | |
| 30 | tests := []struct { |
| 31 | name string |
| 32 | tokenInfo *ghcontext.TokenInfo |
| 33 | fetcherScopes []string |
| 34 | fetcherErr error |
| 35 | expectScopesFetched bool |
| 36 | expectedScopes []string |
| 37 | expectNextHandlerCalled bool |
| 38 | }{ |
| 39 | { |
| 40 | name: "no token info in context calls next handler", |
| 41 | tokenInfo: nil, |
| 42 | expectScopesFetched: false, |
| 43 | expectedScopes: nil, |
| 44 | expectNextHandlerCalled: true, |
| 45 | }, |
| 46 | { |
| 47 | name: "non-PAT token type skips scope fetching", |
| 48 | tokenInfo: &ghcontext.TokenInfo{ |
| 49 | Token: "gho_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", |
| 50 | TokenType: utils.TokenTypeOAuthAccessToken, |
| 51 | }, |
| 52 | expectScopesFetched: false, |
| 53 | expectedScopes: nil, |
| 54 | expectNextHandlerCalled: true, |
| 55 | }, |
| 56 | { |
| 57 | name: "fine-grained PAT skips scope fetching", |
| 58 | tokenInfo: &ghcontext.TokenInfo{ |
| 59 | Token: "github_pat_xxxxxxxxxxxxxxxxxxxxxxx", |
| 60 | TokenType: utils.TokenTypeFineGrainedPersonalAccessToken, |
| 61 | }, |
| 62 | expectScopesFetched: false, |
| 63 | expectedScopes: nil, |
| 64 | expectNextHandlerCalled: true, |
| 65 | }, |
| 66 | { |
| 67 | name: "classic PAT fetches and stores scopes", |
| 68 | tokenInfo: &ghcontext.TokenInfo{ |
| 69 | Token: "ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", |
| 70 | TokenType: utils.TokenTypePersonalAccessToken, |
| 71 | }, |
| 72 | fetcherScopes: []string{"repo", "user", "read:org"}, |
| 73 | expectScopesFetched: true, |
| 74 | expectedScopes: []string{"repo", "user", "read:org"}, |
| 75 | expectNextHandlerCalled: true, |
| 76 | }, |
| 77 | { |
| 78 | name: "classic PAT with empty scopes", |
| 79 | tokenInfo: &ghcontext.TokenInfo{ |
| 80 | Token: "ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", |
| 81 | TokenType: utils.TokenTypePersonalAccessToken, |
| 82 | }, |
| 83 | fetcherScopes: []string{}, |
| 84 | expectScopesFetched: true, |
nothing calls this directly
no test coverage detected