Search in sources :

Example 11 with AuthServerContainerExclude

use of org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude in project keycloak by keycloak.

the class AccountFormServiceTest method applicationsVisibilityNoScopesAndConsent.

@Test
@AuthServerContainerExclude(AuthServer.REMOTE)
public void applicationsVisibilityNoScopesAndConsent() throws Exception {
    try (ClientAttributeUpdater cau = ClientAttributeUpdater.forClient(adminClient, REALM_NAME, ROOT_URL_CLIENT).setConsentRequired(true).setFullScopeAllowed(false).setDefaultClientScopes(Collections.EMPTY_LIST).setOptionalClientScopes(Collections.EMPTY_LIST).update()) {
        applicationsPage.open();
        loginPage.login("john-doh@localhost", "password");
        applicationsPage.assertCurrent();
        Map<String, AccountApplicationsPage.AppEntry> apps = applicationsPage.getApplications();
        Assert.assertThat(apps.keySet(), containsInAnyOrder("root-url-client", "Account", "Account Console", "test-app", "test-app-scope", "third-party", "test-app-authz", "My Named Test App", "Test App Named - ${client_account}", "direct-grant", "custom-audience"));
    }
}
Also used : ClientAttributeUpdater(org.keycloak.testsuite.updaters.ClientAttributeUpdater) Matchers.containsString(org.hamcrest.Matchers.containsString) AuthServerContainerExclude(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 12 with AuthServerContainerExclude

use of org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude in project keycloak by keycloak.

the class SessionRestServiceTest method testGetSessions.

@Test
@AuthServerContainerExclude(AuthServer.REMOTE)
public void testGetSessions() throws Exception {
    oauth.setDriver(secondBrowser);
    codeGrant("public-client-0");
    List<SessionRepresentation> sessions = getSessions();
    assertEquals(2, sessions.size());
    for (SessionRepresentation session : sessions) {
        assertNotNull(session.getId());
        assertThat(session.getIpAddress(), anyOf(equalTo("127.0.0.1"), equalTo("0:0:0:0:0:0:0:1")));
        assertTrue(session.getLastAccess() > 0);
        assertTrue(session.getExpires() > 0);
        assertTrue(session.getStarted() > 0);
        assertThat(session.getClients(), Matchers.hasItem(Matchers.hasProperty("clientId", anyOf(Matchers.is("direct-grant"), Matchers.is("public-client-0")))));
    }
}
Also used : SessionRepresentation(org.keycloak.representations.account.SessionRepresentation) AuthServerContainerExclude(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude) Test(org.junit.Test)

Example 13 with AuthServerContainerExclude

use of org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude in project keycloak by keycloak.

the class RegisterTest method registerUserSuccessWithEmailVerificationWithResend.

@Test
// GreenMailRule is not working atm
@AuthServerContainerExclude(AuthServer.REMOTE)
public void registerUserSuccessWithEmailVerificationWithResend() throws Exception {
    try (RealmAttributeUpdater rau = setVerifyEmail(true).update()) {
        loginPage.open();
        loginPage.clickRegister();
        registerPage.assertCurrent();
        registerPage.register("firstName", "lastName", "registerUserSuccessWithEmailVerificationWithResend@email", "registerUserSuccessWithEmailVerificationWithResend", "password", "password");
        verifyEmailPage.assertCurrent();
        String userId = events.expectRegister("registerUserSuccessWithEmailVerificationWithResend", "registerUserSuccessWithEmailVerificationWithResend@email").assertEvent().getUserId();
        {
            assertTrue("Expecting verify email", greenMail.waitForIncomingEmail(1000, 1));
            events.expect(EventType.SEND_VERIFY_EMAIL).detail(Details.EMAIL, "registerUserSuccessWithEmailVerificationWithResend@email".toLowerCase()).user(userId).assertEvent();
            verifyEmailPage.clickResendEmail();
            verifyEmailPage.assertCurrent();
            assertTrue("Expecting second verify email", greenMail.waitForIncomingEmail(1000, 1));
            events.expect(EventType.SEND_VERIFY_EMAIL).detail(Details.EMAIL, "registerUserSuccessWithEmailVerificationWithResend@email".toLowerCase()).user(userId).assertEvent();
            MimeMessage message = greenMail.getLastReceivedMessage();
            String link = MailUtils.getPasswordResetEmailLink(message);
            driver.navigate().to(link);
        }
        events.expectRequiredAction(EventType.VERIFY_EMAIL).detail(Details.EMAIL, "registerUserSuccessWithEmailVerificationWithResend@email".toLowerCase()).user(userId).assertEvent();
        assertUserRegistered(userId, "registerUserSuccessWithEmailVerificationWithResend", "registerUserSuccessWithEmailVerificationWithResend@email");
        appPage.assertCurrent();
        assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
    // test that timestamp is current with 10s tollerance
    // test user info is set from form
    }
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) RealmAttributeUpdater(org.keycloak.testsuite.updaters.RealmAttributeUpdater) Matchers.containsString(org.hamcrest.Matchers.containsString) AuthServerContainerExclude(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 14 with AuthServerContainerExclude

use of org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude in project keycloak by keycloak.

the class RegisterTest method registerUserSuccessWithEmailVerification.

@Test
// GreenMailRule is not working atm
@AuthServerContainerExclude(AuthServer.REMOTE)
public void registerUserSuccessWithEmailVerification() throws Exception {
    try (RealmAttributeUpdater rau = setVerifyEmail(true).update()) {
        loginPage.open();
        loginPage.clickRegister();
        registerPage.assertCurrent();
        registerPage.register("firstName", "lastName", "registerUserSuccessWithEmailVerification@email", "registerUserSuccessWithEmailVerification", "password", "password");
        verifyEmailPage.assertCurrent();
        String userId = events.expectRegister("registerUserSuccessWithEmailVerification", "registerUserSuccessWithEmailVerification@email").assertEvent().getUserId();
        {
            assertTrue("Expecting verify email", greenMail.waitForIncomingEmail(1000, 1));
            events.expect(EventType.SEND_VERIFY_EMAIL).detail(Details.EMAIL, "registerUserSuccessWithEmailVerification@email".toLowerCase()).user(userId).assertEvent();
            MimeMessage message = greenMail.getLastReceivedMessage();
            String link = MailUtils.getPasswordResetEmailLink(message);
            driver.navigate().to(link);
        }
        events.expectRequiredAction(EventType.VERIFY_EMAIL).detail(Details.EMAIL, "registerUserSuccessWithEmailVerification@email".toLowerCase()).user(userId).assertEvent();
        assertUserRegistered(userId, "registerUserSuccessWithEmailVerification", "registerUserSuccessWithEmailVerification@email");
        appPage.assertCurrent();
        assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
    // test that timestamp is current with 10s tollerance
    // test user info is set from form
    }
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) RealmAttributeUpdater(org.keycloak.testsuite.updaters.RealmAttributeUpdater) Matchers.containsString(org.hamcrest.Matchers.containsString) AuthServerContainerExclude(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 15 with AuthServerContainerExclude

use of org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude in project keycloak by keycloak.

the class BrowserFlowTest method testLoginMultiFactorWithWrongCredentialsMessage.

/**
 * This test checks the error messages, when the credentials are invalid and UsernameForm and PasswordForm are separated.
 */
@Test
@AuthServerContainerExclude(REMOTE)
public void testLoginMultiFactorWithWrongCredentialsMessage() {
    UserRepresentation user = testRealm().users().search("test-user@localhost").get(0);
    Assert.assertNotNull(user);
    MultiFactorAuthenticationTest.configureBrowserFlowWithAlternativeCredentials(testingClient);
    try {
        RealmRepresentation realm = testRealm().toRepresentation();
        realm.setLoginWithEmailAllowed(false);
        testRealm().update(realm);
        loginUsernameOnlyPage.open();
        loginUsernameOnlyPage.assertCurrent();
        loginUsernameOnlyPage.login("non_existing_user");
        Assert.assertEquals("Invalid username.", loginUsernameOnlyPage.getUsernameError());
        Assert.assertEquals("Invalid username.", loginUsernameOnlyPage.getUsernameError());
        realm.setLoginWithEmailAllowed(true);
        testRealm().update(realm);
        loginUsernameOnlyPage.login("non_existing_user");
        Assert.assertEquals("Invalid username or email.", loginUsernameOnlyPage.getUsernameError());
        Assert.assertEquals("Invalid username or email.", loginUsernameOnlyPage.getUsernameError());
        loginUsernameOnlyPage.login(user.getUsername());
        passwordPage.assertCurrent();
        passwordPage.login("wrong_password");
        Assert.assertEquals("Invalid password.", passwordPage.getPasswordError());
        Assert.assertEquals("Invalid password.", passwordPage.getPasswordError());
        passwordPage.assertCurrent();
        events.clear();
        passwordPage.login("password");
        Assert.assertFalse(loginUsernameOnlyPage.isCurrent());
        Assert.assertFalse(passwordPage.isCurrent());
        events.expectLogin().user(user).detail(Details.USERNAME, "test-user@localhost").assertEvent();
    } finally {
        revertFlows("browser - alternative");
    }
}
Also used : RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) 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

Test (org.junit.Test)108 AuthServerContainerExclude (org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude)108 AbstractTestRealmKeycloakTest (org.keycloak.testsuite.AbstractTestRealmKeycloakTest)31 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)30 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)29 Matchers.containsString (org.hamcrest.Matchers.containsString)28 AbstractKeycloakTest (org.keycloak.testsuite.AbstractKeycloakTest)27 Response (javax.ws.rs.core.Response)24 UserResource (org.keycloak.admin.client.resource.UserResource)21 AbstractAuthenticationTest (org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest)21 SocialLoginTest (org.keycloak.testsuite.broker.SocialLoginTest)21 MimeMessage (javax.mail.internet.MimeMessage)14 OAuthClient (org.keycloak.testsuite.util.OAuthClient)14 OIDCClientRepresentation (org.keycloak.representations.oidc.OIDCClientRepresentation)13 ComponentRepresentation (org.keycloak.representations.idm.ComponentRepresentation)12 LinkedList (java.util.LinkedList)11 List (java.util.List)9 RealmRepresentation (org.keycloak.representations.idm.RealmRepresentation)9 HashMap (java.util.HashMap)8 IOException (java.io.IOException)7