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

Function TestUserOIDCClaims

cli/useroidcclaims_test.go:21–161  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19)
20
21func TestUserOIDCClaims(t *testing.T) {
22 t.Parallel()
23
24 newOIDCTest := func(t *testing.T) (*oidctest.FakeIDP, *codersdk.Client) {
25 t.Helper()
26
27 fake := oidctest.NewFakeIDP(t,
28 oidctest.WithServing(),
29 )
30 cfg := fake.OIDCConfig(t, nil, func(cfg *coderd.OIDCConfig) {
31 cfg.AllowSignups = true
32 })
33 ownerClient := coderdtest.New(t, &coderdtest.Options{
34 OIDCConfig: cfg,
35 })
36 return fake, ownerClient
37 }
38
39 t.Run("OwnClaims", func(t *testing.T) {
40 t.Parallel()
41
42 fake, ownerClient := newOIDCTest(t)
43 claims := jwt.MapClaims{
44 "email": "alice@coder.com",
45 "email_verified": true,
46 "sub": uuid.NewString(),
47 "groups": []string{"admin", "eng"},
48 }
49 userClient, loginResp := fake.Login(t, ownerClient, claims)
50 defer loginResp.Body.Close()
51
52 inv, root := clitest.New(t, "users", "oidc-claims", "-o", "json")
53 clitest.SetupConfig(t, userClient, root)
54
55 buf := bytes.NewBuffer(nil)
56 inv.Stdout = buf
57 err := inv.WithContext(testutil.Context(t, testutil.WaitMedium)).Run()
58 require.NoError(t, err)
59
60 var resp codersdk.OIDCClaimsResponse
61 err = json.Unmarshal(buf.Bytes(), &resp)
62 require.NoError(t, err, "unmarshal JSON output")
63 require.NotEmpty(t, resp.Claims, "claims should not be empty")
64 assert.Equal(t, "alice@coder.com", resp.Claims["email"])
65 })
66
67 t.Run("Table", func(t *testing.T) {
68 t.Parallel()
69
70 fake, ownerClient := newOIDCTest(t)
71 claims := jwt.MapClaims{
72 "email": "bob@coder.com",
73 "email_verified": true,
74 "sub": uuid.NewString(),
75 }
76 userClient, loginResp := fake.Login(t, ownerClient, claims)
77 defer loginResp.Body.Close()
78

Callers

nothing calls this directly

Calls 15

OIDCConfigMethod · 0.95
LoginMethod · 0.95
NewFakeIDPFunction · 0.92
WithServingFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
ContextFunction · 0.92
CreateFirstUserFunction · 0.92
WithContextMethod · 0.80
NotEmptyMethod · 0.80
UserOIDCClaimsMethod · 0.80

Tested by

no test coverage detected