KEYCLOAK-4624 Fix, stabilize and revamp SocialLoginTest
This commit is contained in:
parent
4344ceefc2
commit
32b62b2a70
11 changed files with 536 additions and 147 deletions
|
@ -59,6 +59,18 @@ public class AccountFields extends Form {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return Form.getInputValue(emailInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFirstName() {
|
||||||
|
return Form.getInputValue(firstNameInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastName() {
|
||||||
|
return Form.getInputValue(lastNameInput);
|
||||||
|
}
|
||||||
|
|
||||||
public void setValues(UserRepresentation user) {
|
public void setValues(UserRepresentation user) {
|
||||||
setUsername(user.getUsername());
|
setUsername(user.getUsername());
|
||||||
setEmail(user.getEmail());
|
setEmail(user.getEmail());
|
||||||
|
|
|
@ -41,4 +41,7 @@ public class UpdateAccount extends Authenticate {
|
||||||
submit();
|
submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AccountFields fields() {
|
||||||
|
return accountFields;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2017 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.testsuite.pages.social;
|
||||||
|
|
||||||
|
import org.jboss.arquillian.drone.api.annotation.Drone;
|
||||||
|
import org.openqa.selenium.WebDriver;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Vaclav Muzikar <vmuzikar@redhat.com>
|
||||||
|
*/
|
||||||
|
public abstract class AbstractSocialLoginPage {
|
||||||
|
@Drone
|
||||||
|
protected WebDriver driver;
|
||||||
|
|
||||||
|
public abstract void login(String user, String password);
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2017 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.testsuite.pages.social;
|
||||||
|
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.openqa.selenium.support.FindBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Vaclav Muzikar <vmuzikar@redhat.com>
|
||||||
|
*/
|
||||||
|
public class FacebookLoginPage extends AbstractSocialLoginPage {
|
||||||
|
@FindBy(id = "email")
|
||||||
|
private WebElement emailInput;
|
||||||
|
|
||||||
|
@FindBy(id = "pass")
|
||||||
|
private WebElement passwordInput;
|
||||||
|
|
||||||
|
@FindBy(id = "loginbutton")
|
||||||
|
private WebElement loginButton;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void login(String user, String password) {
|
||||||
|
emailInput.sendKeys(user);
|
||||||
|
passwordInput.sendKeys(password);
|
||||||
|
loginButton.click();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2017 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.testsuite.pages.social;
|
||||||
|
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.openqa.selenium.support.FindBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Vaclav Muzikar <vmuzikar@redhat.com>
|
||||||
|
*/
|
||||||
|
public class GitHubLoginPage extends AbstractSocialLoginPage {
|
||||||
|
@FindBy(id = "login_field")
|
||||||
|
private WebElement usernameInput;
|
||||||
|
|
||||||
|
@FindBy(id = "password")
|
||||||
|
private WebElement passwordInput;
|
||||||
|
|
||||||
|
@FindBy(name = "commit")
|
||||||
|
private WebElement loginButton;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void login(String user, String password) {
|
||||||
|
usernameInput.sendKeys(user);
|
||||||
|
passwordInput.sendKeys(password);
|
||||||
|
loginButton.click();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2017 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.testsuite.pages.social;
|
||||||
|
|
||||||
|
import org.keycloak.testsuite.util.WaitUtils;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.openqa.selenium.support.FindBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Vaclav Muzikar <vmuzikar@redhat.com>
|
||||||
|
*/
|
||||||
|
public class GoogleLoginPage extends AbstractSocialLoginPage {
|
||||||
|
@FindBy(id = "Email")
|
||||||
|
private WebElement emailInput;
|
||||||
|
|
||||||
|
@FindBy(id = "Passwd")
|
||||||
|
private WebElement passwordInput;
|
||||||
|
|
||||||
|
@FindBy(id = "next")
|
||||||
|
private WebElement nextButton;
|
||||||
|
|
||||||
|
@FindBy(id = "signIn")
|
||||||
|
private WebElement signInButton;
|
||||||
|
|
||||||
|
@FindBy(id = "submit_approve_access")
|
||||||
|
private WebElement approveAccessButton;
|
||||||
|
|
||||||
|
@FindBy(id = "PersistentCookie")
|
||||||
|
private WebElement persisentCookieCheckbox;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void login(String user, String password) {
|
||||||
|
emailInput.sendKeys(user);
|
||||||
|
nextButton.click();
|
||||||
|
passwordInput.sendKeys(password);
|
||||||
|
persisentCookieCheckbox.click();
|
||||||
|
signInButton.click();
|
||||||
|
|
||||||
|
WaitUtils.waitUntilElement(approveAccessButton).is().enabled();
|
||||||
|
approveAccessButton.click();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2017 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.testsuite.pages.social;
|
||||||
|
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.openqa.selenium.support.FindBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Vaclav Muzikar <vmuzikar@redhat.com>
|
||||||
|
*/
|
||||||
|
public class LinkedInLoginPage extends AbstractSocialLoginPage {
|
||||||
|
@FindBy(id = "session_key-oauth2SAuthorizeForm")
|
||||||
|
private WebElement usernameInput;
|
||||||
|
|
||||||
|
@FindBy(id = "session_password-oauth2SAuthorizeForm")
|
||||||
|
private WebElement passwordInput;
|
||||||
|
|
||||||
|
@FindBy(name = "authorize")
|
||||||
|
private WebElement loginButton;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void login(String user, String password) {
|
||||||
|
usernameInput.sendKeys(user);
|
||||||
|
passwordInput.sendKeys(password);
|
||||||
|
loginButton.click();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2017 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.testsuite.pages.social;
|
||||||
|
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.openqa.selenium.support.FindBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Vaclav Muzikar <vmuzikar@redhat.com>
|
||||||
|
*/
|
||||||
|
public class MicrosoftLoginPage extends AbstractSocialLoginPage {
|
||||||
|
@FindBy(name = "loginfmt")
|
||||||
|
private WebElement usernameInput;
|
||||||
|
|
||||||
|
@FindBy(name = "passwd")
|
||||||
|
private WebElement passwordInput;
|
||||||
|
|
||||||
|
@FindBy(id = "idSIButton9")
|
||||||
|
private WebElement submitButton;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void login(String user, String password) {
|
||||||
|
usernameInput.sendKeys(user);
|
||||||
|
submitButton.click();
|
||||||
|
passwordInput.sendKeys(password);
|
||||||
|
submitButton.click();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2017 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.testsuite.pages.social;
|
||||||
|
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.openqa.selenium.support.FindBy;
|
||||||
|
|
||||||
|
import static org.keycloak.testsuite.util.WaitUtils.waitUntilElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Vaclav Muzikar <vmuzikar@redhat.com>
|
||||||
|
*/
|
||||||
|
public class StackOverflowLoginPage extends AbstractSocialLoginPage {
|
||||||
|
@FindBy(xpath = "//a[@title='log in with Stack_Exchange']")
|
||||||
|
private WebElement loginInitButton;
|
||||||
|
|
||||||
|
@FindBy(id = "affiliate-signin-iframe")
|
||||||
|
private WebElement loginFrame;
|
||||||
|
|
||||||
|
@FindBy(name = "email")
|
||||||
|
private WebElement usernameInput;
|
||||||
|
|
||||||
|
@FindBy(id = "password")
|
||||||
|
private WebElement passwordInput;
|
||||||
|
|
||||||
|
@FindBy(xpath = "//input[@value='Sign In']")
|
||||||
|
private WebElement loginButton;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void login(String user, String password) {
|
||||||
|
waitUntilElement(loginInitButton).is().visible();
|
||||||
|
loginInitButton.click();
|
||||||
|
|
||||||
|
driver.switchTo().frame(loginFrame);
|
||||||
|
|
||||||
|
usernameInput.sendKeys(user);
|
||||||
|
passwordInput.sendKeys(password);
|
||||||
|
|
||||||
|
loginButton.click();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2017 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.testsuite.pages.social;
|
||||||
|
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.openqa.selenium.support.FindBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Vaclav Muzikar <vmuzikar@redhat.com>
|
||||||
|
*/
|
||||||
|
public class TwitterLoginPage extends AbstractSocialLoginPage {
|
||||||
|
@FindBy(id = "username_or_email")
|
||||||
|
private WebElement usernameInput;
|
||||||
|
|
||||||
|
@FindBy(id = "password")
|
||||||
|
private WebElement passwordInput;
|
||||||
|
|
||||||
|
@FindBy(id = "allow")
|
||||||
|
private WebElement loginButton;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void login(String user, String password) {
|
||||||
|
usernameInput.sendKeys(user);
|
||||||
|
passwordInput.sendKeys(password);
|
||||||
|
loginButton.click();
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,18 +3,29 @@ package org.keycloak.testsuite.broker;
|
||||||
import org.jboss.arquillian.graphene.Graphene;
|
import org.jboss.arquillian.graphene.Graphene;
|
||||||
import org.jboss.arquillian.graphene.page.Page;
|
import org.jboss.arquillian.graphene.page.Page;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.keycloak.representations.idm.IdentityProviderRepresentation;
|
import org.keycloak.representations.idm.IdentityProviderRepresentation;
|
||||||
import org.keycloak.representations.idm.RealmRepresentation;
|
import org.keycloak.representations.idm.RealmRepresentation;
|
||||||
import org.keycloak.social.openshift.OpenshiftV3IdentityProvider;
|
import org.keycloak.social.openshift.OpenshiftV3IdentityProvider;
|
||||||
import org.keycloak.representations.idm.UserRepresentation;
|
import org.keycloak.representations.idm.UserRepresentation;
|
||||||
import org.keycloak.testsuite.AbstractKeycloakTest;
|
import org.keycloak.testsuite.AbstractKeycloakTest;
|
||||||
import org.keycloak.testsuite.pages.AccountUpdateProfilePage;
|
import org.keycloak.testsuite.auth.page.login.UpdateAccount;
|
||||||
import org.keycloak.testsuite.pages.LoginPage;
|
import org.keycloak.testsuite.pages.LoginPage;
|
||||||
import org.keycloak.testsuite.pages.LoginUpdateProfilePage;
|
import org.keycloak.testsuite.pages.social.AbstractSocialLoginPage;
|
||||||
|
import org.keycloak.testsuite.pages.social.FacebookLoginPage;
|
||||||
|
import org.keycloak.testsuite.pages.social.GitHubLoginPage;
|
||||||
|
import org.keycloak.testsuite.pages.social.GoogleLoginPage;
|
||||||
|
import org.keycloak.testsuite.pages.social.LinkedInLoginPage;
|
||||||
|
import org.keycloak.testsuite.pages.social.MicrosoftLoginPage;
|
||||||
|
import org.keycloak.testsuite.pages.social.StackOverflowLoginPage;
|
||||||
|
import org.keycloak.testsuite.pages.social.TwitterLoginPage;
|
||||||
import org.keycloak.testsuite.util.IdentityProviderBuilder;
|
import org.keycloak.testsuite.util.IdentityProviderBuilder;
|
||||||
import org.keycloak.testsuite.util.RealmBuilder;
|
import org.keycloak.testsuite.util.RealmBuilder;
|
||||||
|
import org.keycloak.testsuite.util.URLUtils;
|
||||||
|
import org.keycloak.testsuite.util.WaitUtils;
|
||||||
import org.openqa.selenium.By;
|
import org.openqa.selenium.By;
|
||||||
import org.openqa.selenium.support.ui.ExpectedConditions;
|
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||||
|
|
||||||
|
@ -26,9 +37,18 @@ import java.util.Properties;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assume.assumeTrue;
|
import static org.junit.Assume.assumeTrue;
|
||||||
|
import static org.keycloak.testsuite.broker.SocialLoginTest.Provider.FACEBOOK;
|
||||||
|
import static org.keycloak.testsuite.broker.SocialLoginTest.Provider.GITHUB;
|
||||||
|
import static org.keycloak.testsuite.broker.SocialLoginTest.Provider.GOOGLE;
|
||||||
|
import static org.keycloak.testsuite.broker.SocialLoginTest.Provider.LINKEDIN;
|
||||||
|
import static org.keycloak.testsuite.broker.SocialLoginTest.Provider.MICROSOFT;
|
||||||
|
import static org.keycloak.testsuite.broker.SocialLoginTest.Provider.OPENSHIFT;
|
||||||
|
import static org.keycloak.testsuite.broker.SocialLoginTest.Provider.STACKOVERFLOW;
|
||||||
|
import static org.keycloak.testsuite.broker.SocialLoginTest.Provider.TWITTER;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by st on 19.01.17.
|
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||||
|
* @author Vaclav Muzikar <vmuzikar@redhat.com>
|
||||||
*/
|
*/
|
||||||
public class SocialLoginTest extends AbstractKeycloakTest {
|
public class SocialLoginTest extends AbstractKeycloakTest {
|
||||||
|
|
||||||
|
@ -38,13 +58,39 @@ public class SocialLoginTest extends AbstractKeycloakTest {
|
||||||
private static Properties config = new Properties();
|
private static Properties config = new Properties();
|
||||||
|
|
||||||
@Page
|
@Page
|
||||||
public AccountUpdateProfilePage account;
|
private LoginPage loginPage;
|
||||||
|
|
||||||
@Page
|
@Page
|
||||||
public LoginPage loginPage;
|
private UpdateAccount updateAccountPage;
|
||||||
|
|
||||||
@Page
|
public enum Provider {
|
||||||
public LoginUpdateProfilePage updateProfilePage;
|
GOOGLE("google", GoogleLoginPage.class),
|
||||||
|
FACEBOOK("facebook", FacebookLoginPage.class),
|
||||||
|
GITHUB("github", GitHubLoginPage.class),
|
||||||
|
TWITTER("twitter", TwitterLoginPage.class),
|
||||||
|
LINKEDIN("linkedin", LinkedInLoginPage.class),
|
||||||
|
MICROSOFT("microsoft", MicrosoftLoginPage.class),
|
||||||
|
STACKOVERFLOW("stackoverflow", StackOverflowLoginPage.class),
|
||||||
|
OPENSHIFT("openshift-v3", null);
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
private Class<? extends AbstractSocialLoginPage> pageObjectClazz;
|
||||||
|
|
||||||
|
Provider(String id, Class<? extends AbstractSocialLoginPage> pageObjectClazz) {
|
||||||
|
this.id = id;
|
||||||
|
this.pageObjectClazz = pageObjectClazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String id() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class<? extends AbstractSocialLoginPage> pageObjectClazz() {
|
||||||
|
return pageObjectClazz;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Provider currentTestProvider;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void loadConfig() throws Exception {
|
public static void loadConfig() throws Exception {
|
||||||
|
@ -52,12 +98,22 @@ public class SocialLoginTest extends AbstractKeycloakTest {
|
||||||
|
|
||||||
config.load(new FileInputStream(System.getProperty(SOCIAL_CONFIG)));
|
config.load(new FileInputStream(System.getProperty(SOCIAL_CONFIG)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void beforeSocialLoginTest() {
|
||||||
|
accountPage.setAuthRealm(REALM);
|
||||||
|
accountPage.navigateTo();
|
||||||
|
currentTestProvider = null;
|
||||||
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void removeUser() {
|
public void removeUser() {
|
||||||
List<UserRepresentation> users = adminClient.realm(REALM).users().search(null, null, null);
|
List<UserRepresentation> users = adminClient.realm(REALM).users().search(null, null, null);
|
||||||
for (UserRepresentation user : users) {
|
for (UserRepresentation user : users) {
|
||||||
adminClient.realm(REALM).users().get(user.getId()).remove();
|
if (user.getServiceAccountClientId() == null) {
|
||||||
|
log.infof("removing test user '%s'", user.getUsername());
|
||||||
|
adminClient.realm(REALM).users().get(user.getId()).remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,21 +123,17 @@ public class SocialLoginTest extends AbstractKeycloakTest {
|
||||||
List<IdentityProviderRepresentation> idps = new LinkedList<>();
|
List<IdentityProviderRepresentation> idps = new LinkedList<>();
|
||||||
rep.setIdentityProviders(idps);
|
rep.setIdentityProviders(idps);
|
||||||
|
|
||||||
idps.add(buildIdp("openshift-v3"));
|
for (Provider provider : Provider.values()) {
|
||||||
idps.add(buildIdp("google"));
|
idps.add(buildIdp(provider));
|
||||||
idps.add(buildIdp("facebook"));
|
}
|
||||||
idps.add(buildIdp("github"));
|
|
||||||
idps.add(buildIdp("twitter"));
|
|
||||||
idps.add(buildIdp("linkedin"));
|
|
||||||
idps.add(buildIdp("microsoft"));
|
|
||||||
idps.add(buildIdp("stackoverflow"));
|
|
||||||
|
|
||||||
testRealms.add(rep);
|
testRealms.add(rep);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
|
// TODO: Fix and revamp this test
|
||||||
public void openshiftLogin() throws Exception {
|
public void openshiftLogin() throws Exception {
|
||||||
account.open(REALM);
|
|
||||||
loginPage.clickSocial("openshift-v3");
|
loginPage.clickSocial("openshift-v3");
|
||||||
|
|
||||||
Graphene.waitGui().until(ExpectedConditions.visibilityOfElementLocated(By.id("inputUsername")));
|
Graphene.waitGui().until(ExpectedConditions.visibilityOfElementLocated(By.id("inputUsername")));
|
||||||
|
@ -92,169 +144,136 @@ public class SocialLoginTest extends AbstractKeycloakTest {
|
||||||
Graphene.waitGui().until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input[name=approve]")));
|
Graphene.waitGui().until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input[name=approve]")));
|
||||||
driver.findElement(By.cssSelector("input[name=approve]")).click();
|
driver.findElement(By.cssSelector("input[name=approve]")).click();
|
||||||
|
|
||||||
assertEquals(config.getProperty("openshift-v3.username", config.getProperty("common.profile.username")), account.getUsername());
|
assertEquals(config.getProperty("openshift-v3.username", config.getProperty("common.profile.username")), accountPage.getUsername());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void googleLogin() throws InterruptedException {
|
public void googleLogin() throws InterruptedException {
|
||||||
account.open(REALM);
|
currentTestProvider = GOOGLE;
|
||||||
|
performLogin();
|
||||||
loginPage.clickSocial("google");
|
assertAccount();
|
||||||
|
|
||||||
Graphene.waitGui().until(ExpectedConditions.visibilityOfElementLocated(By.id("Email")));
|
|
||||||
|
|
||||||
driver.findElement(By.id("Email")).sendKeys(config.getProperty("google.username", config.getProperty("common.username")));
|
|
||||||
driver.findElement(By.id("next")).click();
|
|
||||||
|
|
||||||
Graphene.waitGui().until(ExpectedConditions.visibilityOfElementLocated(By.id("Passwd")));
|
|
||||||
|
|
||||||
driver.findElement(By.id("Passwd")).sendKeys(config.getProperty("google.password", config.getProperty("common.password")));
|
|
||||||
driver.findElement(By.id("signIn")).click();
|
|
||||||
|
|
||||||
Graphene.waitGui().until(ExpectedConditions.elementToBeClickable(By.id("submit_approve_access")));
|
|
||||||
|
|
||||||
driver.findElement(By.id("submit_approve_access")).click();
|
|
||||||
|
|
||||||
assertEquals(config.getProperty("google.profile.firstName", config.getProperty("common.profile.firstName")), account.getFirstName());
|
|
||||||
assertEquals(config.getProperty("google.profile.lastName", config.getProperty("common.profile.lastName")), account.getLastName());
|
|
||||||
assertEquals(config.getProperty("google.profile.email", config.getProperty("common.profile.email")), account.getEmail());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void faceBookLogin() {
|
public void facebookLogin() {
|
||||||
account.open(REALM);
|
currentTestProvider = FACEBOOK;
|
||||||
|
performLogin();
|
||||||
loginPage.clickSocial("facebook");
|
assertAccount();
|
||||||
|
|
||||||
Graphene.waitGui().until(ExpectedConditions.visibilityOfElementLocated(By.id("email")));
|
|
||||||
driver.findElement(By.id("email")).sendKeys(config.getProperty("facebook.username", config.getProperty("common.username")));
|
|
||||||
driver.findElement(By.id("pass")).sendKeys(config.getProperty("facebook.password", config.getProperty("common.password")));
|
|
||||||
|
|
||||||
driver.findElement(By.id("loginbutton")).click();
|
|
||||||
|
|
||||||
assertEquals(config.getProperty("facebook.profile.firstName", config.getProperty("common.profile.firstName")), account.getFirstName());
|
|
||||||
assertEquals(config.getProperty("facebook.profile.lastName", config.getProperty("common.profile.lastName")), account.getLastName());
|
|
||||||
assertEquals(config.getProperty("facebook.profile.email", config.getProperty("common.profile.email")), account.getEmail());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void githubLogin() {
|
public void githubLogin() {
|
||||||
account.open(REALM);
|
currentTestProvider = GITHUB;
|
||||||
|
performLogin();
|
||||||
loginPage.clickSocial("github");
|
assertAccount();
|
||||||
|
|
||||||
Graphene.waitGui().until(ExpectedConditions.visibilityOfElementLocated(By.id("login_field")));
|
|
||||||
driver.findElement(By.id("login_field")).sendKeys(config.getProperty("github.username", config.getProperty("common.username")));
|
|
||||||
driver.findElement(By.id("password")).sendKeys(config.getProperty("github.password", config.getProperty("common.password")));
|
|
||||||
|
|
||||||
driver.findElement(By.name("commit")).click();
|
|
||||||
|
|
||||||
assertEquals(config.getProperty("github.profile.firstName", config.getProperty("common.profile.firstName")), account.getFirstName());
|
|
||||||
assertEquals(config.getProperty("github.profile.lastName", config.getProperty("common.profile.lastName")), account.getLastName());
|
|
||||||
assertEquals(config.getProperty("github.profile.email", config.getProperty("common.profile.email")), account.getEmail());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void twitterLogin() {
|
public void twitterLogin() {
|
||||||
account.open(REALM);
|
currentTestProvider = TWITTER;
|
||||||
|
performLogin();
|
||||||
loginPage.clickSocial("twitter");
|
assertUpdateProfile(false, false, true);
|
||||||
|
assertAccount();
|
||||||
Graphene.waitGui().until(ExpectedConditions.visibilityOfElementLocated(By.id("username_or_email")));
|
|
||||||
driver.findElement(By.id("username_or_email")).sendKeys(config.getProperty("twitter.username", config.getProperty("common.username")));
|
|
||||||
driver.findElement(By.id("password")).sendKeys(config.getProperty("twitter.password", config.getProperty("common.password")));
|
|
||||||
|
|
||||||
driver.findElement(By.id("allow")).click();
|
|
||||||
|
|
||||||
assertTrue(updateProfilePage.isCurrent());
|
|
||||||
|
|
||||||
assertEquals(config.getProperty("twitter.profile.firstName", config.getProperty("common.profile.firstName")), account.getFirstName());
|
|
||||||
assertEquals(config.getProperty("twitter.profile.lastName", config.getProperty("common.profile.lastName")), account.getLastName());
|
|
||||||
assertEquals("", updateProfilePage.getEmail());
|
|
||||||
|
|
||||||
updateProfilePage.update(null, null, "keycloakey@gmail.com");
|
|
||||||
|
|
||||||
assertEquals(config.getProperty("twitter.profile.firstName", config.getProperty("common.profile.firstName")), account.getFirstName());
|
|
||||||
assertEquals(config.getProperty("twitter.profile.lastName", config.getProperty("common.profile.lastName")), account.getLastName());
|
|
||||||
assertEquals(config.getProperty("twitter.profile.email", config.getProperty("common.profile.email")), account.getEmail());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void linkedinLogin() {
|
public void linkedinLogin() {
|
||||||
account.open(REALM);
|
currentTestProvider = LINKEDIN;
|
||||||
|
performLogin();
|
||||||
loginPage.clickSocial("linkedin");
|
assertAccount();
|
||||||
|
|
||||||
Graphene.waitGui().until(ExpectedConditions.visibilityOfElementLocated(By.id("session_key-oauth2SAuthorizeForm")));
|
|
||||||
driver.findElement(By.id("session_key-oauth2SAuthorizeForm")).sendKeys(config.getProperty("linkedin.username", config.getProperty("common.username")));
|
|
||||||
driver.findElement(By.id("session_password-oauth2SAuthorizeForm")).sendKeys(config.getProperty("linkedin.password", config.getProperty("common.password")));
|
|
||||||
|
|
||||||
driver.findElement(By.name("authorize")).click();
|
|
||||||
|
|
||||||
assertEquals(config.getProperty("linkedin.profile.firstName", config.getProperty("common.profile.firstName")), account.getFirstName());
|
|
||||||
assertEquals(config.getProperty("linkedin.profile.lastName", config.getProperty("common.profile.lastName")), account.getLastName());
|
|
||||||
assertEquals(config.getProperty("linkedin.profile.email", config.getProperty("common.profile.email")), account.getEmail());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void microsoftLogin() {
|
public void microsoftLogin() {
|
||||||
account.open(REALM);
|
currentTestProvider = MICROSOFT;
|
||||||
|
performLogin();
|
||||||
loginPage.clickSocial("microsoft");
|
assertAccount();
|
||||||
|
|
||||||
Graphene.waitGui().until(ExpectedConditions.visibilityOfElementLocated(By.name("loginfmt")));
|
|
||||||
driver.findElement(By.name("loginfmt")).sendKeys(config.getProperty("microsoft.username", config.getProperty("common.username")));
|
|
||||||
driver.findElement(By.xpath("//input[@value='Next']")).click();
|
|
||||||
|
|
||||||
Graphene.waitGui().until(ExpectedConditions.visibilityOfElementLocated(By.name("passwd")));
|
|
||||||
driver.findElement(By.name("passwd")).sendKeys(config.getProperty("microsoft.password", config.getProperty("common.password")));
|
|
||||||
driver.findElement(By.xpath("//input[@value='Sign in']")).click();
|
|
||||||
|
|
||||||
assertEquals(config.getProperty("microsoft.profile.firstName", config.getProperty("common.profile.firstName")), account.getFirstName());
|
|
||||||
assertEquals(config.getProperty("microsoft.profile.lastName", config.getProperty("common.profile.lastName")), account.getLastName());
|
|
||||||
assertEquals(config.getProperty("microsoft.profile.email", config.getProperty("common.profile.email")), account.getEmail());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void stackoverflowLogin() {
|
public void stackoverflowLogin() {
|
||||||
account.open(REALM);
|
currentTestProvider = STACKOVERFLOW;
|
||||||
|
performLogin();
|
||||||
loginPage.clickSocial("stackoverflow");
|
assertUpdateProfile(false, false, true);
|
||||||
|
assertAccount();
|
||||||
Graphene.waitModel().until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[@title='log in with Stack_Exchange']")));
|
|
||||||
driver.findElement(By.xpath("//a[@title='log in with Stack_Exchange']")).click();
|
|
||||||
|
|
||||||
driver.switchTo().frame(driver.findElement(By.id("affiliate-signin-iframe")));
|
|
||||||
|
|
||||||
Graphene.waitGui().until(ExpectedConditions.visibilityOfElementLocated(By.name("email")));
|
|
||||||
driver.findElement(By.name("email")).sendKeys(config.getProperty("stackoverflow.username", config.getProperty("common.username")));
|
|
||||||
driver.findElement(By.name("password")).sendKeys(config.getProperty("stackoverflow.password", config.getProperty("common.password")));
|
|
||||||
|
|
||||||
driver.findElement(By.xpath("//input[@value='Sign In']")).click();
|
|
||||||
|
|
||||||
assertEquals(config.getProperty("stackoverflow.profile.firstName", config.getProperty("common.profile.firstName")), updateProfilePage.getFirstName());
|
|
||||||
assertEquals(config.getProperty("stackoverflow.profile.lastName", config.getProperty("common.profile.lastName")), updateProfilePage.getLastName());
|
|
||||||
assertEquals("", updateProfilePage.getEmail());
|
|
||||||
|
|
||||||
updateProfilePage.update(null, null, "keycloakey@gmail.com");
|
|
||||||
|
|
||||||
assertEquals(config.getProperty("stackoverflow.profile.firstName", config.getProperty("common.profile.firstName")), account.getFirstName());
|
|
||||||
assertEquals(config.getProperty("stackoverflow.profile.lastName", config.getProperty("common.profile.lastName")), account.getLastName());
|
|
||||||
assertEquals(config.getProperty("stackoverflow.profile.email", config.getProperty("common.profile.email")), account.getEmail());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private IdentityProviderRepresentation buildIdp(String id) {
|
private IdentityProviderRepresentation buildIdp(Provider provider) {
|
||||||
IdentityProviderRepresentation idp = IdentityProviderBuilder.create().alias(id).providerId(id).build();
|
IdentityProviderRepresentation idp = IdentityProviderBuilder.create().alias(provider.id()).providerId(provider.id()).build();
|
||||||
idp.setEnabled(true);
|
idp.setEnabled(true);
|
||||||
idp.getConfig().put("clientId", config.getProperty(id + ".clientId"));
|
idp.getConfig().put("clientId", getConfig(provider, "clientId"));
|
||||||
idp.getConfig().put("clientSecret", config.getProperty(id + ".clientSecret"));
|
idp.getConfig().put("clientSecret", getConfig(provider, "clientSecret"));
|
||||||
if (id.equals("stackoverflow")) {
|
if (provider == STACKOVERFLOW) {
|
||||||
idp.getConfig().put("key", config.getProperty(id + ".clientKey"));
|
idp.getConfig().put("key", getConfig(provider, "clientKey"));
|
||||||
}
|
}
|
||||||
if (id.equals("openshift-v3")) {
|
if (provider == OPENSHIFT) {
|
||||||
idp.getConfig().put("baseUrl", config.getProperty(id + ".baseUrl", OpenshiftV3IdentityProvider.BASE_URL));
|
idp.getConfig().put("baseUrl", config.getProperty(provider.id() + ".baseUrl", OpenshiftV3IdentityProvider.BASE_URL));
|
||||||
}
|
}
|
||||||
return idp;
|
return idp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getConfig(Provider provider, String key) {
|
||||||
|
return config.getProperty(provider.id() + "." + key, config.getProperty("common." + key));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getConfig(String key) {
|
||||||
|
return getConfig(currentTestProvider, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void performLogin() {
|
||||||
|
loginPage.clickSocial(currentTestProvider.id());
|
||||||
|
|
||||||
|
// Just to be sure there's no redirect in progress
|
||||||
|
WaitUtils.pause(3000);
|
||||||
|
WaitUtils.waitForPageToLoad(driver);
|
||||||
|
|
||||||
|
// Only when there's not active session for the social provider, i.e. login is required
|
||||||
|
if (URLUtils.currentUrlDoesntStartWith(driver, getAuthServerRoot().toASCIIString())) {
|
||||||
|
log.infof("current URL: %s", driver.getCurrentUrl());
|
||||||
|
log.infof("performing log in to '%s' ...", currentTestProvider.id());
|
||||||
|
AbstractSocialLoginPage loginPage = Graphene.createPageFragment(currentTestProvider.pageObjectClazz(), driver.findElement(By.tagName("html")));
|
||||||
|
loginPage.login(getConfig("username"), getConfig("password"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
log.infof("already logged in to '%s'; skipping the login process", currentTestProvider.id());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertAccount() {
|
||||||
|
assertTrue(URLUtils.currentUrlStartWith(driver, accountPage.toString())); // Sometimes after login the URL ends with /# or similar
|
||||||
|
|
||||||
|
assertEquals(getConfig("profile.firstName"), accountPage.getFirstName());
|
||||||
|
assertEquals(getConfig("profile.lastName"), accountPage.getLastName());
|
||||||
|
assertEquals(getConfig("profile.email"), accountPage.getEmail());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertUpdateProfile(boolean firstName, boolean lastName, boolean email) {
|
||||||
|
assertTrue(URLUtils.currentUrlDoesntStartWith(driver, accountPage.toString()));
|
||||||
|
|
||||||
|
if (firstName) {
|
||||||
|
assertTrue(updateAccountPage.fields().getFirstName().isEmpty());
|
||||||
|
updateAccountPage.fields().setFirstName(getConfig("profile.firstName"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
assertEquals(getConfig("profile.firstName"), updateAccountPage.fields().getFirstName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastName) {
|
||||||
|
assertTrue(updateAccountPage.fields().getLastName().isEmpty());
|
||||||
|
updateAccountPage.fields().setLastName(getConfig("profile.lastName"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
assertEquals(getConfig("profile.lastName"), updateAccountPage.fields().getLastName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (email) {
|
||||||
|
assertTrue(updateAccountPage.fields().getEmail().isEmpty());
|
||||||
|
updateAccountPage.fields().setEmail(getConfig("profile.email"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
assertEquals(getConfig("profile.email"), updateAccountPage.fields().getEmail());
|
||||||
|
}
|
||||||
|
|
||||||
|
updateAccountPage.submit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue