Skip to content

Commit c8041d0

Browse files
daiaziusbrianchandotcom
authored andcommitted
LPD-43475 Add test to check if the user's credential is updated on succesful authentication
1 parent 367dc7d commit c8041d0

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

modules/apps/user/user-test/src/testIntegration/java/com/liferay/user/service/test/UserLocalServiceTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,47 @@ public void testLockoutUser() throws Exception {
806806
}
807807
}
808808

809+
@Test
810+
public void testOutdatedPasswordAlgorithmIsUpdatedAfterLogin()
811+
throws Exception {
812+
813+
User user = UserTestUtil.addUser();
814+
815+
String password = "password";
816+
817+
user = _userLocalService.updatePassword(
818+
user.getUserId(), password, password, false, true);
819+
820+
Assert.assertTrue(
821+
user.getPassword(
822+
).startsWith(
823+
"{PBKDF2WITHHMACSHA1}"
824+
));
825+
826+
try (AutoCloseable autoCloseable1 =
827+
ReflectionTestUtil.setFieldValueWithAutoCloseable(
828+
UserLocalServiceImpl.class,
829+
"_PASSWORDS_ENCRYPTION_ALGORITHM", "SHA-384");
830+
AutoCloseable autoCloseable2 =
831+
ReflectionTestUtil.setFieldValueWithAutoCloseable(
832+
PasswordEncryptorUtil.class,
833+
"_PASSWORDS_ENCRYPTION_ALGORITHM", "SHA-384")) {
834+
835+
Assert.assertEquals(
836+
Authenticator.SUCCESS,
837+
_userLocalService.authenticateByEmailAddress(
838+
user.getCompanyId(), user.getDisplayEmailAddress(),
839+
password, null, null, null));
840+
841+
user = _userLocalService.getUser(user.getUserId());
842+
843+
Assert.assertEquals(
844+
"{SHA-384}qLZLq9CsqRpZvbt3YbQh1PK7OCgNOnW6DyHyvrxFWD1Eb" +
845+
"FmGYMlM5oDEfRnDB4On",
846+
user.getPassword());
847+
}
848+
}
849+
809850
@Test
810851
public void testPasswordHistory() throws Exception {
811852
User user = UserTestUtil.addUser();

0 commit comments

Comments
 (0)