TestAuthorizationsAppOperations tests the application/token related operations, such as creating, testing, resetting and revoking application OAuth tokens.
(t *testing.T)
| 27 | // TestAuthorizationsAppOperations tests the application/token related operations, such |
| 28 | // as creating, testing, resetting and revoking application OAuth tokens. |
| 29 | func TestAuthorizationsAppOperations(t *testing.T) { |
| 30 | appAuthenticatedClient := getOAuthAppClient(t) |
| 31 | |
| 32 | // We know these vars are set because getOAuthAppClient would have |
| 33 | // skipped the test by now |
| 34 | clientID := os.Getenv(envKeyClientID) |
| 35 | accessToken := os.Getenv(envKeyAccessToken) |
| 36 | |
| 37 | // Verify the token |
| 38 | appAuth, resp, err := appAuthenticatedClient.Authorizations.Check(t.Context(), clientID, accessToken) |
| 39 | failOnError(t, err) |
| 40 | failIfNotStatusCode(t, resp, 200) |
| 41 | |
| 42 | // Quick sanity check |
| 43 | if *appAuth.Token != accessToken { |
| 44 | t.Fatal("The returned auth/token does not match.") |
| 45 | } |
| 46 | |
| 47 | // Let's verify that we get a 404 for a nonexistent token |
| 48 | _, resp, err = appAuthenticatedClient.Authorizations.Check(t.Context(), clientID, InvalidTokenValue) |
| 49 | if err == nil { |
| 50 | t.Fatal("An error should have been returned because of the invalid token.") |
| 51 | } |
| 52 | failIfNotStatusCode(t, resp, 404) |
| 53 | |
| 54 | // Let's reset the token |
| 55 | resetAuth, resp, err := appAuthenticatedClient.Authorizations.Reset(t.Context(), clientID, accessToken) |
| 56 | failOnError(t, err) |
| 57 | failIfNotStatusCode(t, resp, 200) |
| 58 | |
| 59 | // Let's verify that we get a 404 for a nonexistent token |
| 60 | _, resp, err = appAuthenticatedClient.Authorizations.Reset(t.Context(), clientID, InvalidTokenValue) |
| 61 | if err == nil { |
| 62 | t.Fatal("An error should have been returned because of the invalid token.") |
| 63 | } |
| 64 | failIfNotStatusCode(t, resp, 404) |
| 65 | |
| 66 | // Verify that the token has changed |
| 67 | if *resetAuth.Token == accessToken { |
| 68 | t.Fatal("The reset token should be different from the original.") |
| 69 | } |
| 70 | |
| 71 | // Verify that we do have a token value |
| 72 | if *resetAuth.Token == "" { |
| 73 | t.Fatal("A token value should have been returned.") |
| 74 | } |
| 75 | |
| 76 | // Verify that the original token is now invalid |
| 77 | _, resp, err = appAuthenticatedClient.Authorizations.Check(t.Context(), clientID, accessToken) |
| 78 | if err == nil { |
| 79 | t.Fatal("The original token should be invalid.") |
| 80 | } |
| 81 | failIfNotStatusCode(t, resp, 404) |
| 82 | |
| 83 | // Check that the reset token is valid |
| 84 | _, resp, err = appAuthenticatedClient.Authorizations.Check(t.Context(), clientID, *resetAuth.Token) |
| 85 | failOnError(t, err) |
| 86 | failIfNotStatusCode(t, resp, 200) |
nothing calls this directly
no test coverage detected
searching dependent graphs…