8000 Migrate ConditionalCredentialAuthenticatorTest by vaceksimon · Pull Request #52072 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,11 @@
return this;
}

public RealmBuilder otpCodeReusable(Boolean reusable) {
rep.setOtpPolicyCodeReusable(reusable);
return this;
}

public RealmBuilder passwordPolicy(String passwordPolicy) {
rep.setPasswordPolicy(passwordPolicy);
return this;
Expand Down Expand Up @@ -701,7 +706,7 @@
* @return this
* @deprecated
*/
public RealmBuilder update(RealmUpdate... update) {

Check warning on line 709 in test-framework/builders/src/main/java/org/keycloak/testframework/realm/RealmBuilder.java

View workflow job for this annotation

GitHub Actions / Test Framework

deprecated item is not annotated with @deprecated
Arrays.stream(update).forEach(u -> u.update(rep));
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.keycloak.testframework.ui.page;

import java.util.List;
import java.util.stream.Collectors;

import org.keycloak.testframework.ui.webdriver.ManagedWebDriver;

import org.junit.jupiter.api.Assertions;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

/**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
*/
public class LoginTotpPage extends AbstractLoginPage {

@FindBy(id = "otp")
private WebElement otpInput;

@FindBy(id = "password-token")
private WebElement passwordToken;

@FindBy(css = "[type=\"submit\"]")
private WebElement submitButton;

@FindBy(css = "div[class^='pf-v5-c-alert'], div[class^='alert-error']")
private WebElement loginErrorMessage;

@FindBy(id = "input-error-otp")
private WebElement totpInputCodeError;

@FindBy(id = "input-error-otp-code")
private WebElement otpInputCodeError;

public LoginTotpPage(ManagedWebDriver driver) {
super(driver);
}

public void login(String totp) {
otpInput.clear();
if (totp != null) otpInput.sendKeys(totp);

submitButton.click();
}

public String getAlertError() {
try {
return loginErrorMessage.getText();
} catch (NoSuchElementException e) {
return null;
}
}

public String getInputError() {
try {
return totpInputCodeError.getText();
} catch (NoSuchElementException e) {
try {
return otpInputCodeError.getText();
} catch (NoSuchElementException ex) {
return null;
}
}
}

@Override
public String getExpectedPageId() {
return "login-login-otp";
}

// If false, we don't expect that credentials combobox is available. If true, we expect that it is available on the page
public void assertOtpCredentialSelectorAvailability(boolean expectedAvailability) {
try {
driver.findElement(By.className("pf-v5-c-tile"));
Assertions.assertTrue(expectedAvailability);
} catch (NoSuchElementException nse) {
Assertions.assertFalse(expectedAvailability);
}
}

public List<String> getAvailableOtpCredentials() {
return driver.findElements(getXPathForLookupAllCards())
.stream().map(WebElement::getText).collect(Collectors.toList());
}

public String getSelectedOtpCredential() {
try {
WebElement selected = driver.findElement(getCssSelectorForLookupActiveCard());
return selected.getText();
} catch (NoSuchElementException nse) {
// No selected element found
return null;
}
}

private By getXPathForLookupAllCards() {
return By.xpath("//span[contains(@class, 'pf-v5-c-tile__title')]");
}

private By getCssSelectorForLookupActiveCard() {
return By.cssSelector(".pf-m-selected");
}

private By getXPathForLookupCardWithName(String credentialName) {
return By.xpath("//div[contains(@class, 'pf-v5-c-tile')][normalize-space() = '"+ credentialName +"']");
}

public void selectOtpCredential(String credentialName) {
WebElement webElement = driver.findElement(getXPathForLookupCardWithName(credentialName));
webElement.click();
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.keycloak.testframework.ui.webdriver;

import java.net.URL;
import java.util.List;

import org.keycloak.testframework.injection.ManagedTestResource;

Expand Down Expand Up @@ -50,6 +51,10 @@ public WebElement findElement(By by) {
return driver.findElement(by);
}

public List<WebElement> findElements(By by) {
return driver.findElements(by);
}

public void open(String url) {
driver.navigate().to(url);
}
Expand Down
Loading
Loading
0