From 4b6e46d1a9f3825b0fbe25a11fd635ad5d058c48 Mon Sep 17 00:00:00 2001 From: aboullos Date: Wed, 25 Mar 2020 10:27:53 +0100 Subject: [PATCH] KEYCLOAK-13445 Modify SigningInTest for changes in credential type --- .../testsuite/ui/account2/SigningInTest.java | 39 +++++++++++++++++-- .../ui/account2/page/SigningInPage.java | 19 +++++++++ 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/testsuite/integration-arquillian/tests/other/base-ui/src/test/java/org/keycloak/testsuite/ui/account2/SigningInTest.java b/testsuite/integration-arquillian/tests/other/base-ui/src/test/java/org/keycloak/testsuite/ui/account2/SigningInTest.java index 8c6e0aedf6..1869d1a24a 100644 --- a/testsuite/integration-arquillian/tests/other/base-ui/src/test/java/org/keycloak/testsuite/ui/account2/SigningInTest.java +++ b/testsuite/integration-arquillian/tests/other/base-ui/src/test/java/org/keycloak/testsuite/ui/account2/SigningInTest.java @@ -219,6 +219,8 @@ public class SigningInTest extends BaseAccountPageTest { @Test public void otpTest() { + testContext.setTestRealmReps(emptyList()); + assertFalse(otpCredentialType.isSetUp()); otpCredentialType.clickSetUpLink(); otpSetupPage.cancel(); @@ -240,6 +242,18 @@ public class SigningInTest extends BaseAccountPageTest { assertEquals(2, otpCredentialType.getUserCredentialsCount()); assertUserCredential(label2, true, otp2); + assertTrue("Set up link is not visible", otpCredentialType.isSetUpLinkVisible()); + RequiredActionProviderRepresentation requiredAction = new RequiredActionProviderRepresentation(); + requiredAction.setEnabled(false); + testRealmResource().flows().updateRequiredAction(CONFIGURE_TOTP.name(), requiredAction); + + refreshPageAndWaitForLoad(); + + assertFalse("Set up link for \"otp\" is visible", otpCredentialType.isSetUpLinkVisible()); + assertFalse("Not set up link for \"otp\" is visible", otpCredentialType.isNotSetUpLabelVisible()); + assertTrue("Title for \"otp\" is not visible", otpCredentialType.isTitleVisible()); + assertEquals(2, otpCredentialType.getUserCredentialsCount()); + testRemoveCredential(otp1); } @@ -254,23 +268,29 @@ public class SigningInTest extends BaseAccountPageTest { } private void testWebAuthn(boolean passwordless) { + testContext.setTestRealmReps(emptyList()); + WebAuthnAssume.assumeChrome(driver); // we need some special flags to be able to register security key SigningInPage.CredentialType credentialType; final String expectedHelpText; + final String providerId; if (passwordless) { credentialType = webAuthnPwdlessCredentialType; expectedHelpText = "Use your security key for passwordless log in."; + providerId = WebAuthnPasswordlessRegisterFactory.PROVIDER_ID; } else { credentialType = webAuthnCredentialType; expectedHelpText = "Use your security key to log in."; + providerId = WebAuthnRegisterFactory.PROVIDER_ID; } assertFalse(credentialType.isSetUp()); // no way to simulate registration cancellation + assertTrue("Set up link for \"" + credentialType.getType() + "\" is not visible", credentialType.isSetUpLinkVisible()); assertEquals("Security Key", credentialType.getTitle()); assertEquals(expectedHelpText, credentialType.getHelpText()); @@ -286,6 +306,17 @@ public class SigningInTest extends BaseAccountPageTest { assertEquals(2, credentialType.getUserCredentialsCount()); assertUserCredential(label2, true, webAuthn2); + RequiredActionProviderRepresentation requiredAction = new RequiredActionProviderRepresentation(); + requiredAction.setEnabled(false); + testRealmResource().flows().updateRequiredAction(providerId, requiredAction); + + refreshPageAndWaitForLoad(); + + assertFalse("Set up link for \"" + credentialType.getType() + "\" is visible", credentialType.isSetUpLinkVisible()); + assertFalse("Not set up link for \"" + credentialType.getType() + "\" is visible", credentialType.isNotSetUpLabelVisible()); + assertTrue("Title for \"" + credentialType.getType() + "\" is not visible", credentialType.isTitleVisible()); + assertEquals(2, credentialType.getUserCredentialsCount()); + testRemoveCredential(webAuthn1); } @@ -297,17 +328,17 @@ public class SigningInTest extends BaseAccountPageTest { } private void testSetUpLink(SigningInPage.CredentialType credentialType, String requiredActionProviderId) { - assertTrue("Set up link is visible", credentialType.isSetUpLinkVisible()); + assertTrue("Set up link for \"" + credentialType.getType() + "\" is not visible", credentialType.isSetUpLinkVisible()); RequiredActionProviderRepresentation requiredAction = new RequiredActionProviderRepresentation(); requiredAction.setEnabled(false); testRealmResource().flows().updateRequiredAction(requiredActionProviderId, requiredAction); refreshPageAndWaitForLoad(); - assertFalse("Set up link is not visible", credentialType.isSetUpLinkVisible()); - assertFalse("Credential type is not set up", credentialType.isSetUp()); // this also check the cred type is present - assertNotNull("Title is present", credentialType.getTitle()); + assertFalse("Set up link for \"" + credentialType.getType() + "\" is visible", credentialType.isSetUpLinkVisible()); + assertFalse("Title for \"" + credentialType.getType() + "\" is visible", credentialType.isTitleVisible()); + assertFalse("Set up link for \"" + credentialType.getType() + "\" is visible", credentialType.isNotSetUpLabelVisible()); } private SigningInPage.UserCredential addOtpCredential(String label) { diff --git a/testsuite/integration-arquillian/tests/other/base-ui/src/test/java/org/keycloak/testsuite/ui/account2/page/SigningInPage.java b/testsuite/integration-arquillian/tests/other/base-ui/src/test/java/org/keycloak/testsuite/ui/account2/page/SigningInPage.java index 95175ac242..201eb820fb 100644 --- a/testsuite/integration-arquillian/tests/other/base-ui/src/test/java/org/keycloak/testsuite/ui/account2/page/SigningInPage.java +++ b/testsuite/integration-arquillian/tests/other/base-ui/src/test/java/org/keycloak/testsuite/ui/account2/page/SigningInPage.java @@ -91,6 +91,7 @@ public class SigningInPage extends AbstractLoggedInPage { public boolean isSetUp() { boolean notSetUpLabelPresent; + try { notSetUpLabelPresent = getItemElement(NOT_SET_UP).isDisplayed(); } @@ -124,6 +125,24 @@ public class SigningInPage extends AbstractLoggedInPage { } } + public boolean isNotSetUpLabelVisible() { + try { + return getItemElement(NOT_SET_UP).isDisplayed(); + } + catch (NoSuchElementException e) { + return false; + } + } + + public boolean isTitleVisible() { + try { + return getItemElement(TITLE).isDisplayed(); + } + catch (NoSuchElementException e) { + return false; + } + } + public String getTitle() { return getTextFromElement(getItemElement(TITLE)); }