Skip to content

Commit a384465

Browse files
Mackinnon Buckwtgodbe
authored andcommitted
Merged PR 49098: [internal/release/2.3] Add empty string check for recovery 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 recovery codes to prevent invalid inputs. - `src/Identity/Extensions.Stores/src/UserStoreBase.cs`: Added a check to throw an `ArgumentException` if the recovery code is an empty string. - `src/Identity/EntityFrameworkCore/test/EF.Test/UserStoreTest.cs`: Added tests to ensure `RedeemCodeAsync` throws appropriate exceptions for null and empty recovery codes. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot --> ---- #### AI description (iteration 1) #### PR Classification Bug fix #### PR Summary This pull request adds a check for empty recovery codes to prevent invalid inputs. - `src/Identity/Extensions.Stores/src/UserStoreBase.cs`: Added a check to throw an `ArgumentException` if the recovery code is an empty string. - `src/Identity/EntityFrameworkCore/test/EF.Test/UserStoreTest.cs`: Added tests to ensure `RedeemCodeAsync` throws appropriate exceptions for null and empty recovery codes.
1 parent 368c670 commit a384465

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

eng/PatchConfig.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Later on, this will be checked using this condition:
2020
</PropertyGroup>
2121
<PropertyGroup Condition=" '$(VersionPrefix)' == '2.3.2' ">
2222
<PackagesInPatch>
23+
Microsoft.Extensions.Identity.Stores;
2324
</PackagesInPatch>
2425
</PropertyGroup>
2526
</Project>

src/Identity/EntityFrameworkCore/test/EF.Test/UserStoreTest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ await Assert.ThrowsAsync<ArgumentNullException>("user",
165165
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.GetTwoFactorEnabledAsync(null));
166166
await Assert.ThrowsAsync<ArgumentNullException>("user",
167167
async () => await store.SetTwoFactorEnabledAsync(null, true));
168+
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.RedeemCodeAsync(user: null, code: "fake", default));
169+
await Assert.ThrowsAsync<ArgumentNullException>("code", async () => await store.RedeemCodeAsync(new IdentityUser("fake"), code: null, default));
170+
await Assert.ThrowsAsync<ArgumentException>("code", async () => await store.RedeemCodeAsync(new IdentityUser("fake"), code: "", default));
168171
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.GetAccessFailedCountAsync(null));
169172
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.GetLockoutEnabledAsync(null));
170173
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.SetLockoutEnabledAsync(null, false));

src/Identity/Extensions.Stores/src/UserStoreBase.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,10 @@ public virtual async Task<bool> RedeemCodeAsync(TUser user, string code, Cancell
10601060
{
10611061
throw new ArgumentNullException(nameof(code));
10621062
}
1063+
if (code.Length == 0)
1064+
{
1065+
throw new ArgumentException("Must not be null or empty", nameof(code));
1066+
}
10631067

10641068
var mergedCodes = await GetTokenAsync(user, InternalLoginProvider, RecoveryCodeTokenName, cancellationToken) ?? "";
10651069
var splitCodes = mergedCodes.Split(';');

0 commit comments

Comments
 (0)