mirror of
https://github.com/bitwarden/server
synced 2026-01-28 23:36:12 +00:00
user reset password key can be empty string (#6871)
This commit is contained in:
@@ -34,8 +34,7 @@ public class OrganizationUserRotationValidator : IRotationValidator<IEnumerable<
|
||||
}
|
||||
|
||||
// Exclude any account recovery that do not have a key.
|
||||
existing = existing.Where(o => o.ResetPasswordKey != null).ToList();
|
||||
|
||||
existing = existing.Where(o => !string.IsNullOrEmpty(o.ResetPasswordKey)).ToList();
|
||||
|
||||
foreach (var ou in existing)
|
||||
{
|
||||
|
||||
@@ -69,6 +69,44 @@ public class OrganizationUserRotationValidatorTests
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[BitAutoData([null])]
|
||||
[BitAutoData("")]
|
||||
public async Task ValidateAsync_OrgUsersWithNullOrEmptyResetPasswordKey_FiltersOutInvalidKeys(
|
||||
string? invalidResetPasswordKey,
|
||||
SutProvider<OrganizationUserRotationValidator> sutProvider, User user,
|
||||
ResetPasswordWithOrgIdRequestModel validResetPasswordKey)
|
||||
{
|
||||
// Arrange
|
||||
var existingUserResetPassword = new List<OrganizationUser>
|
||||
{
|
||||
// Valid org user with reset password key
|
||||
new OrganizationUser
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
OrganizationId = validResetPasswordKey.OrganizationId,
|
||||
ResetPasswordKey = validResetPasswordKey.ResetPasswordKey
|
||||
},
|
||||
// Invalid org user with null or empty reset password key - should be filtered out
|
||||
new OrganizationUser
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
OrganizationId = Guid.NewGuid(),
|
||||
ResetPasswordKey = invalidResetPasswordKey
|
||||
}
|
||||
};
|
||||
sutProvider.GetDependency<IOrganizationUserRepository>().GetManyByUserAsync(user.Id)
|
||||
.Returns(existingUserResetPassword);
|
||||
|
||||
// Act
|
||||
var result = await sutProvider.Sut.ValidateAsync(user, new[] { validResetPasswordKey });
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Single(result);
|
||||
Assert.Equal(validResetPasswordKey.OrganizationId, result[0].OrganizationId);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[BitAutoData]
|
||||
public async Task ValidateAsync_MissingResetPassword_Throws(
|
||||
|
||||
Reference in New Issue
Block a user