Skip to content

PostgreSQL backup tool with Point-In-Time-Recovery and restore verification

FIX (users): Report a missing account from the console password reset, instead of crashing on an address no account holds

Rostislav Dugincb44ce8d6169
diff --git a/backend/internal/features/users/services/user_services.go b/backend/internal/features/users/services/user_services.go
index 38b45b83..d3116690 100644
--- a/backend/internal/features/users/services/user_services.go
+++ b/backend/internal/features/users/services/user_services.go
@@ -313,6 +313,10 @@ func (s *UserService) ChangeUserPasswordByEmail(ctx context.Context, email, newP
return fmt.Errorf("failed to get user: %w", err)
}
+ if user == nil {
+ return errors.New("user with this email does not exist")
+ }
+
return s.ChangeUserPassword(ctx, user.ID, newPassword)
}
diff --git a/backend/internal/features/users/services/user_services_test.go b/backend/internal/features/users/services/user_services_test.go
new file mode 100644
index 00000000..f12b7cb9
--- /dev/null
+++ b/backend/internal/features/users/services/user_services_test.go
@@ -0,0 +1,24 @@
+package users_services_test
+
+import (
+ "testing"
+
+ "github.com/google/uuid"
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+
+ users_services "databasus-backend/internal/features/users/services"
+)
+
+func Test_ChangeUserPasswordByEmail_WhenNoAccountHoldsTheAddress_ReturnsAnError(t *testing.T) {
+ missingEmail := "missing-" + uuid.New().String() + "@example.com"
+
+ err := users_services.GetUserService().ChangeUserPasswordByEmail(
+ t.Context(),
+ missingEmail,
+ "AnyPassword123!",
+ )
+
+ require.Error(t, err)
+ assert.Contains(t, err.Error(), "does not exist")
+}