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

Function TestAnalyzeOIDCLinks

coderd/authlink/authlink_test.go:18–165  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16)
17
18func TestAnalyzeOIDCLinks(t *testing.T) {
19 t.Parallel()
20
21 t.Run("MixedIssuers", func(t *testing.T) {
22 t.Parallel()
23 ctx := testutil.Context(t, testutil.WaitShort)
24
25 db, _ := dbtestutil.NewDB(t)
26 const expectedIssuer = "https://accounts.google.com"
27
28 // 3 users linked to the expected issuer.
29 for i := 0; i < 3; i++ {
30 user := dbgen.User(t, db, database.User{LoginType: database.LoginTypeOIDC})
31 dbgen.UserLink(t, db, database.UserLink{
32 UserID: user.ID,
33 LoginType: database.LoginTypeOIDC,
34 LinkedID: expectedIssuer + "||sub-" + user.ID.String(),
35 })
36 }
37
38 // 2 users linked to an old issuer.
39 for i := 0; i < 2; i++ {
40 user := dbgen.User(t, db, database.User{LoginType: database.LoginTypeOIDC})
41 dbgen.UserLink(t, db, database.UserLink{
42 UserID: user.ID,
43 LoginType: database.LoginTypeOIDC,
44 LinkedID: "https://old-issuer.example.com||sub-" + user.ID.String(),
45 })
46 }
47
48 // 1 user linked to another old issuer.
49 user := dbgen.User(t, db, database.User{LoginType: database.LoginTypeOIDC})
50 dbgen.UserLink(t, db, database.UserLink{
51 UserID: user.ID,
52 LoginType: database.LoginTypeOIDC,
53 LinkedID: "https://staging.example.com||sub-" + user.ID.String(),
54 })
55
56 // 1 unlinked user (empty linked_id).
57 unlinkedUser := dbgen.User(t, db, database.User{LoginType: database.LoginTypeOIDC})
58 dbgen.UserLink(t, db, database.UserLink{
59 UserID: unlinkedUser.ID,
60 LoginType: database.LoginTypeOIDC,
61 LinkedID: "",
62 })
63
64 analysis, err := authlink.AnalyzeOIDCLinks(ctx, db, expectedIssuer)
65 require.NoError(t, err)
66
67 require.Equal(t, 7, analysis.Total)
68 require.Equal(t, 3, analysis.CorrectIssuer)
69 require.Equal(t, 1, analysis.Unlinked)
70 require.Equal(t, 3, analysis.MismatchedTotal())
71 require.Equal(t, 2, analysis.MismatchedCounts["https://old-issuer.example.com"])
72 require.Equal(t, 1, analysis.MismatchedCounts["https://staging.example.com"])
73 })
74
75 t.Run("NoOIDCUsers", func(t *testing.T) {

Callers

nothing calls this directly

Calls 10

ContextFunction · 0.92
NewDBFunction · 0.92
UserFunction · 0.92
UserLinkFunction · 0.92
AnalyzeOIDCLinksFunction · 0.92
MismatchedTotalMethod · 0.80
RunMethod · 0.65
UpdateUserDeletedByIDMethod · 0.65
StringMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected