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

Function TestUserChangeLoginType

coderd/database/querier_test.go:2505–2550  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2503}
2504
2505func TestUserChangeLoginType(t *testing.T) {
2506 t.Parallel()
2507 if testing.Short() {
2508 t.SkipNow()
2509 }
2510
2511 sqlDB := testSQLDB(t)
2512 err := migrations.Up(sqlDB)
2513 require.NoError(t, err)
2514 db := database.New(sqlDB)
2515 ctx := context.Background()
2516
2517 alice := dbgen.User(t, db, database.User{
2518 LoginType: database.LoginTypePassword,
2519 })
2520 bob := dbgen.User(t, db, database.User{
2521 LoginType: database.LoginTypePassword,
2522 })
2523 bobExpPass := bob.HashedPassword
2524 require.NotEmpty(t, alice.HashedPassword, "hashed password should not start empty")
2525 require.NotEmpty(t, bob.HashedPassword, "hashed password should not start empty")
2526
2527 alice, err = db.UpdateUserLoginType(ctx, database.UpdateUserLoginTypeParams{
2528 NewLoginType: database.LoginTypeOIDC,
2529 UserID: alice.ID,
2530 })
2531 require.NoError(t, err)
2532
2533 require.Empty(t, alice.HashedPassword, "hashed password should be empty")
2534
2535 // First check other users are not affected
2536 bob, err = db.GetUserByID(ctx, bob.ID)
2537 require.NoError(t, err)
2538 require.Equal(t, bobExpPass, bob.HashedPassword, "hashed password should not change")
2539
2540 // Then check password -> password is a noop
2541 bob, err = db.UpdateUserLoginType(ctx, database.UpdateUserLoginTypeParams{
2542 NewLoginType: database.LoginTypePassword,
2543 UserID: bob.ID,
2544 })
2545 require.NoError(t, err)
2546
2547 bob, err = db.GetUserByID(ctx, bob.ID)
2548 require.NoError(t, err)
2549 require.Equal(t, bobExpPass, bob.HashedPassword, "hashed password should not change")
2550}
2551
2552func TestDefaultOrg(t *testing.T) {
2553 t.Parallel()

Callers

nothing calls this directly

Calls 10

UpFunction · 0.92
NewFunction · 0.92
UserFunction · 0.92
SkipNowMethod · 0.80
NotEmptyMethod · 0.80
testSQLDBFunction · 0.70
UpdateUserLoginTypeMethod · 0.65
GetUserByIDMethod · 0.65
EmptyMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected