Skip to content

Commit 91fa02f

Browse files
authored
[PM-19811] fix ResetPasswordEnrolled check to handle empty and whitespace strings. (#5599)
1 parent a8403f3 commit 91fa02f

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/Api/AdminConsole/Models/Response/ProfileOrganizationResponseModel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public ProfileOrganizationResponseModel(
5151
SsoBound = !string.IsNullOrWhiteSpace(organization.SsoExternalId);
5252
Identifier = organization.Identifier;
5353
Permissions = CoreHelpers.LoadClassFromJsonData<Permissions>(organization.Permissions);
54-
ResetPasswordEnrolled = organization.ResetPasswordKey != null;
54+
ResetPasswordEnrolled = !string.IsNullOrWhiteSpace(organization.ResetPasswordKey);
5555
UserId = organization.UserId;
5656
OrganizationUserId = organization.OrganizationUserId;
5757
ProviderId = organization.ProviderId;

src/Api/AdminConsole/Public/Models/Response/MemberResponseModel.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public MemberResponseModel(OrganizationUser user, IEnumerable<CollectionAccessSe
3030
Email = user.Email;
3131
Status = user.Status;
3232
Collections = collections?.Select(c => new AssociationWithPermissionsResponseModel(c));
33-
ResetPasswordEnrolled = user.ResetPasswordKey != null;
33+
ResetPasswordEnrolled = !string.IsNullOrWhiteSpace(user.ResetPasswordKey);
3434
}
3535

3636
[SetsRequiredMembers]
@@ -49,7 +49,7 @@ public MemberResponseModel(OrganizationUserUserDetails user, bool twoFactorEnabl
4949
TwoFactorEnabled = twoFactorEnabled;
5050
Status = user.Status;
5151
Collections = collections?.Select(c => new AssociationWithPermissionsResponseModel(c));
52-
ResetPasswordEnrolled = user.ResetPasswordKey != null;
52+
ResetPasswordEnrolled = !string.IsNullOrWhiteSpace(user.ResetPasswordKey);
5353
SsoExternalId = user.SsoExternalId;
5454
}
5555

test/Api.Test/AdminConsole/Public/Models/Response/MemberResponseModelTests.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,16 @@ public void ResetPasswordEnrolled_ShouldBeTrue_WhenUserHasResetPasswordKey()
2525
Assert.True(sut.ResetPasswordEnrolled);
2626
}
2727

28-
[Fact]
29-
public void ResetPasswordEnrolled_ShouldBeFalse_WhenUserDoesNotHaveResetPasswordKey()
28+
[Theory]
29+
[InlineData(null)]
30+
[InlineData("")]
31+
[InlineData(" ")]
32+
public void ResetPasswordEnrolled_ShouldBeFalse_WhenResetPasswordKeyIsInvalid(string? resetPasswordKey)
3033
{
3134
// Arrange
3235
var user = Substitute.For<OrganizationUser>();
36+
user.ResetPasswordKey = resetPasswordKey;
37+
3338
var collections = Substitute.For<IEnumerable<CollectionAccessSelection>>();
3439

3540
// Act

0 commit comments

Comments
 (0)