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

Function TestAzureAKPKIWithCoderd

coderd/oauthpki/okidcpki_test.go:133–183  ·  view source on GitHub ↗

TestAzureAKPKIWithCoderd uses a fake IDP and a real Coderd to test PKI auth. nolint:bodyclose

(t *testing.T)

Source from the content-addressed store, hash-verified

131// TestAzureAKPKIWithCoderd uses a fake IDP and a real Coderd to test PKI auth.
132// nolint:bodyclose
133func TestAzureAKPKIWithCoderd(t *testing.T) {
134 t.Parallel()
135
136 scopes := []string{"openid", "email", "profile", "offline_access"}
137 fake := oidctest.NewFakeIDP(t,
138 oidctest.WithIssuer("https://login.microsoftonline.com/fake_app"),
139 oidctest.WithCustomClientAuth(func(t testing.TB, req *http.Request) (url.Values, error) {
140 values := assertJWTAuth(t, req)
141 if values == nil {
142 return nil, xerrors.New("authorizatin failed in request")
143 }
144 return values, nil
145 }),
146 oidctest.WithServing(),
147 oidctest.WithLogging(t, nil),
148 )
149 cfg := fake.OIDCConfig(t, scopes, func(cfg *coderd.OIDCConfig) {
150 cfg.AllowSignups = true
151 })
152
153 oauthCfg := cfg.OAuth2Config.(*oauth2.Config)
154 // Create the oauthpki config
155 pki, err := oauthpki.NewOauth2PKIConfig(oauthpki.ConfigParams{
156 ClientID: oauthCfg.ClientID,
157 TokenURL: oauthCfg.Endpoint.TokenURL,
158 Scopes: scopes,
159 PemEncodedKey: []byte(testClientKey),
160 PemEncodedCert: []byte(testClientCert),
161 Config: oauthCfg,
162 })
163 require.NoError(t, err)
164 cfg.OAuth2Config = pki
165
166 owner, _, api := coderdtest.NewWithAPI(t, &coderdtest.Options{
167 OIDCConfig: cfg,
168 })
169
170 // Create a user and login
171 const email = "alice@coder.com"
172 claims := jwt.MapClaims{
173 "email": email,
174 "sub": uuid.NewString(),
175 }
176 helper := oidctest.NewLoginHelper(owner, fake)
177 user, _ := helper.Login(t, claims)
178
179 // Try refreshing the token more than once.
180 for i := 0; i < 2; i++ {
181 helper.ForceRefresh(t, api.Database, user, claims)
182 }
183}
184
185// TestSavedAzureADPKIOIDC was created by capturing actual responses from an Azure
186// AD instance and saving them to replay, removing some details.

Callers

nothing calls this directly

Calls 13

OIDCConfigMethod · 0.95
LoginMethod · 0.95
ForceRefreshMethod · 0.95
NewFakeIDPFunction · 0.92
WithIssuerFunction · 0.92
WithCustomClientAuthFunction · 0.92
WithServingFunction · 0.92
WithLoggingFunction · 0.92
NewOauth2PKIConfigFunction · 0.92
NewWithAPIFunction · 0.92
NewLoginHelperFunction · 0.92
assertJWTAuthFunction · 0.85

Tested by

no test coverage detected