CreateAuthCode emulates a user clicking "allow" on the IDP page. When doing unit tests, it's easier to skip this step sometimes. It does make an actual request to the IDP, so it should be equivalent to doing this "manually" with actual requests.
(t testing.TB, state string)
| 759 | // request to the IDP, so it should be equivalent to doing this "manually" with |
| 760 | // actual requests. |
| 761 | func (f *FakeIDP) CreateAuthCode(t testing.TB, state string) string { |
| 762 | // We need to store some claims, because this is also an OIDC provider, and |
| 763 | // it expects some claims to be present. |
| 764 | f.stateToIDTokenClaims.Store(state, jwt.MapClaims{}) |
| 765 | |
| 766 | code, err := OAuth2GetCode(f.locked.Config().AuthCodeURL(state), func(req *http.Request) (*http.Response, error) { |
| 767 | rw := httptest.NewRecorder() |
| 768 | f.locked.Handler().ServeHTTP(rw, req) |
| 769 | resp := rw.Result() |
| 770 | return resp, nil |
| 771 | }) |
| 772 | require.NoError(t, err, "failed to get auth code") |
| 773 | return code |
| 774 | } |
| 775 | |
| 776 | // OIDCCallback will emulate the IDP redirecting back to the Coder callback. |
| 777 | // This is helpful if no Coderd exists because the IDP needs to redirect to |