Skip to content

Conversation

wtgodbe
Copy link
Member

@wtgodbe wtgodbe commented May 13, 2025

If an empty string gets passed as the recovery code to UserStoreBase.RedeemCodeAsync(TUser user, string code, CancellationToken ct), the method returns true, incorrectly indicating a valid recovery code. This PR resolves the issue by validating that the code argument is not an empty string.

…covery code

# Add empty string check for recovery code

If an empty string gets passed as the recovery code to `UserStoreBase.RedeemCodeAsync(TUser user, string code, CancellationToken ct)`, the method returns `true`, incorrectly indicating a valid recovery code. This PR resolves the issue by validating that the `code` argument is not an empty string.

## Description

The `RedeemCodeAsync()` method already validates that `code` is non-null. This PR:
* Extends the logic in this method to handle the empty string (`""`) case
* Adds tests validating that an exception gets thrown when `code` is `null` or `""`

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix

#### PR Summary
This pull request adds a check for empty strings in recovery codes to prevent null or empty values from being processed.
- `src/Shared/ThrowHelpers/ArgumentNullThrowHelper.cs`: Added `ThrowIfNullOrEmpty` method to validate strings as non-null and non-empty.
- `src/Identity/EntityFrameworkCore/test/EF.Test/UserStoreTest.cs`: Added tests to ensure `RedeemCodeAsync` throws exceptions for null or empty codes.
- `src/Identity/Extensions.Stores/src/UserStoreBase.cs`: Updated `ThrowIfNull` to `ThrowIfNullOrEmpty` for code validation in `RedeemCodeAsync`.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix

#### PR Summary
This pull request adds a check for empty strings in recovery code validation to prevent errors.
- `src/Shared/ThrowHelpers/ArgumentNullThrowHelper.cs`: Added `ThrowIfNullOrEmpty` method to validate non-null and non-empty strings.
- `src/Identity/EntityFrameworkCore/test/EF.Test/UserStoreTest.cs`: Added tests for null and empty recovery code validation.
- `src/Identity/Extensions.Stores/src/UserStoreBase.cs`: Updated recovery code validation to use `ThrowIfNullOrEmpty`.
@wtgodbe wtgodbe requested a review from MackinnonBuck May 13, 2025 22:43
@github-actions github-actions bot added the area-identity Includes: Identity and providers label May 13, 2025
@wtgodbe wtgodbe enabled auto-merge (squash) May 14, 2025 05:51
@wtgodbe wtgodbe merged commit 0230498 into main May 14, 2025
28 checks passed
@wtgodbe wtgodbe deleted the wtgodbe/PortM branch May 14, 2025 06:49
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-preview5 milestone May 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-identity Includes: Identity and providers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants