Search in sources :

Example 1 with Page

use of org.jboss.arquillian.graphene.page.Page in project keycloak by keycloak.

the class BrowserFlowTest method testAlternativeNonInteractiveExecutorInSubflow.

@Test
@AuthServerContainerExclude(REMOTE)
// TODO remove this (KEYCLOAK-16228)
@DisableFeature(value = Profile.Feature.ACCOUNT2, skipRestart = true)
public void testAlternativeNonInteractiveExecutorInSubflow() {
    final String newFlowAlias = "browser - alternative non-interactive executor";
    testingClient.server("test").run(session -> FlowUtil.inCurrentRealm(session).copyBrowserFlow(newFlowAlias));
    testingClient.server("test").run(session -> FlowUtil.inCurrentRealm(session).selectFlow(newFlowAlias).inForms(forms -> forms.clear().addAuthenticatorExecution(AuthenticationExecutionModel.Requirement.REQUIRED, UsernameFormFactory.PROVIDER_ID).addSubFlowExecution(Requirement.REQUIRED, reqSubFlow -> reqSubFlow.addAuthenticatorExecution(Requirement.ALTERNATIVE, PassThroughAuthenticator.PROVIDER_ID))).defineAsBrowserFlow());
    try {
        // provides username
        loginUsernameOnlyPage.open();
        loginUsernameOnlyPage.login("test-user@localhost");
        // Check that Keycloak is redirecting us to the Keycloak account management page
        WebElement aHref = driver.findElement(By.tagName("a"));
        driver.get(aHref.getAttribute("href"));
        assertThat(driver.getTitle(), containsString("Account Management"));
    } finally {
        revertFlows("browser - alternative non-interactive executor");
    }
}
Also used : Arrays(java.util.Arrays) UsernameFormFactory(org.keycloak.authentication.authenticators.browser.UsernameFormFactory) AbstractAdminTest.loadJson(org.keycloak.testsuite.admin.AbstractAdminTest.loadJson) AssertEvents(org.keycloak.testsuite.AssertEvents) WebElement(org.openqa.selenium.WebElement) SetUserAttributeAuthenticatorFactory(org.keycloak.testsuite.authentication.SetUserAttributeAuthenticatorFactory) Page(org.jboss.arquillian.graphene.page.Page) DefaultAuthenticationFlows(org.keycloak.models.utils.DefaultAuthenticationFlows) OAuthClient(org.keycloak.testsuite.util.OAuthClient) REMOTE(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude.AuthServer.REMOTE) LoginTotpPage(org.keycloak.testsuite.pages.LoginTotpPage) Requirement(org.keycloak.models.AuthenticationExecutionModel.Requirement) GOOGLE(org.keycloak.testsuite.broker.SocialLoginTest.Provider.GOOGLE) UsernamePasswordFormFactory(org.keycloak.authentication.authenticators.browser.UsernamePasswordFormFactory) RealmResource(org.keycloak.admin.client.resource.RealmResource) DisableFeature(org.keycloak.testsuite.arquillian.annotation.DisableFeature) GITLAB(org.keycloak.testsuite.broker.SocialLoginTest.Provider.GITLAB) URLUtils(org.keycloak.testsuite.util.URLUtils) PasswordFormFactory(org.keycloak.authentication.authenticators.browser.PasswordFormFactory) ConditionalUserConfiguredAuthenticatorFactory(org.keycloak.authentication.authenticators.conditional.ConditionalUserConfiguredAuthenticatorFactory) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) ConditionalRoleAuthenticatorFactory(org.keycloak.authentication.authenticators.conditional.ConditionalRoleAuthenticatorFactory) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) RoleBuilder(org.keycloak.testsuite.util.RoleBuilder) List(java.util.List) GITHUB(org.keycloak.testsuite.broker.SocialLoginTest.Provider.GITHUB) Details(org.keycloak.events.Details) LoginPage(org.keycloak.testsuite.pages.LoginPage) OneTimeCode(org.keycloak.testsuite.auth.page.login.OneTimeCode) ActionURIUtils(org.keycloak.testsuite.ActionURIUtils) SocialLoginTest(org.keycloak.testsuite.broker.SocialLoginTest) WebAuthnRegisterFactory(org.keycloak.authentication.requiredactions.WebAuthnRegisterFactory) Matchers.containsString(org.hamcrest.Matchers.containsString) IdentityProviderRepresentation(org.keycloak.representations.idm.IdentityProviderRepresentation) ConditionalUserAttributeValueFactory(org.keycloak.testsuite.authentication.ConditionalUserAttributeValueFactory) Profile(org.keycloak.common.Profile) AuthServerContainerExclude(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude) WebDriver(org.openqa.selenium.WebDriver) Constants(org.keycloak.models.Constants) TimeBasedOTP(org.keycloak.models.utils.TimeBasedOTP) OTPFormAuthenticatorFactory(org.keycloak.authentication.authenticators.browser.OTPFormAuthenticatorFactory) WebAuthnAuthenticatorFactory(org.keycloak.authentication.authenticators.browser.WebAuthnAuthenticatorFactory) EnableFeature(org.keycloak.testsuite.arquillian.annotation.EnableFeature) Drone(org.jboss.arquillian.drone.api.annotation.Drone) AuthenticationExecutionModel(org.keycloak.models.AuthenticationExecutionModel) AuthenticationFlowRepresentation(org.keycloak.representations.idm.AuthenticationFlowRepresentation) ArquillianResource(org.jboss.arquillian.test.api.ArquillianResource) FlowUtil(org.keycloak.testsuite.util.FlowUtil) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) UserResource(org.keycloak.admin.client.resource.UserResource) RequiredActionProviderSimpleRepresentation(org.keycloak.representations.idm.RequiredActionProviderSimpleRepresentation) ApiUtil(org.keycloak.testsuite.admin.ApiUtil) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) By(org.openqa.selenium.By) PasswordPage(org.keycloak.testsuite.pages.PasswordPage) RequiredActionProviderRepresentation(org.keycloak.representations.idm.RequiredActionProviderRepresentation) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest) AbstractAuthenticationTest(org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) LoginUsernameOnlyPage(org.keycloak.testsuite.pages.LoginUsernameOnlyPage) ErrorPage(org.keycloak.testsuite.pages.ErrorPage) Assert(org.junit.Assert) Collections(java.util.Collections) OTPFormAuthenticator(org.keycloak.authentication.authenticators.browser.OTPFormAuthenticator) Matchers.containsString(org.hamcrest.Matchers.containsString) WebElement(org.openqa.selenium.WebElement) AuthServerContainerExclude(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude) DisableFeature(org.keycloak.testsuite.arquillian.annotation.DisableFeature) SocialLoginTest(org.keycloak.testsuite.broker.SocialLoginTest) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest) AbstractAuthenticationTest(org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest)

Example 2 with Page

use of org.jboss.arquillian.graphene.page.Page in project keycloak by keycloak.

the class AbstractX509AuthenticationTest method replaceDefaultWebDriver.

public void replaceDefaultWebDriver(WebDriver driver) {
    this.driver = driver;
    DroneUtils.addWebDriver(driver);
    List<Field> allFields = new ArrayList<>();
    // Add all fields of this class and superclasses
    Class<?> testClass = this.getClass();
    while (AbstractX509AuthenticationTest.class.isAssignableFrom(testClass)) {
        allFields.addAll(Arrays.asList(testClass.getDeclaredFields()));
        allFields.addAll(Arrays.asList(testClass.getFields()));
        testClass = testClass.getSuperclass();
    }
    for (Field f : allFields) {
        if (f.getAnnotation(Page.class) != null) {
            try {
                AbstractPage page = (AbstractPage) f.get(this);
                page.setDriver(driver);
            } catch (IllegalAccessException e) {
                throw new IllegalStateException("Could not replace the driver in " + f, e);
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) AbstractPage(org.keycloak.testsuite.pages.AbstractPage) ArrayList(java.util.ArrayList) Page(org.jboss.arquillian.graphene.page.Page) LoginPage(org.keycloak.testsuite.pages.LoginPage) X509IdentityConfirmationPage(org.keycloak.testsuite.pages.x509.X509IdentityConfirmationPage) AppPage(org.keycloak.testsuite.pages.AppPage) AbstractPage(org.keycloak.testsuite.pages.AbstractPage)

Example 3 with Page

use of org.jboss.arquillian.graphene.page.Page in project keycloak by keycloak.

the class BrowserFlowTest method testSwitchExecutionNotAllowedWithRequiredPasswordAndAlternativeOTP.

@Test
@AuthServerContainerExclude(REMOTE)
public void testSwitchExecutionNotAllowedWithRequiredPasswordAndAlternativeOTP() {
    String newFlowAlias = "browser - copy 1";
    configureBrowserFlowWithRequiredPasswordFormAndAlternativeOTP(newFlowAlias);
    try {
        loginUsernameOnlyPage.open();
        loginUsernameOnlyPage.assertCurrent();
        loginUsernameOnlyPage.login("user-with-one-configured-otp");
        // Assert on password page now
        passwordPage.assertCurrent();
        String otpAuthenticatorExecutionId = realmsResouce().realm("test").flows().getExecutions(newFlowAlias).stream().filter(execution -> OTPFormAuthenticatorFactory.PROVIDER_ID.equals(execution.getProviderId())).findFirst().get().getId();
        // Manually run request to switch execution to OTP. It shouldn't be allowed and error should be thrown
        String actionURL = ActionURIUtils.getActionURIFromPageSource(driver.getPageSource());
        String formParameters = Constants.AUTHENTICATION_EXECUTION + "=" + otpAuthenticatorExecutionId + "&" + Constants.CREDENTIAL_ID + "=";
        URLUtils.sendPOSTRequestWithWebDriver(actionURL, formParameters);
        errorPage.assertCurrent();
    } finally {
        revertFlows("browser - copy 1");
    }
}
Also used : Arrays(java.util.Arrays) UsernameFormFactory(org.keycloak.authentication.authenticators.browser.UsernameFormFactory) AbstractAdminTest.loadJson(org.keycloak.testsuite.admin.AbstractAdminTest.loadJson) AssertEvents(org.keycloak.testsuite.AssertEvents) WebElement(org.openqa.selenium.WebElement) SetUserAttributeAuthenticatorFactory(org.keycloak.testsuite.authentication.SetUserAttributeAuthenticatorFactory) Page(org.jboss.arquillian.graphene.page.Page) DefaultAuthenticationFlows(org.keycloak.models.utils.DefaultAuthenticationFlows) OAuthClient(org.keycloak.testsuite.util.OAuthClient) REMOTE(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude.AuthServer.REMOTE) LoginTotpPage(org.keycloak.testsuite.pages.LoginTotpPage) Requirement(org.keycloak.models.AuthenticationExecutionModel.Requirement) GOOGLE(org.keycloak.testsuite.broker.SocialLoginTest.Provider.GOOGLE) UsernamePasswordFormFactory(org.keycloak.authentication.authenticators.browser.UsernamePasswordFormFactory) RealmResource(org.keycloak.admin.client.resource.RealmResource) DisableFeature(org.keycloak.testsuite.arquillian.annotation.DisableFeature) GITLAB(org.keycloak.testsuite.broker.SocialLoginTest.Provider.GITLAB) URLUtils(org.keycloak.testsuite.util.URLUtils) PasswordFormFactory(org.keycloak.authentication.authenticators.browser.PasswordFormFactory) ConditionalUserConfiguredAuthenticatorFactory(org.keycloak.authentication.authenticators.conditional.ConditionalUserConfiguredAuthenticatorFactory) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) ConditionalRoleAuthenticatorFactory(org.keycloak.authentication.authenticators.conditional.ConditionalRoleAuthenticatorFactory) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) RoleBuilder(org.keycloak.testsuite.util.RoleBuilder) List(java.util.List) GITHUB(org.keycloak.testsuite.broker.SocialLoginTest.Provider.GITHUB) Details(org.keycloak.events.Details) LoginPage(org.keycloak.testsuite.pages.LoginPage) OneTimeCode(org.keycloak.testsuite.auth.page.login.OneTimeCode) ActionURIUtils(org.keycloak.testsuite.ActionURIUtils) SocialLoginTest(org.keycloak.testsuite.broker.SocialLoginTest) WebAuthnRegisterFactory(org.keycloak.authentication.requiredactions.WebAuthnRegisterFactory) Matchers.containsString(org.hamcrest.Matchers.containsString) IdentityProviderRepresentation(org.keycloak.representations.idm.IdentityProviderRepresentation) ConditionalUserAttributeValueFactory(org.keycloak.testsuite.authentication.ConditionalUserAttributeValueFactory) Profile(org.keycloak.common.Profile) AuthServerContainerExclude(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude) WebDriver(org.openqa.selenium.WebDriver) Constants(org.keycloak.models.Constants) TimeBasedOTP(org.keycloak.models.utils.TimeBasedOTP) OTPFormAuthenticatorFactory(org.keycloak.authentication.authenticators.browser.OTPFormAuthenticatorFactory) WebAuthnAuthenticatorFactory(org.keycloak.authentication.authenticators.browser.WebAuthnAuthenticatorFactory) EnableFeature(org.keycloak.testsuite.arquillian.annotation.EnableFeature) Drone(org.jboss.arquillian.drone.api.annotation.Drone) AuthenticationExecutionModel(org.keycloak.models.AuthenticationExecutionModel) AuthenticationFlowRepresentation(org.keycloak.representations.idm.AuthenticationFlowRepresentation) ArquillianResource(org.jboss.arquillian.test.api.ArquillianResource) FlowUtil(org.keycloak.testsuite.util.FlowUtil) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) UserResource(org.keycloak.admin.client.resource.UserResource) RequiredActionProviderSimpleRepresentation(org.keycloak.representations.idm.RequiredActionProviderSimpleRepresentation) ApiUtil(org.keycloak.testsuite.admin.ApiUtil) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) By(org.openqa.selenium.By) PasswordPage(org.keycloak.testsuite.pages.PasswordPage) RequiredActionProviderRepresentation(org.keycloak.representations.idm.RequiredActionProviderRepresentation) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest) AbstractAuthenticationTest(org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) LoginUsernameOnlyPage(org.keycloak.testsuite.pages.LoginUsernameOnlyPage) ErrorPage(org.keycloak.testsuite.pages.ErrorPage) Assert(org.junit.Assert) Collections(java.util.Collections) OTPFormAuthenticator(org.keycloak.authentication.authenticators.browser.OTPFormAuthenticator) Matchers.containsString(org.hamcrest.Matchers.containsString) AuthServerContainerExclude(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude) SocialLoginTest(org.keycloak.testsuite.broker.SocialLoginTest) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest) AbstractAuthenticationTest(org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest)

Aggregations

Page (org.jboss.arquillian.graphene.page.Page)3 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 List (java.util.List)2 Consumer (java.util.function.Consumer)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Drone (org.jboss.arquillian.drone.api.annotation.Drone)2 ArquillianResource (org.jboss.arquillian.test.api.ArquillianResource)2 Assert (org.junit.Assert)2 Rule (org.junit.Rule)2 Test (org.junit.Test)2 RealmResource (org.keycloak.admin.client.resource.RealmResource)2 UserResource (org.keycloak.admin.client.resource.UserResource)2 OTPFormAuthenticator (org.keycloak.authentication.authenticators.browser.OTPFormAuthenticator)2 OTPFormAuthenticatorFactory (org.keycloak.authentication.authenticators.browser.OTPFormAuthenticatorFactory)2 PasswordFormFactory (org.keycloak.authentication.authenticators.browser.PasswordFormFactory)2 UsernameFormFactory (org.keycloak.authentication.authenticators.browser.UsernameFormFactory)2 UsernamePasswordFormFactory (org.keycloak.authentication.authenticators.browser.UsernamePasswordFormFactory)2 WebAuthnAuthenticatorFactory (org.keycloak.authentication.authenticators.browser.WebAuthnAuthenticatorFactory)2