Search in sources :

Example 21 with WebAuthnRealmData

use of org.keycloak.testsuite.webauthn.utils.WebAuthnRealmData in project keycloak by keycloak.

the class AuthAttachmentRegisterTest method assertAuthenticatorAttachment.

private void assertAuthenticatorAttachment(boolean shouldSuccess, AuthenticatorAttachment attachment) {
    try (Closeable u = getWebAuthnRealmUpdater().setWebAuthnPolicyAuthenticatorAttachment(attachment.getValue()).update()) {
        WebAuthnRealmData realmData = new WebAuthnRealmData(testRealm().toRepresentation(), isPasswordless());
        assertThat(realmData.getAuthenticatorAttachment(), is(attachment.getValue()));
        registerDefaultUser(shouldSuccess);
        displayErrorMessageIfPresent();
        assertThat(webAuthnErrorPage.isCurrent(), is(!shouldSuccess));
    } catch (IOException e) {
        throw new RuntimeException(e.getCause());
    }
}
Also used : Closeable(java.io.Closeable) IOException(java.io.IOException) WebAuthnRealmData(org.keycloak.testsuite.webauthn.utils.WebAuthnRealmData)

Example 22 with WebAuthnRealmData

use of org.keycloak.testsuite.webauthn.utils.WebAuthnRealmData in project keycloak by keycloak.

the class PubKeySignRegisterTest method assertPublicKeyAlgorithms.

private void assertPublicKeyAlgorithms(boolean shouldSuccess, COSEAlgorithmIdentifier selectedAlgorithm, List<String> algorithms) {
    assertThat(algorithms, notNullValue());
    try (Closeable u = getWebAuthnRealmUpdater().setWebAuthnPolicySignatureAlgorithms(algorithms).update()) {
        if (!algorithms.isEmpty()) {
            WebAuthnRealmData realmData = new WebAuthnRealmData(testRealm().toRepresentation(), isPasswordless());
            assertThat(realmData.getSignatureAlgorithms(), is(algorithms));
        }
        registerDefaultUser(shouldSuccess);
        assertThat(webAuthnErrorPage.isCurrent(), is(!shouldSuccess));
        if (!shouldSuccess) {
            final String expectedMessage = getExpectedMessageByDriver("NotSupportedError: Operation is not supported", "The operation either timed out or was not allowed");
            assertThat(webAuthnErrorPage.getError(), containsString(expectedMessage));
            return;
        }
        final String credentialType = getCredentialType();
        getTestingClient().server(TEST_REALM_NAME).run(session -> {
            final WebAuthnDataWrapper dataWrapper = new WebAuthnDataWrapper(session, USERNAME, credentialType);
            assertThat(dataWrapper, notNullValue());
            final WebAuthnCredentialData data = dataWrapper.getWebAuthnData();
            assertThat(data, notNullValue());
            final COSEKey pubKey = dataWrapper.getKey();
            assertThat(pubKey, notNullValue());
            assertThat(pubKey.getAlgorithm(), notNullValue());
            assertThat(pubKey.getAlgorithm().getValue(), is(selectedAlgorithm.getValue()));
            assertThat(pubKey.hasPublicKey(), is(true));
        });
    } catch (IOException e) {
        throw new RuntimeException(e.getCause());
    }
}
Also used : WebAuthnDataWrapper(org.keycloak.testsuite.webauthn.utils.WebAuthnDataWrapper) WebAuthnCredentialData(org.keycloak.models.credential.dto.WebAuthnCredentialData) COSEKey(com.webauthn4j.data.attestation.authenticator.COSEKey) Closeable(java.io.Closeable) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IOException(java.io.IOException) WebAuthnRealmData(org.keycloak.testsuite.webauthn.utils.WebAuthnRealmData)

Example 23 with WebAuthnRealmData

use of org.keycloak.testsuite.webauthn.utils.WebAuthnRealmData 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)

Example 24 with WebAuthnRealmData

use of org.keycloak.testsuite.webauthn.utils.WebAuthnRealmData in project keycloak by keycloak.

the class WebAuthnPropertyTest method timeout.

@Test
@IgnoreBrowserDriver(FirefoxDriver.class)
public void timeout() throws IOException {
    // seconds
    final Integer TIMEOUT = 3;
    registerDefaultUser();
    logout();
    getVirtualAuthManager().removeAuthenticator();
    try (Closeable u = getWebAuthnRealmUpdater().setWebAuthnPolicyCreateTimeout(TIMEOUT).update()) {
        WebAuthnRealmData realmData = new WebAuthnRealmData(testRealm().toRepresentation(), isPasswordless());
        assertThat(realmData.getCreateTimeout(), is(TIMEOUT));
        authenticateDefaultUser(false);
        WaitUtils.pause((TIMEOUT + 2) * 1000);
        webAuthnErrorPage.assertCurrent();
        assertThat(webAuthnErrorPage.getError(), containsString("Failed to authenticate by the Security key."));
    }
}
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 25 with WebAuthnRealmData

use of org.keycloak.testsuite.webauthn.utils.WebAuthnRealmData in project keycloak by keycloak.

the class WebAuthnPolicySettingsTest method rpEntityValues.

@Test
public void rpEntityValues() {
    String rpEntityName = getPolicyPage().getRpEntityName();
    assertThat(rpEntityName, notNullValue());
    assertThat(rpEntityName, is(Constants.DEFAULT_WEBAUTHN_POLICY_RP_ENTITY_NAME));
    getPolicyPage().setRpEntityName("newEntityName");
    getPolicyPage().clickSaveButton();
    AbstractPatternFlyAlert.waitUntilHidden();
    rpEntityName = getPolicyPage().getRpEntityName();
    assertThat(rpEntityName, notNullValue());
    assertThat(rpEntityName, is("newEntityName"));
    getPolicyPage().setRpEntityName("");
    getPolicyPage().clickSaveButton();
    AbstractPatternFlyAlert.waitUntilHidden();
    rpEntityName = getPolicyPage().getRpEntityName();
    assertThat(rpEntityName, notNullValue());
    assertThat(rpEntityName, is(Constants.DEFAULT_WEBAUTHN_POLICY_RP_ENTITY_NAME));
    String rpEntityId = getPolicyPage().getRpEntityId();
    assertThat(rpEntityId, notNullValue());
    assertThat(rpEntityId, is(""));
    getPolicyPage().setRpEntityId("rpId123");
    getPolicyPage().clickSaveButton();
    AbstractPatternFlyAlert.waitUntilHidden();
    rpEntityId = getPolicyPage().getRpEntityId();
    assertThat(rpEntityId, notNullValue());
    assertThat(rpEntityId, is("rpId123"));
    final WebAuthnRealmData realm = new WebAuthnRealmData(testRealmResource().toRepresentation(), isPasswordless());
    assertThat(realm, notNullValue());
    assertThat(realm.getRpEntityName(), is(Constants.DEFAULT_WEBAUTHN_POLICY_RP_ENTITY_NAME));
    assertThat(realm.getRpId(), is("rpId123"));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) WebAuthnRealmData(org.keycloak.testsuite.webauthn.utils.WebAuthnRealmData) AbstractConsoleTest(org.keycloak.testsuite.console.AbstractConsoleTest) Test(org.junit.Test)

Aggregations

WebAuthnRealmData (org.keycloak.testsuite.webauthn.utils.WebAuthnRealmData)29 Test (org.junit.Test)22 Closeable (java.io.Closeable)12 AbstractConsoleTest (org.keycloak.testsuite.console.AbstractConsoleTest)10 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)9 AbstractWebAuthnVirtualTest (org.keycloak.testsuite.webauthn.AbstractWebAuthnVirtualTest)9 IOException (java.io.IOException)6 IgnoreBrowserDriver (org.keycloak.testsuite.arquillian.annotation.IgnoreBrowserDriver)4 WebAuthnCredentialData (org.keycloak.models.credential.dto.WebAuthnCredentialData)3 WebAuthnDataWrapper (org.keycloak.testsuite.webauthn.utils.WebAuthnDataWrapper)3 NoSuchElementException (org.openqa.selenium.NoSuchElementException)2 Credential (org.openqa.selenium.virtualauthenticator.Credential)2 AttestationConveyancePreference (com.webauthn4j.data.AttestationConveyancePreference)1 AuthenticatorAttachment (com.webauthn4j.data.AuthenticatorAttachment)1 UserVerificationRequirement (com.webauthn4j.data.UserVerificationRequirement)1 COSEKey (com.webauthn4j.data.attestation.authenticator.COSEKey)1 RealmRepresentation (org.keycloak.representations.idm.RealmRepresentation)1 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)1 RealmAttributeUpdater (org.keycloak.testsuite.updaters.RealmAttributeUpdater)1 WebAuthnPolicyPage (org.keycloak.testsuite.webauthn.pages.WebAuthnPolicyPage)1