Search in sources :

Example 1 with IgnoreBrowserDriver

use of org.keycloak.testsuite.arquillian.annotation.IgnoreBrowserDriver in project keycloak by keycloak.

the class WebAuthnPropertyTest method changeAuthenticatorProperties.

@Test
@IgnoreBrowserDriver(FirefoxDriver.class)
public void changeAuthenticatorProperties() throws IOException {
    getVirtualAuthManager().useAuthenticator(DEFAULT_RESIDENT_KEY.getOptions());
    try (Closeable c = getWebAuthnRealmUpdater().setWebAuthnPolicyRpEntityName("localhost").setWebAuthnPolicyRequireResidentKey(YES.getValue()).setWebAuthnPolicyUserVerificationRequirement(OPTION_REQUIRED).update()) {
        WebAuthnRealmData realmData = new WebAuthnRealmData(testRealm().toRepresentation(), isPasswordless());
        assertThat(realmData, notNullValue());
        assertThat(realmData.getRpEntityName(), is("localhost"));
        assertThat(realmData.getRequireResidentKey(), is(YES.getValue()));
        assertThat(realmData.getUserVerificationRequirement(), is(OPTION_REQUIRED));
        registerDefaultUser();
        logout();
        getVirtualAuthManager().useAuthenticator(DEFAULT.getOptions());
        WaitUtils.pause(500);
        authenticateDefaultUser(false);
        webAuthnErrorPage.assertCurrent();
    }
}
Also used : Closeable(java.io.Closeable) WebAuthnRealmData(org.keycloak.testsuite.webauthn.utils.WebAuthnRealmData) Test(org.junit.Test) IgnoreBrowserDriver(org.keycloak.testsuite.arquillian.annotation.IgnoreBrowserDriver)

Example 2 with IgnoreBrowserDriver

use of org.keycloak.testsuite.arquillian.annotation.IgnoreBrowserDriver in project keycloak by keycloak.

the class WebAuthnErrorTest method errorPageWithTimeout.

@Test
@IgnoreBrowserDriver(FirefoxDriver.class)
public void errorPageWithTimeout() throws IOException {
    final int timeoutSec = 3;
    final String authenticatorLabel = "authenticator";
    addWebAuthnCredential(authenticatorLabel);
    try (RealmAttributeUpdater u = new WebAuthnRealmAttributeUpdater(testRealmResource()).setWebAuthnPolicyCreateTimeout(timeoutSec).update()) {
        RealmRepresentation realm = testRealmResource().toRepresentation();
        assertThat(realm, notNullValue());
        assertThat(realm.getWebAuthnPolicyCreateTimeout(), is(timeoutSec));
        final int webAuthnCount = webAuthnCredentialType.getUserCredentialsCount();
        assertThat(webAuthnCount, is(1));
        getWebAuthnManager().getCurrent().getAuthenticator().removeAllCredentials();
        setUpWebAuthnFlow("webAuthnFlow");
        logout();
        signingInPage.navigateTo();
        loginToAccount();
        webAuthnLoginPage.assertCurrent();
        final WebAuthnAuthenticatorsList authenticators = webAuthnLoginPage.getAuthenticators();
        assertThat(authenticators.getCount(), is(1));
        assertThat(authenticators.getLabels(), Matchers.contains(authenticatorLabel));
        webAuthnLoginPage.clickAuthenticate();
        // Should fail after this time
        WaitUtils.pause((timeoutSec + 1) * 1000);
        webAuthnErrorPage.assertCurrent();
        assertThat(webAuthnErrorPage.getError(), is("Failed to authenticate by the Security key."));
    }
}
Also used : WebAuthnAuthenticatorsList(org.keycloak.testsuite.webauthn.pages.WebAuthnAuthenticatorsList) WebAuthnRealmAttributeUpdater(org.keycloak.testsuite.webauthn.updaters.WebAuthnRealmAttributeUpdater) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) WebAuthnRealmAttributeUpdater(org.keycloak.testsuite.webauthn.updaters.WebAuthnRealmAttributeUpdater) RealmAttributeUpdater(org.keycloak.testsuite.updaters.RealmAttributeUpdater) Test(org.junit.Test) IgnoreBrowserDriver(org.keycloak.testsuite.arquillian.annotation.IgnoreBrowserDriver)

Example 3 with IgnoreBrowserDriver

use of org.keycloak.testsuite.arquillian.annotation.IgnoreBrowserDriver in project keycloak by keycloak.

the class WebAuthnOtherSettingsTest method timeout.

@Test
@IgnoreBrowserDriver(FirefoxDriver.class)
public void timeout() throws IOException {
    // seconds
    final Integer TIMEOUT = 3;
    getVirtualAuthManager().removeAuthenticator();
    try (Closeable u = getWebAuthnRealmUpdater().setWebAuthnPolicyCreateTimeout(TIMEOUT).update()) {
        WebAuthnRealmData realmData = new WebAuthnRealmData(testRealm().toRepresentation(), isPasswordless());
        assertThat(realmData.getCreateTimeout(), is(TIMEOUT));
        loginPage.open();
        loginPage.clickRegister();
        registerPage.assertCurrent();
        registerPage.register("firstName", "lastName", EMAIL, USERNAME, PASSWORD, PASSWORD);
        // User was registered. Now he needs to register WebAuthn credential
        webAuthnRegisterPage.assertCurrent();
        webAuthnRegisterPage.clickRegister();
        pause((TIMEOUT + 2) * 1000);
        webAuthnErrorPage.assertCurrent();
        assertThat(webAuthnErrorPage.getError(), containsString("The operation either timed out or was not allowed"));
        webAuthnErrorPage.clickTryAgain();
        waitForPageToLoad();
        webAuthnRegisterPage.assertCurrent();
        webAuthnRegisterPage.clickRegister();
        assertThat(webAuthnErrorPage.isCurrent(), is(false));
    }
}
Also used : Closeable(java.io.Closeable) WebAuthnRealmData(org.keycloak.testsuite.webauthn.utils.WebAuthnRealmData) AbstractWebAuthnVirtualTest(org.keycloak.testsuite.webauthn.AbstractWebAuthnVirtualTest) Test(org.junit.Test) IgnoreBrowserDriver(org.keycloak.testsuite.arquillian.annotation.IgnoreBrowserDriver)

Example 4 with IgnoreBrowserDriver

use of org.keycloak.testsuite.arquillian.annotation.IgnoreBrowserDriver in project keycloak by keycloak.

the class BrowserDriverIgnoreDecider method decideIgnoring.

private ExecutionDecision decideIgnoring(AnnotatedElement element) {
    final WebDriver webDriver = driver.get();
    Predicate<IgnoreBrowserDriver> shouldBeIgnored = (item) -> {
        return webDriver != null && (isDriverInstanceOf(webDriver, item.value()) ^ item.negate());
    };
    return Arrays.stream(element.getAnnotationsByType(IgnoreBrowserDriver.class)).filter(shouldBeIgnored).findAny().map(f -> ExecutionDecision.dontExecute("This test should not be executed with this browser.")).orElse(ExecutionDecision.execute());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) TestExecutionDecider(org.jboss.arquillian.test.spi.execution.TestExecutionDecider) Arrays(java.util.Arrays) Predicate(java.util.function.Predicate) WebDriver(org.openqa.selenium.WebDriver) Instance(org.jboss.arquillian.core.api.Instance) IgnoreBrowserDriver(org.keycloak.testsuite.arquillian.annotation.IgnoreBrowserDriver) TestContext(org.keycloak.testsuite.arquillian.TestContext) BrowserDriverUtil.isDriverInstanceOf(org.keycloak.testsuite.util.BrowserDriverUtil.isDriverInstanceOf) Inject(org.jboss.arquillian.core.api.annotation.Inject) ExecutionDecision(org.jboss.arquillian.test.spi.execution.ExecutionDecision) IgnoreBrowserDrivers(org.keycloak.testsuite.arquillian.annotation.IgnoreBrowserDrivers) Method(java.lang.reflect.Method) AnnotatedElement(java.lang.reflect.AnnotatedElement) IgnoreBrowserDriver(org.keycloak.testsuite.arquillian.annotation.IgnoreBrowserDriver)

Example 5 with IgnoreBrowserDriver

use of org.keycloak.testsuite.arquillian.annotation.IgnoreBrowserDriver in project keycloak by keycloak.

the class WebAuthnPropertyTest method residentKey.

@Test
@IgnoreBrowserDriver(FirefoxDriver.class)
public void residentKey() throws IOException {
    getVirtualAuthManager().useAuthenticator(DEFAULT_RESIDENT_KEY.getOptions());
    try (Closeable c = getWebAuthnRealmUpdater().setWebAuthnPolicyRpEntityName("localhost").setWebAuthnPolicyRequireResidentKey(YES.getValue()).setWebAuthnPolicyUserVerificationRequirement(OPTION_REQUIRED).update()) {
        WebAuthnRealmData realmData = new WebAuthnRealmData(testRealm().toRepresentation(), isPasswordless());
        assertThat(realmData, notNullValue());
        assertThat(realmData.getRpEntityName(), is("localhost"));
        assertThat(realmData.getRequireResidentKey(), is(YES.getValue()));
        assertThat(realmData.getUserVerificationRequirement(), is(OPTION_REQUIRED));
        registerDefaultUser();
        UserRepresentation user = userResource().toRepresentation();
        assertThat(user, notNullValue());
        logout();
        events.clear();
        authenticateDefaultUser();
        // confirm that authentication is successfully completed
        events.expectLogin().user(user.getId()).detail(WebAuthnConstants.USER_VERIFICATION_CHECKED, "true").assertEvent();
    }
}
Also used : Closeable(java.io.Closeable) WebAuthnRealmData(org.keycloak.testsuite.webauthn.utils.WebAuthnRealmData) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) Test(org.junit.Test) IgnoreBrowserDriver(org.keycloak.testsuite.arquillian.annotation.IgnoreBrowserDriver)

Aggregations

IgnoreBrowserDriver (org.keycloak.testsuite.arquillian.annotation.IgnoreBrowserDriver)6 Test (org.junit.Test)5 Closeable (java.io.Closeable)4 WebAuthnRealmData (org.keycloak.testsuite.webauthn.utils.WebAuthnRealmData)4 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 Method (java.lang.reflect.Method)1 Arrays (java.util.Arrays)1 Predicate (java.util.function.Predicate)1 Instance (org.jboss.arquillian.core.api.Instance)1 Inject (org.jboss.arquillian.core.api.annotation.Inject)1 ExecutionDecision (org.jboss.arquillian.test.spi.execution.ExecutionDecision)1 TestExecutionDecider (org.jboss.arquillian.test.spi.execution.TestExecutionDecider)1 RealmRepresentation (org.keycloak.representations.idm.RealmRepresentation)1 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)1 TestContext (org.keycloak.testsuite.arquillian.TestContext)1 IgnoreBrowserDrivers (org.keycloak.testsuite.arquillian.annotation.IgnoreBrowserDrivers)1 RealmAttributeUpdater (org.keycloak.testsuite.updaters.RealmAttributeUpdater)1 BrowserDriverUtil.isDriverInstanceOf (org.keycloak.testsuite.util.BrowserDriverUtil.isDriverInstanceOf)1 AbstractWebAuthnVirtualTest (org.keycloak.testsuite.webauthn.AbstractWebAuthnVirtualTest)1 WebAuthnAuthenticatorsList (org.keycloak.testsuite.webauthn.pages.WebAuthnAuthenticatorsList)1