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

Function TestUserOIDC

enterprise/coderd/userauth_test.go:32–795  ·  view source on GitHub ↗

nolint:bodyclose

(t *testing.T)

Source from the content-addressed store, hash-verified

30
31// nolint:bodyclose
32func TestUserOIDC(t *testing.T) {
33 t.Parallel()
34
35 t.Run("OrganizationSync", func(t *testing.T) {
36 t.Parallel()
37
38 t.Run("SingleOrgDeployment", func(t *testing.T) {
39 t.Parallel()
40
41 runner := setupOIDCTest(t, oidcTestConfig{
42 Config: func(cfg *coderd.OIDCConfig) {
43 cfg.AllowSignups = true
44 },
45 DeploymentValues: func(dv *codersdk.DeploymentValues) {
46 dv.OIDC.UserRoleField = "roles"
47 },
48 })
49
50 claims := jwt.MapClaims{
51 "email": "alice@coder.com",
52 "sub": uuid.NewString(),
53 }
54
55 // Login a new client that signs up
56 client, resp := runner.Login(t, claims)
57 require.Equal(t, http.StatusOK, resp.StatusCode)
58 runner.AssertOrganizations(t, "alice", true, nil)
59
60 // Force a refresh, and assert nothing has changes
61 runner.ForceRefresh(t, client, claims)
62 runner.AssertOrganizations(t, "alice", true, nil)
63 })
64
65 t.Run("MultiOrgNoSync", func(t *testing.T) {
66 t.Parallel()
67
68 runner := setupOIDCTest(t, oidcTestConfig{
69 Config: func(cfg *coderd.OIDCConfig) {
70 cfg.AllowSignups = true
71 },
72 })
73
74 ctx := testutil.Context(t, testutil.WaitMedium)
75 second, err := runner.AdminClient.CreateOrganization(ctx, codersdk.CreateOrganizationRequest{
76 Name: "second",
77 DisplayName: "",
78 Description: "",
79 Icon: "",
80 })
81 require.NoError(t, err)
82
83 claims := jwt.MapClaims{
84 "email": "alice@coder.com",
85 "sub": uuid.NewString(),
86 }
87
88 // Login a new client that signs up
89 _, resp := runner.Login(t, claims)

Callers

nothing calls this directly

Calls 15

StatusCodeMethod · 0.95
ContextFunction · 0.92
OrganizationMemberFunction · 0.92
OrganizationFunction · 0.92
RoleTemplateAdminFunction · 0.92
RoleUserAdminFunction · 0.92
RoleOwnerFunction · 0.92
WithRefreshFunction · 0.92
setupOIDCTestFunction · 0.85
AssertOrganizationsMethod · 0.80
ForceRefreshMethod · 0.80
CreateOrganizationMethod · 0.80

Tested by

no test coverage detected