Search in sources :

Example 1 with SocialLoginTest

use of org.keycloak.testsuite.broker.SocialLoginTest in project keycloak by keycloak.

the class ReAuthenticationTest method loadTestRealm.

private RealmRepresentation loadTestRealm() {
    RealmRepresentation res = loadJson(getClass().getResourceAsStream("/testrealm.json"), RealmRepresentation.class);
    res.setBrowserFlow("browser");
    res.setRememberMe(true);
    // Add some sample dummy GitHub, Gitlab & Google social providers to the testing realm. Those are dummy providers for test if they are visible (clickable)
    // on the login pages
    List<IdentityProviderRepresentation> idps = new ArrayList<>();
    for (SocialLoginTest.Provider provider : Arrays.asList(GITHUB, GOOGLE)) {
        SocialLoginTest socialLoginTest = new SocialLoginTest();
        idps.add(socialLoginTest.buildIdp(provider));
    }
    res.setIdentityProviders(idps);
    return res;
}
Also used : RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) IdentityProviderRepresentation(org.keycloak.representations.idm.IdentityProviderRepresentation) ArrayList(java.util.ArrayList) SocialLoginTest(org.keycloak.testsuite.broker.SocialLoginTest)

Example 2 with SocialLoginTest

use of org.keycloak.testsuite.broker.SocialLoginTest in project keycloak by keycloak.

the class BrowserFlowTest method testSocialProvidersPresentOnLoginUsernameOnlyPageIfConfigured.

@Test
@AuthServerContainerExclude(REMOTE)
public void testSocialProvidersPresentOnLoginUsernameOnlyPageIfConfigured() {
    String testRealm = "test";
    // Test setup - Configure the testing Keycloak instance with UsernameForm & PasswordForm (both REQUIRED) and OTPFormAuthenticator (ALTERNATIVE)
    configureBrowserFlowWithRequiredPasswordFormAndAlternativeOTP("browser - copy 1");
    try {
        SocialLoginTest socialLoginTest = new SocialLoginTest();
        // matters is if they are visible (clickable) on the LoginUsernameOnlyPage once the page is loaded
        for (SocialLoginTest.Provider provider : Arrays.asList(GITHUB, GITLAB, GOOGLE)) {
            adminClient.realm(testRealm).identityProviders().create(socialLoginTest.buildIdp(provider));
            loginUsernameOnlyPage.open();
            loginUsernameOnlyPage.assertCurrent();
            // For each of the testing social providers, check the particular social provider button is present on the UsernameForm
            // Test succeeded if NoSuchElementException is thrown for none of them
            loginUsernameOnlyPage.findSocialButton(provider.id());
        }
    // Test cleanup - Return back to the initial state
    } finally {
        // Drop the testing social providers previously created within the test
        for (IdentityProviderRepresentation providerRepresentation : adminClient.realm(testRealm).identityProviders().findAll()) {
            adminClient.realm(testRealm).identityProviders().get(providerRepresentation.getInternalId()).remove();
        }
        revertFlows("browser - copy 1");
    }
}
Also used : IdentityProviderRepresentation(org.keycloak.representations.idm.IdentityProviderRepresentation) Matchers.containsString(org.hamcrest.Matchers.containsString) SocialLoginTest(org.keycloak.testsuite.broker.SocialLoginTest) AuthServerContainerExclude(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude) SocialLoginTest(org.keycloak.testsuite.broker.SocialLoginTest) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest) AbstractAuthenticationTest(org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest)

Aggregations

IdentityProviderRepresentation (org.keycloak.representations.idm.IdentityProviderRepresentation)2 SocialLoginTest (org.keycloak.testsuite.broker.SocialLoginTest)2 ArrayList (java.util.ArrayList)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.Test)1 RealmRepresentation (org.keycloak.representations.idm.RealmRepresentation)1 AbstractTestRealmKeycloakTest (org.keycloak.testsuite.AbstractTestRealmKeycloakTest)1 AbstractAuthenticationTest (org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest)1 AuthServerContainerExclude (org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude)1