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

Function TestUserLinks

enterprise/dbcrypt/dbcrypt_internal_test.go:24–277  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22)
23
24func TestUserLinks(t *testing.T) {
25 t.Parallel()
26 ctx := context.Background()
27
28 t.Run("InsertUserLink", func(t *testing.T) {
29 t.Parallel()
30 db, crypt, ciphers := setup(t)
31 user := dbgen.User(t, crypt, database.User{})
32 link := dbgen.UserLink(t, crypt, database.UserLink{
33 UserID: user.ID,
34 OAuthAccessToken: "access",
35 OAuthRefreshToken: "refresh",
36 })
37 require.Equal(t, "access", link.OAuthAccessToken)
38 require.Equal(t, "refresh", link.OAuthRefreshToken)
39 require.Equal(t, ciphers[0].HexDigest(), link.OAuthAccessTokenKeyID.String)
40 require.Equal(t, ciphers[0].HexDigest(), link.OAuthRefreshTokenKeyID.String)
41
42 rawLink, err := db.GetUserLinkByLinkedID(ctx, link.LinkedID)
43 require.NoError(t, err)
44 requireEncryptedEquals(t, ciphers[0], rawLink.OAuthAccessToken, "access")
45 requireEncryptedEquals(t, ciphers[0], rawLink.OAuthRefreshToken, "refresh")
46 })
47
48 t.Run("UpdateUserLink", func(t *testing.T) {
49 t.Parallel()
50 db, crypt, ciphers := setup(t)
51 user := dbgen.User(t, crypt, database.User{})
52 link := dbgen.UserLink(t, crypt, database.UserLink{
53 UserID: user.ID,
54 })
55
56 expectedClaims := database.UserLinkClaims{
57 IDTokenClaims: map[string]interface{}{
58 "sub": "123",
59 "groups": []interface{}{
60 "foo", "bar",
61 },
62 },
63 UserInfoClaims: map[string]interface{}{
64 "number": float64(2),
65 "struct": map[string]interface{}{
66 "number": float64(2),
67 },
68 },
69 MergedClaims: map[string]interface{}{
70 "sub": "123",
71 "groups": []interface{}{
72 "foo", "bar",
73 },
74 "number": float64(2),
75 "struct": map[string]interface{}{
76 "number": float64(2),
77 },
78 },
79 }
80
81 updated, err := crypt.UpdateUserLink(ctx, database.UpdateUserLinkParams{

Callers

nothing calls this directly

Calls 15

UserFunction · 0.92
UserLinkFunction · 0.92
ExternalAuthLinkFunction · 0.92
NowFunction · 0.92
fakeBase64RandomDataFunction · 0.85
setupFunction · 0.70
requireEncryptedEqualsFunction · 0.70
RunMethod · 0.65
HexDigestMethod · 0.65
GetUserLinkByLinkedIDMethod · 0.65
UpdateUserLinkMethod · 0.65

Tested by

no test coverage detected