Refine search
private void setValueForTextInput(Driver driver, WebElement element, String text) { if (text == null || text.isEmpty()) { element.clear(); } else if (driver.config().fastSetValue()) { String error = setValueByJs(driver, element, text); if (error != null) throw new InvalidStateException(driver, error); else { events.fireEvent(driver, element, "keydown", "keypress", "input", "keyup", "change"); } } else { element.clear(); element.sendKeys(text); } }
private void login(IdentityProvider<SamlIdentityProviderDefinition> provider) { webDriver.get(baseUrl + "/login"); Assert.assertEquals("Cloud Foundry", webDriver.getTitle()); webDriver.findElement(By.xpath("//a[text()='" + provider.getConfig().getLinkText() + "']")).click(); webDriver.findElement(By.xpath("//h2[contains(text(), 'Enter your username and password')]")); webDriver.findElement(By.name("username")).clear(); webDriver.findElement(By.name("username")).sendKeys(testAccounts.getUserName()); webDriver.findElement(By.name("password")).sendKeys(testAccounts.getPassword()); webDriver.findElement(By.xpath("//input[@value='Login']")).click(); } }
private void testSimpleSamlLogin(String firstUrl, String lookfor, String username, String password) throws Exception { IdentityProvider<SamlIdentityProviderDefinition> provider = createIdentityProvider(SAML_ORIGIN); webDriver.get(baseUrl + firstUrl); Assert.assertEquals("Cloud Foundry", webDriver.getTitle()); webDriver.findElement(By.xpath("//a[text()='" + provider.getConfig().getLinkText() + "']")).click(); //takeScreenShot(); webDriver.findElement(By.xpath("//h2[contains(text(), 'Enter your username and password')]")); webDriver.findElement(By.name("username")).clear(); webDriver.findElement(By.name("username")).sendKeys(username); webDriver.findElement(By.name("password")).sendKeys(password); webDriver.findElement(By.xpath("//input[@value='Login']")).click(); assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString(lookfor)); IntegrationTestUtils.validateAccountChooserCookie(baseUrl, webDriver); }
@Test public void testLoginClientIDPAuthorizationAlreadyLoggedIn() throws Exception { webDriver.get(baseUrl + "/logout.do"); String adminAccessToken = testClient.getOAuthAccessToken("admin", "adminsecret", "client_credentials", "clients.read clients.write clients.secret clients.admin"); String clientId = UUID.randomUUID().toString(); BaseClientDetails clientDetails = new BaseClientDetails(clientId, null, "openid", GRANT_TYPE_AUTHORIZATION_CODE, "uaa.none", "http://localhost:8080/login"); clientDetails.setClientSecret("secret"); List<String> idps = Arrays.asList("okta-local"); //not authorized for the current IDP clientDetails.addAdditionalInformation(ClientConstants.ALLOWED_PROVIDERS, idps); testClient.createClient(adminAccessToken, clientDetails); webDriver.findElement(By.name("username")).clear(); webDriver.findElement(By.name("username")).sendKeys(testAccounts.getUserName()); webDriver.findElement(By.name("password")).sendKeys("koala"); webDriver.findElement(By.xpath("//input[@value='Sign in']")).click(); webDriver.get(baseUrl + "/oauth/authorize?client_id=" + clientId + "&redirect_uri=http%3A%2F%2Flocalhost%3A8888%2Flogin&response_type=code&state=8tp0tR"); assertThat(webDriver.findElement(By.cssSelector("p")).getText(), Matchers.containsString(clientId + " does not support your identity provider. To log into an identity provider supported by the application")); webDriver.get(baseUrl + "/logout.do"); }
@Test public void testSingleLogout() throws Exception { IdentityProvider<SamlIdentityProviderDefinition> provider = createIdentityProvider(SAML_ORIGIN); webDriver.get(baseUrl + "/login"); Assert.assertEquals("Cloud Foundry", webDriver.getTitle()); webDriver.findElement(By.xpath("//a[text()='" + provider.getConfig().getLinkText() + "']")).click(); webDriver.findElement(By.xpath("//h2[contains(text(), 'Enter your username and password')]")); webDriver.findElement(By.name("username")).clear(); webDriver.findElement(By.name("username")).sendKeys(testAccounts.getUserName()); webDriver.findElement(By.name("password")).sendKeys(testAccounts.getPassword()); webDriver.findElement(By.xpath("//input[@value='Login']")).click(); assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Where to")); logout(); IntegrationTestUtils.validateAccountChooserCookie(baseUrl, webDriver); webDriver.findElement(By.xpath("//a[text()='" + provider.getConfig().getLinkText() + "']")).click(); webDriver.findElement(By.xpath("//h2[contains(text(), 'Enter your username and password')]")); }
@Test public void testSamlLoginClientIDPAuthorizationAutomaticRedirect() throws Exception { IdentityProvider<SamlIdentityProviderDefinition> provider = createIdentityProvider(SAML_ORIGIN); assertEquals(provider.getOriginKey(), provider.getConfig().getIdpEntityAlias()); List<String> idps = Arrays.asList(provider.getOriginKey()); webDriver.get(baseUrl + "/logout.do"); String adminAccessToken = testClient.getOAuthAccessToken("admin", "adminsecret", "client_credentials", "clients.read clients.write clients.secret clients.admin"); String clientId = UUID.randomUUID().toString(); BaseClientDetails clientDetails = new BaseClientDetails(clientId, null, "openid", GRANT_TYPE_AUTHORIZATION_CODE, "uaa.none", baseUrl); clientDetails.setClientSecret("secret"); clientDetails.addAdditionalInformation(ClientConstants.ALLOWED_PROVIDERS, idps); clientDetails.setAutoApproveScopes(Collections.singleton("true")); testClient.createClient(adminAccessToken, clientDetails); webDriver.get(baseUrl + "/oauth/authorize?client_id=" + clientId + "&redirect_uri=" + URLEncoder.encode(baseUrl) + "&response_type=code&state=8tp0tR"); //we should now be in the Simple SAML PHP site webDriver.findElement(By.xpath("//h2[contains(text(), 'Enter your username and password')]")); webDriver.findElement(By.name("username")).clear(); webDriver.findElement(By.name("username")).sendKeys(testAccounts.getUserName()); webDriver.findElement(By.name("password")).sendKeys("koala"); webDriver.findElement(By.xpath("//input[@value='Login']")).click(); assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Where to?")); webDriver.get(baseUrl + "/logout.do"); }
private void testLocalSamlIdpLogin(String firstUrl, String lookfor, String username, String password) throws Exception { SamlIdentityProviderDefinition idpDef = createLocalSamlIdpDefinition(IDP_ENTITY_ID, "uaa"); @SuppressWarnings("unchecked") IdentityProvider<SamlIdentityProviderDefinition> provider = IntegrationTestUtils.createIdentityProvider( "Local SAML IdP", true, this.baseUrl, this.serverRunning, idpDef); SamlServiceProviderDefinition spDef = createLocalSamlSpDefinition("cloudfoundry-saml-login", "uaa"); createSamlServiceProvider("Local SAML SP", "cloudfoundry-saml-login", baseUrl, serverRunning, spDef); webDriver.get(baseUrl + firstUrl); IntegrationTestUtils.takeScreenShot(webDriver); assertEquals("Cloud Foundry", webDriver.getTitle()); webDriver.findElement(By.xpath("//a[text()='" + provider.getConfig().getLinkText() + "']")).click(); webDriver.findElement(By.xpath("//h1[contains(text(), 'Welcome!')]")); webDriver.findElement(By.name("username")).clear(); webDriver.findElement(By.name("username")).sendKeys(username); webDriver.findElement(By.name("password")).sendKeys(password); webDriver.findElement(By.xpath("//input[@value='Sign in']")).click(); assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), containsString(lookfor)); provider.setActive(false); IntegrationTestUtils.updateIdentityProvider(this.baseUrl, this.serverRunning, provider); }
@Test public void idp_initiated_login_invalid_sp() throws Exception { //zone1 is IDP (create SP config and user here) //zone2 is SP (create IDP config here) //start at zone_1_url //should land on zone_2_url String zoneId1 = "testzone1"; RestTemplate identityClient = getIdentityClient(); String adminToken = IntegrationTestUtils.getClientCredentialsToken(baseUrl, "admin", "adminsecret"); IdentityZoneConfiguration configuration = new IdentityZoneConfiguration(); IntegrationTestUtils.createZoneOrUpdateSubdomain(identityClient, baseUrl, zoneId1, zoneId1, configuration); String testZone1Url = baseUrl.replace("localhost", zoneId1 + ".localhost"); String email = new RandomValueStringGenerator().generate().toLowerCase() + "@samltesting.org"; ScimUser idpUser = new ScimUser(null, email, "IDPFirst", "IDPLast"); idpUser.setPrimaryEmail(email); idpUser.setPassword("secr3T"); IntegrationTestUtils.createUser(adminToken, baseUrl, idpUser, zoneId1); webDriver.get(testZone1Url + "/logout.do"); webDriver.get(testZone1Url + "/login"); webDriver.findElement(By.name("username")).clear(); webDriver.findElement(By.name("username")).sendKeys(email); webDriver.findElement(By.name("password")).sendKeys("secr3T"); webDriver.findElement(By.xpath("//input[@value='Sign in']")).click(); assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), containsString("Where to?")); webDriver.get(testZone1Url + "/saml/idp/initiate"); assertNotNull(webDriver.findElement(By.xpath("//h2[contains(text(), 'Missing sp request parameter')]"))); webDriver.get(testZone1Url + "/saml/idp/initiate?sp=invalid_entity_id"); assertNotNull(webDriver.findElement(By.xpath("//h2[contains(text(), 'Invalid sp entity ID')]"))); }
@Test public void acceptInvitation_for_samlUser() throws Exception { webDriver.get(baseUrl + "/logout.do"); BaseClientDetails appClient = IntegrationTestUtils.getClient(scimToken, baseUrl, "app"); appClient.setScope(Lists.newArrayList("cloud_controller.read", "password.write", "scim.userids", "cloud_controller.write", "openid", "organizations.acme")); appClient.setAutoApproveScopes(Lists.newArrayList("openid")); IntegrationTestUtils.updateClient(baseUrl, scimToken, appClient); String code = createInvitation(testInviteEmail, testInviteEmail, "http://localhost:8080/app/", "simplesamlphp"); String invitedUserId = IntegrationTestUtils.getUserIdByField(scimToken, baseUrl, "simplesamlphp", "email", testInviteEmail); IntegrationTestUtils.createIdentityProvider("simplesamlphp", true, baseUrl, serverRunning); webDriver.get(baseUrl + "/invitations/accept?code=" + code); webDriver.findElement(By.xpath("//h2[contains(text(), 'Enter your username and password')]")); webDriver.findElement(By.name("username")).clear(); webDriver.findElement(By.name("username")).sendKeys("user_only_for_invitations_test"); webDriver.findElement(By.name("password")).sendKeys("saml"); WebElement loginButton = webDriver.findElement(By.xpath("//input[@value='Login']")); loginButton.click(); //wait until UAA page has loaded webDriver.findElement(By.id("application_authorization")); String acceptedUsername = IntegrationTestUtils.getUsernameById(scimToken, baseUrl, invitedUserId); //webdriver follows redirects so we should be on the UAA authorization page assertEquals("user_only_for_invitations_test", acceptedUsername); //external users should default to not being "verified" since we can't determine this ScimUser user = IntegrationTestUtils.getUser(scimToken, baseUrl, invitedUserId); assertFalse(user.isVerified()); }
@Test public void testSimpleSamlLoginWithAddShadowUserOnLoginFalse() throws Exception { // Deleting marissa@test.org from simplesamlphp because previous SAML authentications automatically // create a UAA user with the email address as the username. deleteUser(SAML_ORIGIN, testAccounts.getEmail()); 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, "UTF-8"); webDriver.get(baseUrl + firstUrl); webDriver.findElement(By.xpath("//h2[contains(text(), 'Enter your username and password')]")); webDriver.findElement(By.name("username")).clear(); webDriver.findElement(By.name("username")).sendKeys(testAccounts.getUserName()); webDriver.findElement(By.name("password")).sendKeys(testAccounts.getPassword()); webDriver.findElement(By.xpath("//input[@value='Login']")).click(); // We need to verify the last request URL through the performance log because the redirect // URI does not exist. When the webDriver follows the non-existent redirect URI it receives a // connection refused error so webDriver.getCurrentURL() will remain as the SAML IdP URL. List<LogEntry> logEntries = webDriver.manage().logs().get(LogType.PERFORMANCE).getAll(); List<String> logMessages = logEntries.stream().map(logEntry -> logEntry.getMessage()).collect(Collectors.toList()); assertThat(logMessages, hasItem(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 public void testSingleLogoutWithNoLogoutUrlOnIDP() throws Exception { SamlIdentityProviderDefinition providerDefinition = createIDPWithNoSLOSConfigured(SAML_ORIGIN); IdentityProvider<SamlIdentityProviderDefinition> provider = new IdentityProvider(); provider.setIdentityZoneId(OriginKeys.UAA); provider.setType(OriginKeys.SAML); provider.setActive(true); provider.setConfig(providerDefinition); provider.setOriginKey(providerDefinition.getIdpEntityAlias()); provider.setName("simplesamlphp for uaa"); String zoneAdminToken = getZoneAdminToken(baseUrl, serverRunning); provider = IntegrationTestUtils.createOrUpdateProvider(zoneAdminToken, baseUrl, provider); webDriver.get(baseUrl + "/login"); Assert.assertEquals("Cloud Foundry", webDriver.getTitle()); webDriver.findElement(By.xpath("//a[text()='" + provider.getConfig().getLinkText() + "']")).click(); webDriver.findElement(By.xpath("//h2[contains(text(), 'Enter your username and password')]")); webDriver.findElement(By.name("username")).clear(); webDriver.findElement(By.name("username")).sendKeys(testAccounts.getUserName()); webDriver.findElement(By.name("password")).sendKeys(testAccounts.getPassword()); webDriver.findElement(By.xpath("//input[@value='Login']")).click(); assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Where to")); webDriver.findElement(By.cssSelector(".dropdown-trigger")).click(); webDriver.findElement(By.linkText("Sign Out")).click(); webDriver.findElement(By.xpath("//a[text()='" + provider.getConfig().getLinkText() + "']")).click(); assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Where to")); }
webDriver.get(testZone1Url + "/saml/idp/initiate?sp=testzone2.cloudfoundry-saml-login"); webDriver.findElement(By.xpath("//h1[contains(text(), 'Welcome to The Twiglet Zone[" + zoneId1 + "]!')]")); webDriver.findElement(By.name("username")).clear(); webDriver.findElement(By.name("username")).sendKeys(email); webDriver.findElement(By.name("password")).sendKeys("secr3T"); webDriver.findElement(By.xpath("//input[@value='Sign in']")).click(); assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), containsString("Where to?"));
try { webDriver.findElement(By.xpath("//h1[contains(text(), 'Welcome to The Twiglet Zone[" + idpZoneId + "]!')]")); webDriver.findElement(By.name("username")).clear(); webDriver.findElement(By.name("username")).sendKeys(idpZoneUserEmail); webDriver.findElement(By.name("password")).sendKeys("secr3T"); webDriver.findElement(By.xpath("//input[@value='Sign in']")).click(); assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), containsString("Where to?"));