Search in sources :

Example 1 with WebAuthnRealmData

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

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

the class WebAuthnPolicySettingsTest method policySettingsWithExternalProperties.

@Test
public void policySettingsWithExternalProperties() throws IOException {
    try (RealmAttributeUpdater rau = updateWebAuthnPolicy("rpName", Collections.singletonList("ES256"), INDIRECT.getValue(), CROSS_PLATFORM.getValue(), "No", null, PREFERRED.getValue(), Collections.singletonList(ALL_ZERO_AAGUID))) {
        WebAuthnRealmData realm = new WebAuthnRealmData(testRealmResource().toRepresentation(), isPasswordless());
        assertThat(realm, notNullValue());
        assertThat(realm.getSignatureAlgorithms(), hasItems("ES256"));
        assertThat(realm.getAttestationConveyancePreference(), is(INDIRECT.getValue()));
        assertThat(realm.getAuthenticatorAttachment(), is(CROSS_PLATFORM.getValue()));
        assertThat(realm.getRequireResidentKey(), is("No"));
        assertThat(realm.getRpId(), is(""));
        assertThat(realm.getUserVerificationRequirement(), is(PREFERRED.getValue()));
        assertThat(realm.getAcceptableAaguids(), hasItems(ALL_ZERO_AAGUID));
    }
}
Also used : WebAuthnRealmAttributeUpdater(org.keycloak.testsuite.webauthn.updaters.WebAuthnRealmAttributeUpdater) RealmAttributeUpdater(org.keycloak.testsuite.updaters.RealmAttributeUpdater) PasswordLessRealmAttributeUpdater(org.keycloak.testsuite.webauthn.updaters.PasswordLessRealmAttributeUpdater) WebAuthnRealmData(org.keycloak.testsuite.webauthn.utils.WebAuthnRealmData) AbstractConsoleTest(org.keycloak.testsuite.console.AbstractConsoleTest) Test(org.junit.Test)

Example 3 with WebAuthnRealmData

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

the class WebAuthnPolicySettingsTest method assertDataAfterModification.

/**
 * Assert WebAuthn Realm data before and after modification
 *
 * @param actualValue     actual value before modification
 * @param expectedValue   expected value after modification
 * @param getCurrentValue get updated value
 * @param setData         exact approach, how to change the realm data
 */
private <T> void assertDataAfterModification(T actualValue, T expectedValue, Function<WebAuthnRealmData, T> getCurrentValue, Consumer<WebAuthnRealmData.Builder> setData) {
    WebAuthnRealmData realm = new WebAuthnRealmData(testRealmResource().toRepresentation(), isPasswordless());
    assertThat(realm, notNullValue());
    assertThat(getCurrentValue.apply(realm), is(actualValue));
    WebAuthnRealmData.Builder builder = realm.builder();
    assertThat(builder, notNullValue());
    setData.accept(builder);
    final RealmRepresentation newRealm = builder.build();
    assertThat(newRealm, notNullValue());
    testRealmResource().update(newRealm);
    realm = new WebAuthnRealmData(testRealmResource().toRepresentation(), isPasswordless());
    assertThat(realm, notNullValue());
    assertThat(getCurrentValue.apply(realm), is(expectedValue));
}
Also used : RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) WebAuthnRealmData(org.keycloak.testsuite.webauthn.utils.WebAuthnRealmData)

Example 4 with WebAuthnRealmData

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

the class WebAuthnPolicySettingsTest method authenticatorAttachment.

@Test
public void authenticatorAttachment() {
    AuthenticatorAttachment attachment = getPolicyPage().getAuthenticatorAttachment();
    assertThat(attachment, nullValue());
    // Cross-platform
    getPolicyPage().setAuthenticatorAttachment(AuthenticatorAttachment.CROSS_PLATFORM);
    getPolicyPage().clickSaveButton();
    attachment = getPolicyPage().getAuthenticatorAttachment();
    assertThat(attachment, notNullValue());
    assertThat(attachment, is(AuthenticatorAttachment.CROSS_PLATFORM));
    // Platform
    getPolicyPage().setAuthenticatorAttachment(AuthenticatorAttachment.PLATFORM);
    getPolicyPage().clickSaveButton();
    attachment = getPolicyPage().getAuthenticatorAttachment();
    assertThat(attachment, notNullValue());
    assertThat(attachment, is(AuthenticatorAttachment.PLATFORM));
    assertDataAfterModification(AuthenticatorAttachment.PLATFORM.getValue(), DEFAULT_WEBAUTHN_POLICY_NOT_SPECIFIED, WebAuthnRealmData::getAuthenticatorAttachment, (builder) -> builder.authenticatorAttachment(null));
}
Also used : AuthenticatorAttachment(com.webauthn4j.data.AuthenticatorAttachment) WebAuthnRealmData(org.keycloak.testsuite.webauthn.utils.WebAuthnRealmData) AbstractConsoleTest(org.keycloak.testsuite.console.AbstractConsoleTest) Test(org.junit.Test)

Example 5 with WebAuthnRealmData

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

the class WebAuthnPolicySettingsTest method avoidSameAuthenticatorRegistration.

@Test
public void avoidSameAuthenticatorRegistration() {
    boolean avoidSameAuthenticatorRegistration = getPolicyPage().avoidSameAuthenticatorRegistration();
    assertThat(avoidSameAuthenticatorRegistration, is(false));
    getPolicyPage().avoidSameAuthenticatorRegister(true);
    assertThat(getPolicyPage().isSaveButtonEnabled(), is(true));
    getPolicyPage().clickSaveButton();
    avoidSameAuthenticatorRegistration = getPolicyPage().avoidSameAuthenticatorRegistration();
    assertThat(avoidSameAuthenticatorRegistration, is(true));
    getPolicyPage().avoidSameAuthenticatorRegister(false);
    getPolicyPage().clickSaveButton();
    avoidSameAuthenticatorRegistration = getPolicyPage().avoidSameAuthenticatorRegistration();
    assertThat(avoidSameAuthenticatorRegistration, is(false));
    final WebAuthnRealmData realm = new WebAuthnRealmData(testRealmResource().toRepresentation(), isPasswordless());
    assertThat(realm, notNullValue());
    assertThat(realm.isAvoidSameAuthenticatorRegister(), is(false));
}
Also used : 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