Search in sources :

Example 6 with WebAuthnAuthenticatorsList

use of org.keycloak.testsuite.webauthn.pages.WebAuthnAuthenticatorsList in project keycloak by keycloak.

the class WebAuthnTransportLocaleTest method assertLocalizationIndividual.

private void assertLocalizationIndividual(VirtualAuthenticatorOptions options, String originalName, String localizedText) {
    final Consumer<String> checkTransportName = (requiredName) -> {
        WebAuthnAuthenticatorsList authenticators = webAuthnLoginPage.getAuthenticators();
        assertThat(authenticators, notNullValue());
        assertThat(authenticators.getCount(), is(1));
        assertThat(authenticators.getLabels(), Matchers.contains("authenticator#1"));
        List<WebAuthnAuthenticatorsList.WebAuthnAuthenticatorItem> items = authenticators.getItems();
        assertThat(items, notNullValue());
        assertThat(items.size(), is(1));
        WebAuthnAuthenticatorsList.WebAuthnAuthenticatorItem item = items.get(0);
        assertThat(item, notNullValue());
        assertThat(item.getTransport(), is(requiredName));
    };
    try (Closeable c = setLocalesUpdater(Locale.ENGLISH.getLanguage(), "cs").update()) {
        getWebAuthnManager().useAuthenticator(options);
        addWebAuthnCredential("authenticator#1");
        final int webAuthnCount = webAuthnCredentialType.getUserCredentialsCount();
        assertThat(webAuthnCount, is(1));
        setUpWebAuthnFlow("webAuthnFlow");
        logout();
        signingInPage.navigateTo();
        loginToAccount();
        webAuthnLoginPage.assertCurrent();
        checkTransportName.accept(originalName);
        webAuthnLoginPage.openLanguage("Čeština");
        checkTransportName.accept(localizedText);
        webAuthnLoginPage.clickAuthenticate();
        signingInPage.assertCurrent();
    } catch (IOException e) {
        throw new RuntimeException("Cannot update locale.", e);
    }
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) WebAuthnAuthenticatorsList(org.keycloak.testsuite.webauthn.pages.WebAuthnAuthenticatorsList) DEFAULT_BLE(org.keycloak.testsuite.webauthn.authenticators.DefaultVirtualAuthOptions.DEFAULT_BLE) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) IgnoreBrowserDriver(org.keycloak.testsuite.arquillian.annotation.IgnoreBrowserDriver) IOException(java.io.IOException) Supplier(java.util.function.Supplier) DEFAULT(org.keycloak.testsuite.webauthn.authenticators.DefaultVirtualAuthOptions.DEFAULT) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Consumer(java.util.function.Consumer) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) List(java.util.List) DEFAULT_NFC(org.keycloak.testsuite.webauthn.authenticators.DefaultVirtualAuthOptions.DEFAULT_NFC) DefaultVirtualAuthOptions(org.keycloak.testsuite.webauthn.authenticators.DefaultVirtualAuthOptions) Locale(java.util.Locale) DEFAULT_INTERNAL(org.keycloak.testsuite.webauthn.authenticators.DefaultVirtualAuthOptions.DEFAULT_INTERNAL) VirtualAuthenticatorOptions(org.openqa.selenium.virtualauthenticator.VirtualAuthenticatorOptions) Closeable(java.io.Closeable) BiConsumer(java.util.function.BiConsumer) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DEFAULT_USB(org.keycloak.testsuite.webauthn.authenticators.DefaultVirtualAuthOptions.DEFAULT_USB) WebAuthnAuthenticatorsList(org.keycloak.testsuite.webauthn.pages.WebAuthnAuthenticatorsList) Closeable(java.io.Closeable) WebAuthnAuthenticatorsList(org.keycloak.testsuite.webauthn.pages.WebAuthnAuthenticatorsList) List(java.util.List) IOException(java.io.IOException)

Example 7 with WebAuthnAuthenticatorsList

use of org.keycloak.testsuite.webauthn.pages.WebAuthnAuthenticatorsList in project keycloak by keycloak.

the class WebAuthnSigningInTest method checkAuthenticatorTimeLocale.

@Test
public void checkAuthenticatorTimeLocale() throws ParseException, IOException {
    addWebAuthnCredential("authenticator#1");
    final int webAuthnCount = webAuthnCredentialType.getUserCredentialsCount();
    assertThat(webAuthnCount, is(1));
    setUpWebAuthnFlow("webAuthnFlow");
    logout();
    signingInPage.navigateTo();
    loginToAccount();
    webAuthnLoginPage.assertCurrent();
    WebAuthnAuthenticatorsList authenticators = webAuthnLoginPage.getAuthenticators();
    assertThat(authenticators.getCount(), is(1));
    assertThat(authenticators.getLabels(), Matchers.contains("authenticator#1"));
    WebAuthnAuthenticatorsList.WebAuthnAuthenticatorItem item = authenticators.getItems().get(0);
    assertThat(item, notNullValue());
    assertThat(item.getName(), is("authenticator#1"));
    final String dateEnglishString = item.getCreatedDate();
    assertThat(dateEnglishString, notNullValue());
    DateFormat format = DateTimeFormatterUtil.getDefaultDateFormat(Locale.ENGLISH);
    final Date dateEnglish = format.parse(dateEnglishString);
    assertThat(dateEnglish, notNullValue());
    webAuthnLoginPage.clickAuthenticate();
    signingInPage.assertCurrent();
    logout();
    try (Closeable c = setLocalesUpdater(Locale.CHINA.getLanguage()).update()) {
        signingInPage.navigateTo();
        loginToAccount();
        webAuthnLoginPage.assertCurrent();
        authenticators = webAuthnLoginPage.getAuthenticators();
        assertThat(authenticators.getCount(), is(1));
        item = webAuthnLoginPage.getAuthenticators().getItems().get(0);
        final String dateChineseString = item.getCreatedDate();
        assertThat(dateChineseString, notNullValue());
        format = DateTimeFormatterUtil.getDefaultDateFormat(Locale.CHINA);
        final Date dateChinese = format.parse(dateChineseString);
        assertThat(dateChinese, notNullValue());
        assertThat(dateEnglishString, is(not(dateChineseString)));
        assertThat(dateEnglish, is(dateChinese));
        webAuthnLoginPage.clickAuthenticate();
        signingInPage.assertCurrent();
        logout();
    }
    try (Closeable c = setLocalesUpdater("xx", Locale.ENGLISH.getLanguage()).update()) {
        signingInPage.navigateTo();
        loginToAccount();
        webAuthnLoginPage.assertCurrent();
        authenticators = webAuthnLoginPage.getAuthenticators();
        assertThat(authenticators.getCount(), is(1));
        item = webAuthnLoginPage.getAuthenticators().getItems().get(0);
        final String dateInvalidString = item.getCreatedDate();
        assertThat(dateInvalidString, notNullValue());
        assertThat(dateInvalidString, is(dateEnglishString));
    }
}
Also used : WebAuthnAuthenticatorsList(org.keycloak.testsuite.webauthn.pages.WebAuthnAuthenticatorsList) DateFormat(java.text.DateFormat) Closeable(java.io.Closeable) Date(java.util.Date) Test(org.junit.Test)

Example 8 with WebAuthnAuthenticatorsList

use of org.keycloak.testsuite.webauthn.pages.WebAuthnAuthenticatorsList in project keycloak by keycloak.

the class WebAuthnSigningInTest method userAuthenticatorTimeLocale.

@Test
public void userAuthenticatorTimeLocale() throws IOException {
    Consumer<String> checkCreatedAtLabels = (requiredLabel) -> webAuthnLoginPage.getAuthenticators().getItems().stream().map(WebAuthnAuthenticatorsList.WebAuthnAuthenticatorItem::getCreatedLabel).forEach(f -> assertThat(f, is(requiredLabel)));
    try (Closeable c = setLocalesUpdater(Locale.ENGLISH.getLanguage(), "cs").update()) {
        addWebAuthnCredential("authenticator#1");
        addWebAuthnCredential("authenticator#2");
        final int webAuthnCount = webAuthnCredentialType.getUserCredentialsCount();
        assertThat(webAuthnCount, is(2));
        setUpWebAuthnFlow("webAuthnFlow");
        logout();
        signingInPage.navigateTo();
        loginToAccount();
        webAuthnLoginPage.assertCurrent();
        WebAuthnAuthenticatorsList authenticators = webAuthnLoginPage.getAuthenticators();
        assertThat(authenticators.getCount(), is(2));
        assertThat(authenticators.getLabels(), Matchers.contains("authenticator#1", "authenticator#2"));
        checkCreatedAtLabels.accept("Created");
        webAuthnLoginPage.openLanguage("Čeština");
        checkCreatedAtLabels.accept("Vytvořeno");
        webAuthnLoginPage.clickAuthenticate();
        signingInPage.assertCurrent();
    }
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Date(java.util.Date) CoreMatchers.not(org.hamcrest.CoreMatchers.not) Page(org.jboss.arquillian.graphene.page.Page) ArrayList(java.util.ArrayList) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) DateTimeFormatterUtil(org.keycloak.theme.DateTimeFormatterUtil) Locale(java.util.Locale) SigningInPageUtils.testSetUpLink(org.keycloak.testsuite.ui.account2.page.utils.SigningInPageUtils.testSetUpLink) CredentialRepresentation(org.keycloak.representations.idm.CredentialRepresentation) Matchers.hasSize(org.hamcrest.Matchers.hasSize) UIUtils.refreshPageAndWaitForLoad(org.keycloak.testsuite.util.UIUtils.refreshPageAndWaitForLoad) WebAuthnPasswordlessRegisterFactory(org.keycloak.authentication.requiredactions.WebAuthnPasswordlessRegisterFactory) WebAuthnLoginPage(org.keycloak.testsuite.webauthn.pages.WebAuthnLoginPage) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) UserResource(org.keycloak.admin.client.resource.UserResource) WebAuthnCredentialModel(org.keycloak.models.credential.WebAuthnCredentialModel) ParseException(java.text.ParseException) DateFormat(java.text.DateFormat) SigningInPageUtils.assertUserCredential(org.keycloak.testsuite.ui.account2.page.utils.SigningInPageUtils.assertUserCredential) WebAuthnAuthenticatorsList(org.keycloak.testsuite.webauthn.pages.WebAuthnAuthenticatorsList) Matchers.empty(org.hamcrest.Matchers.empty) Collections.emptyList(java.util.Collections.emptyList) Matchers(org.hamcrest.Matchers) RequiredActionProviderRepresentation(org.keycloak.representations.idm.RequiredActionProviderRepresentation) Test(org.junit.Test) IOException(java.io.IOException) SigningInPage(org.keycloak.testsuite.ui.account2.page.SigningInPage) Collectors(java.util.stream.Collectors) WaitUtils.waitForPageToLoad(org.keycloak.testsuite.util.WaitUtils.waitForPageToLoad) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) Closeable(java.io.Closeable) WebAuthnRegisterFactory(org.keycloak.authentication.requiredactions.WebAuthnRegisterFactory) WebAuthnAuthenticatorsList(org.keycloak.testsuite.webauthn.pages.WebAuthnAuthenticatorsList) Closeable(java.io.Closeable) Test(org.junit.Test)

Example 9 with WebAuthnAuthenticatorsList

use of org.keycloak.testsuite.webauthn.pages.WebAuthnAuthenticatorsList in project keycloak by keycloak.

the class PolicyJsInjectionTest method injectUserLabel.

@Test
public void injectUserLabel() {
    final String originalLabel = "label'`;window.prompt(\"another\");'";
    registerDefaultUser(originalLabel);
    appPage.assertCurrent();
    final CredentialRepresentation credential = userResource().credentials().stream().filter(f -> f.getType().equals(getCredentialType())).findFirst().orElse(null);
    assertThat(credential, notNullValue());
    assertThat(credential.getUserLabel(), is(originalLabel));
    if (!isPasswordless()) {
        logout();
        loginPage.open();
        loginPage.assertCurrent(TEST_REALM_NAME);
        loginPage.login(USERNAME, PASSWORD);
        webAuthnLoginPage.assertCurrent();
        WebAuthnAuthenticatorsList authenticators = webAuthnLoginPage.getAuthenticators();
        assertThat(authenticators, notNullValue());
        assertThat(authenticators.getItems(), not(Matchers.empty()));
        assertThat(authenticators.getLabels().get(0), is("label`;window.prompt(\"another\");"));
    }
}
Also used : CredentialRepresentation(org.keycloak.representations.idm.CredentialRepresentation) WebAuthnAuthenticatorsList(org.keycloak.testsuite.webauthn.pages.WebAuthnAuthenticatorsList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test) AbstractWebAuthnVirtualTest(org.keycloak.testsuite.webauthn.AbstractWebAuthnVirtualTest)

Example 10 with WebAuthnAuthenticatorsList

use of org.keycloak.testsuite.webauthn.pages.WebAuthnAuthenticatorsList in project keycloak by keycloak.

the class WebAuthnSigningInTest method displayAvailableAuthenticators.

@Test
public void displayAvailableAuthenticators() {
    addWebAuthnCredential("authenticator#1");
    addWebAuthnCredential("authenticator#2");
    final int webAuthnCount = webAuthnCredentialType.getUserCredentialsCount();
    assertThat(webAuthnCount, is(2));
    setUpWebAuthnFlow("webAuthnFlow");
    logout();
    signingInPage.navigateTo();
    loginToAccount();
    webAuthnLoginPage.assertCurrent();
    WebAuthnAuthenticatorsList authenticators = webAuthnLoginPage.getAuthenticators();
    assertThat(authenticators.getCount(), is(2));
    assertThat(authenticators.getLabels(), Matchers.contains("authenticator#1", "authenticator#2"));
    webAuthnLoginPage.clickAuthenticate();
    signingInPage.assertCurrent();
}
Also used : WebAuthnAuthenticatorsList(org.keycloak.testsuite.webauthn.pages.WebAuthnAuthenticatorsList) Test(org.junit.Test)

Aggregations

WebAuthnAuthenticatorsList (org.keycloak.testsuite.webauthn.pages.WebAuthnAuthenticatorsList)11 Test (org.junit.Test)10 Closeable (java.io.Closeable)5 IOException (java.io.IOException)4 List (java.util.List)4 Locale (java.util.Locale)4 Consumer (java.util.function.Consumer)4 CoreMatchers.is (org.hamcrest.CoreMatchers.is)4 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)4 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)4 Matchers (org.hamcrest.Matchers)4 DateFormat (java.text.DateFormat)3 Date (java.util.Date)3 UserResource (org.keycloak.admin.client.resource.UserResource)3 CredentialRepresentation (org.keycloak.representations.idm.CredentialRepresentation)3 IgnoreBrowserDriver (org.keycloak.testsuite.arquillian.annotation.IgnoreBrowserDriver)3 RealmAttributeUpdater (org.keycloak.testsuite.updaters.RealmAttributeUpdater)3 WebAuthnRealmAttributeUpdater (org.keycloak.testsuite.webauthn.updaters.WebAuthnRealmAttributeUpdater)3 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2