Skip to content
Snippets Groups Projects
Commit d95a2884 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-3961 fix random password generation

parent de87e75f
Branches
Tags
No related merge requests found
......@@ -154,10 +154,10 @@ class KeycloakUserRemoteService {
return StringUtils.isEmpty(userPassword) ? generateRandomPasswordForKeycloak() : userPassword;
}
private String generateRandomPasswordForKeycloak() {
String generateRandomPasswordForKeycloak() {
log.log(Level.INFO, "Generate password...");
var upperCaseCharacter = RandomStringUtils.random(1).toUpperCase();
var randomString = RandomStringUtils.random(7);
var upperCaseCharacter = RandomStringUtils.randomAlphabetic(1).toUpperCase();
var randomString = RandomStringUtils.randomAlphanumeric(7);
log.log(Level.INFO, "Password generated: " + (upperCaseCharacter + randomString));
return upperCaseCharacter + randomString;
}
......
......@@ -420,11 +420,35 @@ class KeycloakUserRemoteServiceTest {
@Test
void shouldGeneratePasswordIfNotExists() {
var password = userRemoteService.getPassword(StringUtils.EMPTY);
userRemoteService.getPassword(StringUtils.EMPTY);
assertThat(password).isNotEmpty();
assertThat(StringUtils.substring(password, 0, 1)).isUpperCase();
assertThat(StringUtils.substring(password, 1, password.length())).isUpperCase();
verify(userRemoteService).generateRandomPasswordForKeycloak();
}
@DisplayName("generate random password for keycloak")
@Nested
class TestGenerateRandomPasswordForKeycloak {
@Test
void shouldHaveSize() {
var password = userRemoteService.getPassword(StringUtils.EMPTY);
assertThat(password).hasSize(8);
}
@Test
void shouldHaveUpperCaseLetterAtFirst() {
var password = userRemoteService.getPassword(StringUtils.EMPTY);
assertThat(StringUtils.substring(password, 0, 1)).isUpperCase();
}
@Test
void shouldContainsAlphanumericOnly() {
var password = userRemoteService.getPassword(StringUtils.EMPTY);
assertThat(password).isAlphanumeric();
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment