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

Function TestOIDCClaims

coderd/database/oidcclaims_test.go:24–166  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22}
23
24func TestOIDCClaims(t *testing.T) {
25 t.Parallel()
26
27 toJSON := func(a any) json.RawMessage {
28 b, _ := json.Marshal(a)
29 return b
30 }
31
32 db, _ := dbtestutil.NewDB(t)
33 g := userGenerator{t: t, db: db}
34
35 const claimField = "claim-list"
36
37 // https://en.wikipedia.org/wiki/Alice_and_Bob#Cast_of_characters
38 alice := g.withLink(database.LoginTypeOIDC, toJSON(extraKeys{
39 UserLinkClaims: database.UserLinkClaims{
40 IDTokenClaims: map[string]interface{}{
41 "sub": "alice",
42 "alice-id": "from-bob",
43 },
44 UserInfoClaims: nil,
45 MergedClaims: map[string]interface{}{
46 "sub": "alice",
47 "alice-id": "from-bob",
48 claimField: []string{
49 "one", "two", "three",
50 },
51 },
52 },
53 // Always should be a no-op
54 Foo: "bar",
55 }))
56 bob := g.withLink(database.LoginTypeOIDC, toJSON(database.UserLinkClaims{
57 IDTokenClaims: map[string]interface{}{
58 "sub": "bob",
59 "bob-id": "from-bob",
60 "array": []string{
61 "a", "b", "c",
62 },
63 "map": map[string]interface{}{
64 "key": "value",
65 "foo": "bar",
66 },
67 "nil": nil,
68 },
69 UserInfoClaims: map[string]interface{}{
70 "sub": "bob",
71 "bob-info": []string{},
72 "number": 42,
73 },
74 MergedClaims: map[string]interface{}{
75 "sub": "bob",
76 "bob-info": []string{},
77 "number": 42,
78 "bob-id": "from-bob",
79 "array": []string{
80 "a", "b", "c",
81 },

Callers

nothing calls this directly

Calls 10

withLinkMethod · 0.95
noLinkMethod · 0.95
NewDBFunction · 0.92
OrganizationFunction · 0.92
UniqueFunction · 0.92
requireClaimsFunction · 0.85
requireClaimValuesFunction · 0.85
MembersMethod · 0.80
DoMethod · 0.65
MarshalMethod · 0.45

Tested by

no test coverage detected