(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func TestExtractUserToken(t *testing.T) { |
| 17 | oauthCfg := &oauth.Config{ |
| 18 | BaseURL: "https://example.com", |
| 19 | AuthorizationServer: "https://github.com/login/oauth", |
| 20 | } |
| 21 | |
| 22 | tests := []struct { |
| 23 | name string |
| 24 | authHeader string |
| 25 | expectedStatusCode int |
| 26 | expectedTokenType utils.TokenType |
| 27 | expectedToken string |
| 28 | expectTokenInfo bool |
| 29 | expectWWWAuth bool |
| 30 | }{ |
| 31 | // Missing authorization header |
| 32 | { |
| 33 | name: "missing Authorization header returns 401 with WWW-Authenticate", |
| 34 | authHeader: "", |
| 35 | expectedStatusCode: http.StatusUnauthorized, |
| 36 | expectTokenInfo: false, |
| 37 | expectWWWAuth: true, |
| 38 | }, |
| 39 | // Personal Access Token (classic) - ghp_ prefix |
| 40 | { |
| 41 | name: "personal access token (classic) with Bearer prefix", |
| 42 | authHeader: "Bearer ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", |
| 43 | expectedStatusCode: http.StatusOK, |
| 44 | expectedTokenType: utils.TokenTypePersonalAccessToken, |
| 45 | expectedToken: "ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", |
| 46 | expectTokenInfo: true, |
| 47 | }, |
| 48 | { |
| 49 | name: "personal access token (classic) with bearer lowercase", |
| 50 | authHeader: "bearer ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", |
| 51 | expectedStatusCode: http.StatusOK, |
| 52 | expectedTokenType: utils.TokenTypePersonalAccessToken, |
| 53 | expectedToken: "ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", |
| 54 | expectTokenInfo: true, |
| 55 | }, |
| 56 | { |
| 57 | name: "personal access token (classic) without Bearer prefix", |
| 58 | authHeader: "ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", |
| 59 | expectedStatusCode: http.StatusOK, |
| 60 | expectedTokenType: utils.TokenTypePersonalAccessToken, |
| 61 | expectedToken: "ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", |
| 62 | expectTokenInfo: true, |
| 63 | }, |
| 64 | // Fine-grained Personal Access Token - github_pat_ prefix |
| 65 | { |
| 66 | name: "fine-grained personal access token with Bearer prefix", |
| 67 | authHeader: "Bearer github_pat_xxxxxxxxxxxxxxxxxxxxxxx", |
| 68 | expectedStatusCode: http.StatusOK, |
| 69 | expectedTokenType: utils.TokenTypeFineGrainedPersonalAccessToken, |
| 70 | expectedToken: "github_pat_xxxxxxxxxxxxxxxxxxxxxxx", |
| 71 | expectTokenInfo: true, |
| 72 | }, |
| 73 | { |
nothing calls this directly
no test coverage detected