(t *testing.T)
| 75 | } |
| 76 | |
| 77 | func TestUserResetPasswordCmd(t *testing.T) { |
| 78 | tmpDB := t.TempDir() + "/test.db" |
| 79 | |
| 80 | // Create a user first |
| 81 | db := testutils.InitDB(tmpDB) |
| 82 | user := testutils.SetupUserData(db, "test@example.com", "oldpassword123") |
| 83 | oldPasswordHash := user.Password.String |
| 84 | sqlDB, _ := db.DB() |
| 85 | sqlDB.Close() |
| 86 | |
| 87 | // Reset password |
| 88 | userResetPasswordCmd([]string{"--dbPath", tmpDB, "--email", "test@example.com", "--password", "newpassword123"}) |
| 89 | |
| 90 | // Verify password was changed |
| 91 | db2 := testutils.InitDB(tmpDB) |
| 92 | defer func() { |
| 93 | sqlDB2, _ := db2.DB() |
| 94 | sqlDB2.Close() |
| 95 | }() |
| 96 | |
| 97 | var updatedUser database.User |
| 98 | testutils.MustExec(t, db2.Where("email = ?", "test@example.com").First(&updatedUser), "finding user") |
| 99 | |
| 100 | // Verify password hash changed |
| 101 | assert.Equal(t, updatedUser.Password.String != oldPasswordHash, true, "password hash should be different") |
| 102 | assert.Equal(t, len(updatedUser.Password.String) > 0, true, "password should be set") |
| 103 | |
| 104 | // Verify new password works |
| 105 | err := bcrypt.CompareHashAndPassword([]byte(updatedUser.Password.String), []byte("newpassword123")) |
| 106 | assert.Equal(t, err, nil, "new password should match") |
| 107 | |
| 108 | // Verify old password doesn't work |
| 109 | err = bcrypt.CompareHashAndPassword([]byte(updatedUser.Password.String), []byte("oldpassword123")) |
| 110 | assert.Equal(t, err != nil, true, "old password should not match") |
| 111 | } |
| 112 | |
| 113 | func TestUserListCmd(t *testing.T) { |
| 114 | t.Run("multiple users", func(t *testing.T) { |
nothing calls this directly
no test coverage detected