(t *testing.T)
| 2503 | } |
| 2504 | |
| 2505 | func 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 | |
| 2552 | func TestDefaultOrg(t *testing.T) { |
| 2553 | t.Parallel() |
nothing calls this directly
no test coverage detected