Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More page objects - @Before and testSimpleSamlLoginWithAddShadowUserOnLoginFalse() #2655

Merged
merged 3 commits into from
Jan 3, 2024
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 @@ -15,6 +15,10 @@ static public LoginPage logout_goesToLoginPage(WebDriver driver, String baseUrl,
return new LoginPage(driver);
}

static public void logout(WebDriver driver, String baseUrl) {
driver.get(baseUrl + urlPath);
}

private static String buildLogoutDoUrl(String baseUrl, String redirectUrl, String clientId) {
return baseUrl
+ urlPath
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.cloudfoundry.identity.uaa.integration.endpoints;

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

import org.cloudfoundry.identity.uaa.integration.pageObjects.SamlLoginPage;
import org.openqa.selenium.WebDriver;

public class OauthAuthorizeEndpoint {
static final private String urlPath = "/oauth/authorize";

static public SamlLoginPage authorize_goesToSamlLoginPage(WebDriver driver, String baseUrl, String redirectUri, String clientId, String response_type) {
driver.get(buildAuthorizeUrl(baseUrl, redirectUri, clientId, response_type));
return new SamlLoginPage(driver);
}

private static String buildAuthorizeUrl(String baseUrl, String redirectUri, String clientId, String response_type) {
return baseUrl
+ urlPath
+ "?client_id=" + clientId
+ "&response_type=" + response_type
+ "&redirect_uri=" + URLEncoder.encode(redirectUri, StandardCharsets.UTF_8);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,48 @@
*******************************************************************************/
package org.cloudfoundry.identity.uaa.integration.feature;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.jwt.Jwt;
import org.springframework.security.oauth2.client.test.TestAccounts;
import org.springframework.security.oauth2.common.util.RandomValueStringGenerator;
import org.springframework.security.oauth2.provider.client.BaseClientDetails;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestOperations;
import org.springframework.web.client.RestTemplate;

import com.fasterxml.jackson.core.type.TypeReference;
import org.cloudfoundry.identity.uaa.ServerRunning;
import org.cloudfoundry.identity.uaa.account.UserInfoResponse;
import org.cloudfoundry.identity.uaa.constants.OriginKeys;
import org.cloudfoundry.identity.uaa.integration.endpoints.LogoutDoEndpoint;
import org.cloudfoundry.identity.uaa.integration.endpoints.OauthAuthorizeEndpoint;
import org.cloudfoundry.identity.uaa.integration.endpoints.SamlLogoutAuthSourceEndpoint;
import org.cloudfoundry.identity.uaa.integration.pageObjects.FaviconElement;
import org.cloudfoundry.identity.uaa.integration.pageObjects.HomePage;
import org.cloudfoundry.identity.uaa.integration.pageObjects.LoginPage;
import org.cloudfoundry.identity.uaa.integration.endpoints.LogoutDoEndpoint;
import org.cloudfoundry.identity.uaa.integration.pageObjects.Page;
import org.cloudfoundry.identity.uaa.integration.pageObjects.PasscodePage;
import org.cloudfoundry.identity.uaa.integration.endpoints.SamlLogoutAuthSourceEndpoint;
import org.cloudfoundry.identity.uaa.integration.util.IntegrationTestUtils;
import org.cloudfoundry.identity.uaa.integration.util.ScreenshotOnFail;
import org.cloudfoundry.identity.uaa.mock.util.MockMvcUtils;
Expand Down Expand Up @@ -58,36 +90,6 @@
import org.openqa.selenium.WebElement;
import org.opensaml.saml2.core.AuthnContext;
import org.opensaml.xml.ConfigurationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.jwt.Jwt;
import org.springframework.security.oauth2.client.test.TestAccounts;
import org.springframework.security.oauth2.common.util.RandomValueStringGenerator;
import org.springframework.security.oauth2.provider.client.BaseClientDetails;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestOperations;
import org.springframework.web.client.RestTemplate;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import static org.cloudfoundry.identity.uaa.authentication.AbstractClientParametersAuthenticationFilter.CLIENT_SECRET;
import static org.cloudfoundry.identity.uaa.integration.util.IntegrationTestUtils.SAML_AUTH_SOURCE;
Expand Down Expand Up @@ -211,8 +213,8 @@ public static String getValidRandomIDPMetaData() {
public void clearWebDriverOfCookies() {
screenShootRule.setWebDriver(webDriver);
for (String domain : Arrays.asList("localhost", "testzone1.localhost", "testzone2.localhost", "testzone3.localhost", "testzone4.localhost")) {
webDriver.get(baseUrl.replace("localhost", domain) + "/logout.do");
webDriver.manage().deleteAllCookies();
LogoutDoEndpoint.logout(webDriver, baseUrl.replace("localhost", domain));
new Page(webDriver).clearCookies();
}
SamlLogoutAuthSourceEndpoint.logoutAuthSource_goesToSamlWelcomePage(webDriver, IntegrationTestUtils.SIMPLESAMLPHP_UAA_ACCEPTANCE, SAML_AUTH_SOURCE);
}
Expand Down Expand Up @@ -263,15 +265,14 @@ public void testSimpleSamlLoginWithAddShadowUserOnLoginFalse() throws Exception
IdentityProvider provider = IntegrationTestUtils.createIdentityProvider(SAML_ORIGIN, false, baseUrl, serverRunning);
String clientId = "app-addnew-false"+ new RandomValueStringGenerator().generate();
String redirectUri = "http://nosuchhostname:0/nosuchendpoint";
BaseClientDetails client = createClientAndSpecifyProvider(clientId, provider, redirectUri);
String firstUrl = "/oauth/authorize?"
+ "client_id=" + clientId
+ "&response_type=code"
+ "&redirect_uri=" + URLEncoder.encode(redirectUri, StandardCharsets.UTF_8);
webDriver.get(baseUrl + firstUrl);
webDriver.findElement(By.xpath(SIMPLESAMLPHP_LOGIN_PROMPT_XPATH_EXPR));
sendCredentials(testAccounts.getUserName(), testAccounts.getPassword());
assertThat(webDriver.getCurrentUrl(), containsString(redirectUri + "?error=access_denied&error_description=SAML+user+does+not+exist.+You+can+correct+this+by+creating+a+shadow+user+for+the+SAML+user."));
createClientAndSpecifyProvider(clientId, provider, redirectUri);

OauthAuthorizeEndpoint
.authorize_goesToSamlLoginPage(webDriver, baseUrl, redirectUri, clientId, "code")
.login_goesToCustomErrorPage(
testAccounts.getUserName(),
testAccounts.getPassword(),
containsString(redirectUri + "?error=access_denied&error_description=SAML+user+does+not+exist.+You+can+correct+this+by+creating+a+shadow+user+for+the+SAML+user."));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.cloudfoundry.identity.uaa.integration.pageObjects;

import org.hamcrest.Matcher;
import org.openqa.selenium.WebDriver;

public class CustomErrorPage extends Page {

public CustomErrorPage(WebDriver driver, Matcher urlMatcher) {
super(driver);
validateUrl(driver, urlMatcher);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@ private void clickLogout() {
driver.findElement(By.cssSelector(".dropdown-trigger")).click();
driver.findElement(By.linkText("Sign Out")).click();
}

public void clearCookies() {
driver.manage().deleteAllCookies();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.cloudfoundry.identity.uaa.integration.pageObjects;

import org.hamcrest.Matcher;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
Expand All @@ -24,7 +25,10 @@ public PasscodePage login_goesToPasscodePage(String username, String password) {
sendLoginCredentials(username, password);
return new PasscodePage(driver);
}

public CustomErrorPage login_goesToCustomErrorPage(String username, String password, Matcher urlMatcher) {
sendLoginCredentials(username, password);
return new CustomErrorPage(driver, urlMatcher);
}
public SamlErrorPage login_goesToSamlErrorPage(String username, String password) {
sendLoginCredentials(username, password);
return new SamlErrorPage(driver);
Expand Down