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

Method withLink

coderd/database/oidcclaims_test.go:208–244  ·  view source on GitHub ↗
(lt database.LoginType, rawJSON json.RawMessage)

Source from the content-addressed store, hash-verified

206}
207
208func (g userGenerator) withLink(lt database.LoginType, rawJSON json.RawMessage) database.User {
209 t := g.t
210 db := g.db
211
212 user := g.noLink(lt)
213
214 link := dbgen.UserLink(t, db, database.UserLink{
215 UserID: user.ID,
216 LoginType: lt,
217 })
218
219 if sql, ok := db.(rawUpdater); ok {
220 // The only way to put arbitrary json into the db for testing edge cases.
221 // Making this a public API would be a mistake.
222 err := sql.UpdateUserLinkRawJSON(context.Background(), user.ID, rawJSON)
223 require.NoError(t, err)
224 } else {
225 var claims database.UserLinkClaims
226 err := json.Unmarshal(rawJSON, &claims)
227 require.NoError(t, err)
228
229 _, err = db.UpdateUserLink(context.Background(), database.UpdateUserLinkParams{
230 OAuthAccessToken: link.OAuthAccessToken,
231 OAuthAccessTokenKeyID: link.OAuthAccessTokenKeyID,
232 OAuthRefreshToken: link.OAuthRefreshToken,
233 OAuthRefreshTokenKeyID: link.OAuthRefreshTokenKeyID,
234 OAuthExpiry: link.OAuthExpiry,
235 UserID: link.UserID,
236 LoginType: link.LoginType,
237 // The new claims
238 Claims: claims,
239 })
240 require.NoError(t, err)
241 }
242
243 return user
244}
245
246type rawUpdater interface {
247 UpdateUserLinkRawJSON(ctx context.Context, userID uuid.UUID, data json.RawMessage) error

Callers 1

TestOIDCClaimsFunction · 0.95

Calls 5

noLinkMethod · 0.95
UserLinkFunction · 0.92
UpdateUserLinkRawJSONMethod · 0.65
UpdateUserLinkMethod · 0.65
UnmarshalMethod · 0.45

Tested by

no test coverage detected