MCPcopy Index your code
hub / github.com/coder/coder / CreateAuthCode

Method CreateAuthCode

coderd/coderdtest/oidctest/idp.go:761–774  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

759// request to the IDP, so it should be equivalent to doing this "manually" with
760// actual requests.
761func (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

Callers 1

TestInstrumentFunction · 0.95

Calls 7

OAuth2GetCodeFunction · 0.85
ConfigMethod · 0.80
AuthCodeURLMethod · 0.65
StoreMethod · 0.45
ServeHTTPMethod · 0.45
HandlerMethod · 0.45
ResultMethod · 0.45

Tested by 1

TestInstrumentFunction · 0.76