feat(authctl): support password reset
This commit is contained in:
@@ -213,6 +213,41 @@ func TestAuthServiceProvisionsHashedCredentials(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuthServiceResetsExistingUserPassword(t *testing.T) {
|
||||
fixture := newAuthServiceFixture(t)
|
||||
fixture.repository.users["admin"] = domain.User{
|
||||
ID: "user-admin",
|
||||
Username: "admin",
|
||||
PasswordHash: "hashed:old-password",
|
||||
Role: domain.UserRoleAdmin,
|
||||
IsActive: true,
|
||||
}
|
||||
|
||||
err := fixture.service.ResetUserPassword(
|
||||
context.Background(),
|
||||
ResetUserPasswordCommand{
|
||||
Username: " ADMIN ",
|
||||
Password: "admin",
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("ResetUserPassword() error = %v", err)
|
||||
}
|
||||
if fixture.repository.users["admin"].PasswordHash != "hashed:admin" {
|
||||
t.Fatalf(
|
||||
"password hash = %q",
|
||||
fixture.repository.users["admin"].PasswordHash,
|
||||
)
|
||||
}
|
||||
|
||||
err = fixture.service.ResetUserPassword(
|
||||
context.Background(),
|
||||
ResetUserPasswordCommand{Username: "missing", Password: "admin"},
|
||||
)
|
||||
assertAuthCode(t, err, "RESOURCE_NOT_FOUND")
|
||||
}
|
||||
|
||||
func TestAuthServiceChangesUserAndDeviceStatus(t *testing.T) {
|
||||
fixture := newAuthServiceFixture(t)
|
||||
if err := fixture.service.SetUserActive(
|
||||
@@ -409,6 +444,21 @@ func (repository *fakeAuthRepository) ProvisionDevice(
|
||||
return device, nil
|
||||
}
|
||||
|
||||
func (repository *fakeAuthRepository) ResetUserPassword(
|
||||
_ context.Context,
|
||||
username string,
|
||||
passwordHash string,
|
||||
_ time.Time,
|
||||
) error {
|
||||
user, found := repository.users[username]
|
||||
if !found {
|
||||
return ErrRepositoryNotFound
|
||||
}
|
||||
user.PasswordHash = passwordHash
|
||||
repository.users[username] = user
|
||||
return nil
|
||||
}
|
||||
|
||||
func (repository *fakeAuthRepository) SetUserActive(
|
||||
_ context.Context,
|
||||
username string,
|
||||
|
||||
Reference in New Issue
Block a user