KEYCLOAK-3266 password policy NotUsername breaks new user registration
This commit is contained in:
parent
2f14fb7fb7
commit
f384c2340e
3 changed files with 40 additions and 9 deletions
|
@ -35,6 +35,9 @@ public class NotUsernamePasswordPolicyProvider implements PasswordPolicyProvider
|
|||
|
||||
@Override
|
||||
public PolicyError validate(String username, String password) {
|
||||
if (username == null) {
|
||||
return null;
|
||||
}
|
||||
return username.equals(password) ? new PolicyError(ERROR_MESSAGE) : null;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,10 @@ import org.keycloak.testsuite.pages.AppPage;
|
|||
import org.keycloak.testsuite.pages.AppPage.RequestType;
|
||||
import org.keycloak.testsuite.pages.LoginPage;
|
||||
import org.keycloak.testsuite.pages.RegisterPage;
|
||||
import org.keycloak.testsuite.util.RealmBuilder;
|
||||
import org.keycloak.testsuite.util.UserBuilder;
|
||||
|
||||
import static org.jgroups.util.Util.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
|
@ -253,15 +256,35 @@ public class RegisterTest extends TestRealmKeycloakTest {
|
|||
assertEquals("lastName", user.getLastName());
|
||||
}
|
||||
|
||||
/*protected UserModel getUser(String userId) {
|
||||
KeycloakSession samlServerSession = keycloakRule.startSession();
|
||||
try {
|
||||
RealmModel brokerRealm = samlServerSession.realms().getRealm("test");
|
||||
return samlServerSession.users().getUserById(userId, brokerRealm);
|
||||
} finally {
|
||||
keycloakRule.stopSession(samlServerSession, false);
|
||||
}
|
||||
}*/
|
||||
// KEYCLOAK-3266
|
||||
@Test
|
||||
public void registerUserNotUsernamePasswordPolicy() {
|
||||
adminClient.realm("test").update(RealmBuilder.create().passwordPolicy("notUsername").build());
|
||||
|
||||
loginPage.open();
|
||||
|
||||
assertTrue(loginPage.isCurrent());
|
||||
|
||||
loginPage.clickRegister();
|
||||
registerPage.assertCurrent();
|
||||
|
||||
registerPage.register("firstName", "lastName", "registerUserNotUsername@email", "registerUserNotUsername", "registerUserNotUsername", "registerUserNotUsername");
|
||||
|
||||
assertTrue(registerPage.isCurrent());
|
||||
assertEquals("Invalid password: must not be equal to the username.", registerPage.getError());
|
||||
|
||||
adminClient.realm("test").users().create(UserBuilder.create().username("registerUserNotUsername").build());
|
||||
|
||||
registerPage.register("firstName", "lastName", "registerUserNotUsername@email", "registerUserNotUsername", "registerUserNotUsername", "registerUserNotUsername");
|
||||
|
||||
assertTrue(registerPage.isCurrent());
|
||||
assertEquals("Username already exists.", registerPage.getError());
|
||||
|
||||
registerPage.register("firstName", "lastName", "registerUserNotUsername@email", null, "password", "password");
|
||||
|
||||
assertTrue(registerPage.isCurrent());
|
||||
assertEquals("Please specify username.", registerPage.getError());
|
||||
}
|
||||
|
||||
protected UserRepresentation getUser(String userId) {
|
||||
return testRealm().users().get(userId).toRepresentation();
|
||||
|
|
|
@ -172,6 +172,11 @@ public class RealmBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
public RealmBuilder passwordPolicy(String passwordPolicy) {
|
||||
rep.setPasswordPolicy(passwordPolicy);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RealmRepresentation build() {
|
||||
return rep;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue