Package org.keycloak.testsuite.rule.KeycloakRule

Examples of org.keycloak.testsuite.rule.KeycloakRule.KeycloakSetup


        userId = keycloakRule.getUser("test", "test-user@localhost").getId();
    }

    @After
    public void after() {
        keycloakRule.update(new KeycloakSetup() {
            @Override
            public void config(RealmManager manager, RealmModel defaultRealm, RealmModel appRealm) {
                UserModel user = manager.getSession().users().getUserByUsername("test-user@localhost", appRealm);

                UserCredentialModel cred = new UserCredentialModel();
View Full Code Here


        Assert.assertEquals("No access", errorPage.getError());
    }

    @Test
    public void viewLog() {
        keycloakRule.update(new KeycloakSetup() {
            @Override
            public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
                appRealm.setEventsEnabled(true);
            }
        });

        try {
            List<Event> expectedEvents = new LinkedList<Event>();

            loginPage.open();
            loginPage.clickRegister();

            registerPage.register("view", "log", "view-log@localhost", "view-log", "password", "password");

            expectedEvents.add(events.poll());
            expectedEvents.add(events.poll());

            profilePage.open();
            profilePage.updateProfile("view", "log2", "view-log@localhost");

            expectedEvents.add(events.poll());

            logPage.open();

            Assert.assertTrue(logPage.isCurrent());

            List<List<String>> actualEvents = logPage.getEvents();

            Assert.assertEquals(expectedEvents.size(), actualEvents.size());

            for (Event e : expectedEvents) {
                boolean match = false;
                for (List<String> a : logPage.getEvents()) {
                    if (e.getType().toString().replace('_', ' ').toLowerCase().equals(a.get(1)) &&
                            e.getIpAddress().equals(a.get(2)) &&
                            e.getClientId().equals(a.get(3))) {
                        match = true;
                        break;
                    }
                }
                if (!match) {
                    Assert.fail("Event not found " + e.getType());
                }
            }
        } finally {
            keycloakRule.update(new KeycloakSetup() {
                @Override
                public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
                    appRealm.setEventsEnabled(false);
                }
            });
View Full Code Here

        events.expectLogin().assertEvent();
    }

    @Test
    public void profileUpdateRequired() {
        keycloakRule.configure(new KeycloakSetup() {
            @Override
            public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
                appRealm.setUpdateProfileOnInitialSocialLogin(true);
            }
        });

        try {
            loginPage.open();

            loginPage.clickSocial("dummy");

            driver.findElement(By.id("id")).sendKeys("2");
            driver.findElement(By.id("username")).sendKeys("dummy-user2");
            driver.findElement(By.id("firstname")).sendKeys("Bob");
            driver.findElement(By.id("lastname")).sendKeys("Builder");
            driver.findElement(By.id("email")).sendKeys("bob@builder.com");
            driver.findElement(By.id("login")).click();

            profilePage.isCurrent();

            Assert.assertEquals("Bob", profilePage.getFirstName());
            Assert.assertEquals("Builder", profilePage.getLastName());
            Assert.assertEquals("bob@builder.com", profilePage.getEmail());

            String userId = events.expect(EventType.REGISTER)
                    .user(AssertEvents.isUUID())
                    .detail(Details.EMAIL, "bob@builder.com")
                    .detail(Details.REGISTER_METHOD, "social@dummy")
                    .detail(Details.REDIRECT_URI, AssertEvents.DEFAULT_REDIRECT_URI)
                    .detail(Details.USERNAME, "2@dummy")
                    .assertEvent().getUserId();

            profilePage.update("Dummy", "User", "dummy-user-reg@dummy-social");

            events.expectRequiredAction(EventType.UPDATE_PROFILE).user(userId).detail(Details.AUTH_METHOD, "social@dummy").detail(Details.USERNAME, "2@dummy").assertEvent();
            events.expectRequiredAction(EventType.UPDATE_EMAIL).user(userId).detail(Details.AUTH_METHOD, "social@dummy").detail(Details.USERNAME, "2@dummy").detail(Details.PREVIOUS_EMAIL, "bob@builder.com").detail(Details.UPDATED_EMAIL, "dummy-user-reg@dummy-social").assertEvent();

            Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());

            Event loginEvent = events.expectLogin().user(userId).removeDetail(Details.USERNAME).detail(Details.AUTH_METHOD, "social@dummy").detail(Details.USERNAME, "2@dummy").assertEvent();
            String codeId = loginEvent.getDetails().get(Details.CODE_ID);

            AccessTokenResponse response = oauth.doAccessTokenRequest(oauth.getCurrentQuery().get(OAuth2Constants.CODE), "password");
            AccessToken token = oauth.verifyToken(response.getAccessToken());

            events.expectCodeToToken(codeId, loginEvent.getSessionId()).user(userId).assertEvent();

            UserRepresentation profile = keycloakRule.getUserById("test", token.getSubject());

            Assert.assertEquals("Dummy", profile.getFirstName());
            Assert.assertEquals("User", profile.getLastName());
            Assert.assertEquals("dummy-user-reg@dummy-social", profile.getEmail());
        } finally {
            keycloakRule.configure(new KeycloakSetup() {
                @Override
                public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
                    appRealm.setUpdateProfileOnInitialSocialLogin(false);
                }
            });
View Full Code Here

        try {

            loginPage.open();
            loginPage.login("test-user@localhost", "password");

            keycloakRule.configure(new KeycloakSetup() {
                @Override
                public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
                    lifespan = appRealm.getAccessCodeLifespanUserAction();
                    appRealm.setAccessCodeLifespanUserAction(1);
                }
            });

            loginTotpPage.assertCurrent();

            Thread.sleep(2000);

            loginTotpPage.login(totp.generate("totpSecret"));

            loginPage.assertCurrent();
            Assert.assertEquals("Invalid username or password.", loginPage.getError());

            AssertEvents.ExpectedEvent expectedEvent = events.expectLogin().error("invalid_code")
                    .user((String)null)
                    .clearDetails()
                    .session((String) null);
            expectedEvent.assertEvent();
        } finally {
            keycloakRule.configure(new KeycloakSetup() {
                @Override
                public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
                    appRealm.setAccessCodeLifespanUserAction(lifespan);
                }
            });
View Full Code Here

    protected RegisterPage registerPage;

    @Before
    public void before() {
        oauth.state("mystate"); // have to set this as keycloak validates that state is sent
        keycloakRule.configure(new KeycloakSetup() {

            @Override
            public void config(RealmManager manager, RealmModel defaultRealm, RealmModel appRealm) {
                appRealm.setVerifyEmail(true);
View Full Code Here

TOP

Related Classes of org.keycloak.testsuite.rule.KeycloakRule.KeycloakSetup

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.