TestOAuth2ErrorResponseFormat tests that OAuth2 error responses follow proper RFC format
(t *testing.T)
| 22 | |
| 23 | // TestOAuth2ErrorResponseFormat tests that OAuth2 error responses follow proper RFC format |
| 24 | func TestOAuth2ErrorResponseFormat(t *testing.T) { |
| 25 | t.Parallel() |
| 26 | |
| 27 | t.Run("ContentTypeHeader", func(t *testing.T) { |
| 28 | t.Parallel() |
| 29 | |
| 30 | client := coderdtest.New(t, nil) |
| 31 | _ = coderdtest.CreateFirstUser(t, client) |
| 32 | ctx := testutil.Context(t, testutil.WaitLong) |
| 33 | |
| 34 | // Make a request that will definitely fail |
| 35 | req := codersdk.OAuth2ClientRegistrationRequest{ |
| 36 | // Missing required redirect_uris |
| 37 | } |
| 38 | |
| 39 | _, err := client.PostOAuth2ClientRegistration(ctx, req) |
| 40 | require.Error(t, err) |
| 41 | |
| 42 | // Check that it's an HTTP error with JSON content type |
| 43 | var httpErr *codersdk.Error |
| 44 | require.ErrorAs(t, err, &httpErr) |
| 45 | |
| 46 | // The error should be a 400 status for invalid client metadata |
| 47 | require.Equal(t, http.StatusBadRequest, httpErr.StatusCode()) |
| 48 | }) |
| 49 | } |
| 50 | |
| 51 | // TestOAuth2RegistrationErrorCodes tests all RFC 7591 error codes |
| 52 | func TestOAuth2RegistrationErrorCodes(t *testing.T) { |
nothing calls this directly
no test coverage detected