Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
ba082b0d6d
35 files changed
+1333
-194
No files matched your search
@@ -200,6 +200,13 @@
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<workingDirectory>${project.basedir}</workingDirectory>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
@@ -112,17 +112,27 @@ public class KeycloakServer {
|
||||
|
||||
if (System.getProperties().containsKey("resources")) {
|
||||
String resources = System.getProperty("resources");
|
||||
if (resources == null || resources.equals("")) {
|
||||
for (String c : System.getProperty("java.class.path").split(File.pathSeparator)) {
|
||||
if (c.contains("keycloak" + File.separator + "testsuite" + File.separator + "integration")) {
|
||||
config.setResourcesHome(c.replaceFirst("testsuite.integration.*", ""));
|
||||
if (resources == null || resources.equals("") || resources.equals("true")) {
|
||||
if (System.getProperties().containsKey("maven.home")) {
|
||||
resources = System.getProperty("user.dir").replaceFirst("testsuite.integration.*", "");
|
||||
} else {
|
||||
for (String c : System.getProperty("java.class.path").split(File.pathSeparator)) {
|
||||
if (c.contains(File.separator + "testsuite" + File.separator + "integration")) {
|
||||
resources = c.replaceFirst("testsuite.integration.*", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
config.setResourcesHome(resources);
|
||||
}
|
||||
|
||||
File dir = new File(resources).getAbsoluteFile();
|
||||
if (!dir.isDirectory() || !new File(dir, "admin-ui").isDirectory()) {
|
||||
throw new RuntimeException("Invalid resources directory");
|
||||
}
|
||||
|
||||
config.setResourcesHome(dir.getAbsolutePath());
|
||||
}
|
||||
|
||||
|
||||
final KeycloakServer keycloak = new KeycloakServer(config);
|
||||
keycloak.sysout = true;
|
||||
keycloak.start();
|
||||
@@ -291,9 +301,9 @@ public class KeycloakServer {
|
||||
if (path.startsWith("/forms")) {
|
||||
file = file(resourcesHome, "forms", "src", "main", "resources", "META-INF", "resources", path.replace('/', File.separatorChar));
|
||||
} else if (path.startsWith("/admin")) {
|
||||
file = file(resourcesHome, "admin-ui", "src", "main", "resources", "META-INF", "resources", path.replace('/', File.separatorChar));
|
||||
file = file(resourcesHome, "admin-ui", "src", "main", "resources", "META-INF", "resources", path.replace('/', File.separatorChar));
|
||||
if (!file.isFile()) {
|
||||
file = file(resourcesHome, "admin-ui-styles", "src", "main", "resources", "META-INF", "resources", path.replace('/', File.separatorChar));
|
||||
file = file(resourcesHome, "admin-ui-styles", "src", "main", "resources", "META-INF", "resources", path.replace('/', File.separatorChar));
|
||||
}
|
||||
} else {
|
||||
throw new IOException("Unknown resource " + path);
|
||||
@@ -305,10 +315,9 @@ public class KeycloakServer {
|
||||
|
||||
private static File file(String... path) {
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.append(path[0]);
|
||||
for (int i = 1; i < path.length; i++) {
|
||||
for (String p : path) {
|
||||
s.append(File.separator);
|
||||
s.append(path[i]);
|
||||
s.append(p);
|
||||
}
|
||||
return new File(s.toString());
|
||||
}
|
||||
|
||||
+69
-4
@@ -30,6 +30,8 @@ import org.keycloak.services.managers.RealmManager;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.UserModel;
|
||||
import org.keycloak.models.UserModel.RequiredAction;
|
||||
import org.keycloak.testsuite.OAuthClient;
|
||||
import org.keycloak.testsuite.pages.AccountTotpPage;
|
||||
import org.keycloak.testsuite.pages.AppPage;
|
||||
import org.keycloak.testsuite.pages.AppPage.RequestType;
|
||||
import org.keycloak.testsuite.pages.LoginConfigTotpPage;
|
||||
@@ -54,9 +56,6 @@ public class RequiredActionTotpSetupTest {
|
||||
public void config(RealmManager manager, RealmModel defaultRealm, RealmModel appRealm) {
|
||||
appRealm.addRequiredCredential(CredentialRepresentation.TOTP);
|
||||
appRealm.setResetPasswordAllowed(true);
|
||||
|
||||
UserModel user = appRealm.getUser("test-user@localhost");
|
||||
user.addRequiredAction(RequiredAction.CONFIGURE_TOTP);
|
||||
}
|
||||
|
||||
});
|
||||
@@ -76,6 +75,12 @@ public class RequiredActionTotpSetupTest {
|
||||
@WebResource
|
||||
protected LoginConfigTotpPage totpPage;
|
||||
|
||||
@WebResource
|
||||
protected AccountTotpPage accountTotpPage;
|
||||
|
||||
@WebResource
|
||||
protected OAuthClient oauth;
|
||||
|
||||
@WebResource
|
||||
protected RegisterPage registerPage;
|
||||
|
||||
@@ -101,9 +106,69 @@ public class RequiredActionTotpSetupTest {
|
||||
|
||||
totpPage.assertCurrent();
|
||||
|
||||
totpPage.configure(totp.generate(totpPage.getTotpSecret()));
|
||||
String totpSecret = totpPage.getTotpSecret();
|
||||
|
||||
totpPage.configure(totp.generate(totpSecret));
|
||||
|
||||
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
|
||||
|
||||
oauth.openLogout();
|
||||
|
||||
loginPage.open();
|
||||
loginPage.loginTotp("test-user@localhost", "password", totp.generate(totpSecret));
|
||||
|
||||
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setupTotpRegisteredAfterTotpRemoval() {
|
||||
// Register new user
|
||||
loginPage.open();
|
||||
loginPage.clickRegister();
|
||||
registerPage.register("firstName2", "lastName2", "email2", "setupTotp2", "password2", "password2");
|
||||
|
||||
// Configure totp
|
||||
totpPage.assertCurrent();
|
||||
|
||||
String totpCode = totpPage.getTotpSecret();
|
||||
totpPage.configure(totp.generate(totpCode));
|
||||
|
||||
// After totp config, user should be on the app page
|
||||
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
|
||||
|
||||
// Logout
|
||||
oauth.openLogout();
|
||||
|
||||
// Try to login after logout
|
||||
loginPage.open();
|
||||
loginPage.login("setupTotp2", "password2");
|
||||
|
||||
// Totp is already configured, thus one-time password is needed, login page should be loaded
|
||||
Assert.assertTrue(loginPage.isCurrent());
|
||||
Assert.assertFalse(totpPage.isCurrent());
|
||||
|
||||
// Login with one-time password
|
||||
loginPage.loginTotp("setupTotp2", "password2", totp.generate(totpCode));
|
||||
|
||||
// Open account page
|
||||
accountTotpPage.open();
|
||||
accountTotpPage.assertCurrent();
|
||||
|
||||
// Remove google authentificator
|
||||
accountTotpPage.removeTotp();
|
||||
|
||||
// Logout
|
||||
oauth.openLogout();
|
||||
|
||||
// Try to login
|
||||
loginPage.open();
|
||||
loginPage.login("setupTotp2", "password2");
|
||||
|
||||
// Since the authentificator was removed, it has to be set up again
|
||||
totpPage.assertCurrent();
|
||||
totpPage.configure(totp.generate(totpPage.getTotpSecret()));
|
||||
|
||||
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
|
||||
|
||||
}
|
||||
}
|
||||
+8
-1
@@ -41,6 +41,9 @@ public class AccountTotpPage extends Page {
|
||||
@FindBy(css = "button[type=\"submit\"]")
|
||||
private WebElement submitButton;
|
||||
|
||||
@FindBy(linkText = "Remove Google")
|
||||
private WebElement removeLink;
|
||||
|
||||
public void configure(String totp) {
|
||||
totpInput.sendKeys(totp);
|
||||
submitButton.click();
|
||||
@@ -51,11 +54,15 @@ public class AccountTotpPage extends Page {
|
||||
}
|
||||
|
||||
public boolean isCurrent() {
|
||||
return driver.getPageSource().contains("Google Authenticator Setup");
|
||||
return driver.getTitle().contains("Edit Account - Google Authenticator");
|
||||
}
|
||||
|
||||
public void open() {
|
||||
driver.navigate().to(PATH);
|
||||
}
|
||||
|
||||
public void removeTotp() {
|
||||
removeLink.click();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -41,6 +41,9 @@ public class LoginPage extends Page {
|
||||
@FindBy(id = "password")
|
||||
private WebElement passwordInput;
|
||||
|
||||
@FindBy(id = "totp")
|
||||
private WebElement totp;
|
||||
|
||||
@FindBy(css = "input[type=\"submit\"]")
|
||||
private WebElement submitButton;
|
||||
|
||||
@@ -63,6 +66,19 @@ public class LoginPage extends Page {
|
||||
submitButton.click();
|
||||
}
|
||||
|
||||
public void loginTotp(String username, String password, String code) {
|
||||
usernameInput.clear();
|
||||
usernameInput.sendKeys(username);
|
||||
|
||||
passwordInput.clear();
|
||||
passwordInput.sendKeys(password);
|
||||
|
||||
totp.clear();
|
||||
totp.sendKeys(code);
|
||||
|
||||
submitButton.click();
|
||||
}
|
||||
|
||||
public String getError() {
|
||||
return loginErrorMessage != null ? loginErrorMessage.getText() : null;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public abstract class Page {
|
||||
|
||||
public void assertCurrent() {
|
||||
String name = getClass().getSimpleName();
|
||||
Assert.assertTrue("Exptected " + name + " but was " + driver.getTitle() + " (" + driver.getCurrentUrl() + ")",
|
||||
Assert.assertTrue("Expected " + name + " but was " + driver.getTitle() + " (" + driver.getCurrentUrl() + ")",
|
||||
isCurrent());
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user