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

Function TestFixOIDCLinks

cli/server_fix_oidc_links_test.go:38–203  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

36}
37
38func TestFixOIDCLinks(t *testing.T) {
39 t.Parallel()
40
41 t.Run("DryRun", func(t *testing.T) {
42 t.Parallel()
43
44 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
45 t.Cleanup(cancel)
46
47 const expectedIssuer = "https://accounts.google.com"
48 oidcSrv := fakeOIDCDiscovery(t, expectedIssuer)
49
50 connectionURL, err := dbtestutil.Open(t)
51 require.NoError(t, err)
52
53 sqlDB, err := sql.Open("postgres", connectionURL)
54 require.NoError(t, err)
55 defer sqlDB.Close()
56
57 db := database.New(sqlDB)
58
59 // Seed a correctly linked user.
60 correctUser := dbgen.User(t, db, database.User{LoginType: database.LoginTypeOIDC})
61 dbgen.UserLink(t, db, database.UserLink{
62 UserID: correctUser.ID,
63 LoginType: database.LoginTypeOIDC,
64 LinkedID: expectedIssuer + "||sub-correct",
65 })
66
67 // Seed a mismatched user.
68 mismatchedUser := dbgen.User(t, db, database.User{LoginType: database.LoginTypeOIDC})
69 dbgen.UserLink(t, db, database.UserLink{
70 UserID: mismatchedUser.ID,
71 LoginType: database.LoginTypeOIDC,
72 LinkedID: "https://old-issuer.example.com||sub-mismatched",
73 })
74
75 inv, _ := clitest.New(t,
76 "server", "fix-oidc-links",
77 "--postgres-url", connectionURL,
78 "--issuer-url", oidcSrv.URL,
79 "--dry-run",
80 )
81
82 stdout := expecter.NewAttachedToInvocation(t, inv)
83 w := clitest.StartWithWaiter(t, inv)
84
85 stdout.ExpectMatch(ctx, "Resolved OIDC issuer: \""+expectedIssuer+"\"")
86 stdout.ExpectMatch(ctx, "Total OIDC users:")
87 stdout.ExpectMatch(ctx, "Correctly linked:")
88 stdout.ExpectMatch(ctx, "Linked to other issuers:")
89 w.RequireSuccess()
90
91 // Verify no changes were made.
92 link, err := db.GetUserLinkByUserIDLoginType(ctx, database.GetUserLinkByUserIDLoginTypeParams{
93 UserID: mismatchedUser.ID,
94 LoginType: database.LoginTypeOIDC,
95 })

Callers

nothing calls this directly

Calls 15

OpenFunction · 0.92
NewFunction · 0.92
UserFunction · 0.92
UserLinkFunction · 0.92
NewFunction · 0.92
NewAttachedToInvocationFunction · 0.92
StartWithWaiterFunction · 0.92
fakeOIDCDiscoveryFunction · 0.85
RequireSuccessMethod · 0.80
RunMethod · 0.65
CleanupMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected