From 4aa102fcab705aeab25e8a351727a600f769b25f Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Fri, 24 Jun 2016 10:43:06 +0200 Subject: [PATCH 1/2] Remove testsuite/stress --- testsuite/pom.xml | 1 - testsuite/stress/pom.xml | 575 ------------------ .../keycloak/test/stress/MaxRateExecutor.java | 138 ----- .../keycloak/test/stress/StressExecutor.java | 65 -- .../keycloak/test/stress/StressResult.java | 62 -- .../org/keycloak/test/stress/StressTest.java | 37 -- .../java/org/keycloak/test/stress/Test.java | 11 - .../org/keycloak/test/stress/TestFactory.java | 9 - .../test/stress/tests/LoginLogout.java | 104 ---- .../test/CustomerDatabaseServlet.java | 51 -- .../org/keycloak/test/LoginLogoutTest.java | 96 --- .../adapter-test/cust-app-keycloak.json | 11 - .../stress/src/test/resources/testrealm.json | 185 ------ 13 files changed, 1345 deletions(-) delete mode 100755 testsuite/stress/pom.xml delete mode 100755 testsuite/stress/src/main/java/org/keycloak/test/stress/MaxRateExecutor.java delete mode 100755 testsuite/stress/src/main/java/org/keycloak/test/stress/StressExecutor.java delete mode 100755 testsuite/stress/src/main/java/org/keycloak/test/stress/StressResult.java delete mode 100755 testsuite/stress/src/main/java/org/keycloak/test/stress/StressTest.java delete mode 100755 testsuite/stress/src/main/java/org/keycloak/test/stress/Test.java delete mode 100755 testsuite/stress/src/main/java/org/keycloak/test/stress/TestFactory.java delete mode 100755 testsuite/stress/src/main/java/org/keycloak/test/stress/tests/LoginLogout.java delete mode 100755 testsuite/stress/src/test/java/org/keycloak/test/CustomerDatabaseServlet.java delete mode 100755 testsuite/stress/src/test/java/org/keycloak/test/LoginLogoutTest.java delete mode 100755 testsuite/stress/src/test/resources/adapter-test/cust-app-keycloak.json delete mode 100755 testsuite/stress/src/test/resources/testrealm.json diff --git a/testsuite/pom.xml b/testsuite/pom.xml index c934177fab..e7fa229b60 100755 --- a/testsuite/pom.xml +++ b/testsuite/pom.xml @@ -56,7 +56,6 @@ tomcat7 tomcat8 jetty - stress integration-arquillian diff --git a/testsuite/stress/pom.xml b/testsuite/stress/pom.xml deleted file mode 100755 index 8e37d92cc1..0000000000 --- a/testsuite/stress/pom.xml +++ /dev/null @@ -1,575 +0,0 @@ - - - - - - keycloak-testsuite-pom - org.keycloak - 2.0.0.CR1-SNAPSHOT - ../pom.xml - - 4.0.0 - - keycloak-stress-tester - Keycloak Stress TestSuite - - - - - org.bouncycastle - bcprov-jdk15on - - - org.bouncycastle - bcpkix-jdk15on - - - org.keycloak - keycloak-dependencies-server-all - pom - - - org.keycloak - keycloak-admin-client - - - org.keycloak - keycloak-wildfly-adduser - - - log4j - log4j - - - org.jboss.spec.javax.servlet - jboss-servlet-api_3.0_spec - - - org.jboss.spec.javax.ws.rs - jboss-jaxrs-api_2.0_spec - - - org.jboss.resteasy - async-http-servlet-3.0 - - - org.jboss.resteasy - resteasy-jaxrs - - - log4j - log4j - - - org.slf4j - slf4j-api - - - org.slf4j - slf4j-simple - - - - - org.jboss.resteasy - resteasy-client - - - org.jboss.resteasy - resteasy-undertow - - - org.jboss.resteasy - resteasy-multipart-provider - - - org.jboss.resteasy - resteasy-jackson2-provider - - - com.google.zxing - javase - - - org.apache.httpcomponents - httpclient - - - org.keycloak - keycloak-server-spi - - - org.keycloak - keycloak-ldap-federation - - - org.keycloak - keycloak-kerberos-federation - - - org.keycloak - keycloak-undertow-adapter - - - org.keycloak - keycloak-saml-adapter-api-public - - - org.keycloak - keycloak-saml-adapter-core - - - org.keycloak - keycloak-saml-servlet-filter-adapter - - - org.keycloak - keycloak-servlet-filter-adapter - - - org.keycloak - keycloak-saml-undertow-adapter - - - org.keycloak - keycloak-jaxrs-oauth-client - - - org.keycloak - federation-properties-example - - - org.jboss.logging - jboss-logging - - - io.undertow - undertow-servlet - - - io.undertow - undertow-core - - - com.fasterxml.jackson.core - jackson-core - - - com.fasterxml.jackson.core - jackson-databind - - - com.fasterxml.jackson.core - jackson-annotations - - - junit - junit - provided - - - org.hamcrest - hamcrest-all - - - org.hibernate.javax.persistence - hibernate-jpa-2.1-api - - - com.h2database - h2 - - - org.hibernate - hibernate-entitymanager - - - com.icegreen - greenmail - - - org.slf4j - slf4j-api - - - - - org.infinispan - infinispan-core - - - org.seleniumhq.selenium - selenium-java - provided - - - xml-apis - xml-apis - - - org.seleniumhq.selenium - selenium-chrome-driver - provided - - - - - org.keycloak - keycloak-util-embedded-ldap - - - - org.wildfly - wildfly-undertow - test - - - org.keycloak - keycloak-testsuite-integration - test-jar - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.2 - - - - test-jar - - - - - - org.apache.maven.plugins - maven-deploy-plugin - - true - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${maven.compiler.source} - ${maven.compiler.target} - - - - org.codehaus.mojo - exec-maven-plugin - - ${project.basedir} - - - - org.apache.felix - maven-bundle-plugin - true - true - - - org.apache.maven.plugins - maven-javadoc-plugin - - true - - - - - - - - keycloak-server - - - - org.codehaus.mojo - exec-maven-plugin - - org.keycloak.testsuite.KeycloakServer - test - - - - - - - mail-server - - - - org.codehaus.mojo - exec-maven-plugin - - org.keycloak.testsuite.MailServer - test - - - - - - - totp - - - - org.codehaus.mojo - exec-maven-plugin - - org.keycloak.testsuite.TotpGenerator - test - - - - - - - ldap - - - - org.codehaus.mojo - exec-maven-plugin - - org.keycloak.util.ldap.LDAPEmbeddedServer - test - - - - - - - kerberos - - - - org.codehaus.mojo - exec-maven-plugin - - org.keycloak.util.ldap.KerberosEmbeddedServer - test - - - - - - - - jpa - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - jpa - jpa - jpa - jpa - - debug - - - - - - - - - mongo - - - localhost - 27018 - keycloak - 127.0.0.1 - - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - test - integration-test - - test - - - - mongo - mongo - mongo - mongo - ${keycloak.connectionsMongo.host} - ${keycloak.connectionsMongo.port} - ${keycloak.connectionsMongo.db} - ${keycloak.connectionsMongo.bindIp} - - - - - default-test - - true - - - - - - - - com.github.joelittlejohn.embedmongo - embedmongo-maven-plugin - - - start-mongodb - pre-integration-test - - start - - - ${keycloak.connectionsMongo.port} - file - ${project.build.directory}/mongodb.log - ${keycloak.connectionsMongo.bindIp} - - - - stop-mongodb - post-integration-test - - stop - - - - - - - - - - - - - - keycloak.connectionsJpa.driver - com.mysql.jdbc.Driver - - - mysql - - - mysql - mysql-connector-java - - - - - - - - - keycloak.connectionsJpa.driver - org.postgresql.Driver - - - postgresql - - - org.postgresql - postgresql - ${postgresql.version} - - - - - - clean-jpa - - - - org.liquibase - liquibase-maven-plugin - - META-INF/jpa-changelog-master.xml - - ${keycloak.connectionsJpa.url} - ${keycloak.connectionsJpa.driver} - ${keycloak.connectionsJpa.user} - ${keycloak.connectionsJpa.password} - - false - ${keycloak.connectionsJpa.liquibaseDatabaseClass} - - - - clean-jpa - clean - - dropAll - - - - - - - - - - - - - ldap.vendor - msad - - - msad - - - - org.apache.maven.plugins - maven-surefire-plugin - - - org/keycloak/testsuite/federation/ldap/base/** - - - **/LDAPMultipleAttributesTest.java - - - - - - - - - diff --git a/testsuite/stress/src/main/java/org/keycloak/test/stress/MaxRateExecutor.java b/testsuite/stress/src/main/java/org/keycloak/test/stress/MaxRateExecutor.java deleted file mode 100755 index e56aa83e77..0000000000 --- a/testsuite/stress/src/main/java/org/keycloak/test/stress/MaxRateExecutor.java +++ /dev/null @@ -1,138 +0,0 @@ -package org.keycloak.test.stress; - -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorCompletionService; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; - -/** - * Executes a test N number of times. This is done multiple times over an ever expanding amount of threads to determine - * when the computer is saturated and you can't eek out any more concurrent requests. - * - * @author Bill Burke - * @version $Revision: 1 $ - */ -public class MaxRateExecutor { - - public static class RateResult { - StressResult result; - int threads; - long time; - - public RateResult(StressResult result, int threads, long time) { - this.result = result; - this.threads = threads; - this.time = time; - } - - public StressResult getResult() { - return result; - } - - public int getThreads() { - return threads; - } - - public long getTime() { - return time; - } - } - - List allResults = new LinkedList<>(); - RateResult fastest = null; - RateResult last = null; - - - - public void best(TestFactory factory, int jobs) { - fastest = last = null; - int threads = 2; - do { - fastest = last; - try { - last = execute(factory, threads, jobs); - allResults.add(last); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } catch (ExecutionException e) { - throw new RuntimeException(e); - } - threads++; - } while (fastest == null || fastest.time > last.time); - } - - public RateResult getFastest() { - return fastest; - } - - public RateResult getLast() { - return last; - } - - public RateResult execute(TestFactory factory, int threads, int jobs) throws InterruptedException, ExecutionException { - List tests = new LinkedList<>(); - ExecutorService executor = Executors.newFixedThreadPool(threads); - ExecutorCompletionService completionService = new ExecutorCompletionService<>(executor); - StressResult result = new StressResult("num threads:" + threads); - addTest(factory, result, tests, threads + 5); - long start = System.currentTimeMillis(); - for (StressTest stressTest : tests) { - completionService.submit(stressTest); - } - for (int i = 0; i < jobs; i++) { - Future future = completionService.take(); - StressTest stressTest = future.get(); - if (i < jobs - threads - 5) completionService.submit(stressTest); - } - long end = System.currentTimeMillis() - start; - executor.shutdown(); - executor.awaitTermination(10, TimeUnit.SECONDS); - RateResult rate = new RateResult(result, threads, end); - return rate; - } - - private void addTest(TestFactory factory, StressResult result, List tests, int num) { - int add = num - tests.size(); - for (int i = 0; i < add; i++) { - Test test = factory.create(); - test.init(); - StressTest stress = new StressTest(result, test, 1); - tests.add(stress); - } - } - - public void printResults() { - System.out.println("*******************"); - System.out.println("* Best Result *"); - System.out.println("*******************"); - printResult(fastest); - } - - - public void printResult(RateResult result) { - System.out.println("Threads: " + result.getThreads()); - System.out.println("Total Time: " + result.getTime()); - System.out.println("Rate: " + ((double)result.getResult().getIterations()) / ((double)result.getTime())); - System.out.println("Successes: " + result.getResult().getSuccess()); - System.out.println("Iterations: " + result.getResult().getIterations()); - System.out.println("Average time per iteration: " + result.getResult().getAverageTime()); - - } - - public void printSummary() { - - for (RateResult result : allResults) { - System.out.println("*******************"); - printSummary(result); - } - } - public void printSummary(RateResult result) { - System.out.println("Threads: " + result.getThreads()); - System.out.println("Total Time: " + result.getTime()); - } -} diff --git a/testsuite/stress/src/main/java/org/keycloak/test/stress/StressExecutor.java b/testsuite/stress/src/main/java/org/keycloak/test/stress/StressExecutor.java deleted file mode 100755 index ebf6ef117d..0000000000 --- a/testsuite/stress/src/main/java/org/keycloak/test/stress/StressExecutor.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.keycloak.test.stress; - -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Random; -import java.util.concurrent.Callable; -import java.util.concurrent.CompletionService; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorCompletionService; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; - -/** - * Executes all test threads until completion. - * - * @author Bill Burke - * @version $Revision: 1 $ - */ -public class StressExecutor { - protected List tests = new LinkedList<>(); - protected List results = new LinkedList<>(); - - public void addTest(Class test, int threads, int iterations) { - StressResult result = new StressResult(test.getName()); - results.add(result); - for (int i = 0; i < threads; i++) { - try { - Test t = test.newInstance(); - t.init(); - StressTest stress = new StressTest(result, t, iterations); - tests.add(stress); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - } - } - - public void addTest(Test test, StressResult result, int iterations) { - tests.add(new StressTest(result, test, iterations)); - } - - public void addTest(Test test, int iterations) { - StressResult result = new StressResult(test.getClass().getName()); - tests.add(new StressTest(result, test, iterations)); - } - - public long execute() throws InterruptedException, ExecutionException { - ExecutorService executor = Executors.newFixedThreadPool(tests.size()); - Collections.shuffle(tests); - long start = System.currentTimeMillis(); - for (StressTest test : tests) { - executor.submit(test); - } - executor.shutdown(); - boolean done = executor.awaitTermination(100, TimeUnit.HOURS); - long end = System.currentTimeMillis() - start; - return end; - - } -} diff --git a/testsuite/stress/src/main/java/org/keycloak/test/stress/StressResult.java b/testsuite/stress/src/main/java/org/keycloak/test/stress/StressResult.java deleted file mode 100755 index 080c5532d0..0000000000 --- a/testsuite/stress/src/main/java/org/keycloak/test/stress/StressResult.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.keycloak.test.stress; - -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; - -/** - * @author Bill Burke - * @version $Revision: 1 $ - */ -public class StressResult { - ThreadLocal start = new ThreadLocal<>(); - AtomicLong iterations = new AtomicLong(); - AtomicLong totalTime = new AtomicLong(); - String name; - AtomicInteger success = new AtomicInteger(); - - public StressResult(String name) { - this.name = name; - } - - public void start() { - start.set(System.currentTimeMillis()); - } - - public void success() { - success.incrementAndGet(); - } - - public void end() { - long end = System.currentTimeMillis() - start.get(); - totalTime.addAndGet(end); - iterations.incrementAndGet(); - } - - public int getSuccess() { - return success.get(); - } - - public String getName() { - return name; - } - - public long getTotalTime() { - return totalTime.longValue(); - } - public long getIterations() { - return iterations.get(); - } - - public double getAverageTime() { - return (double)(double)totalTime.get() / (double)iterations.get(); - } - public double getRate() { - return (double)(double)iterations.get() / (double)totalTime.get(); - } - - public void clear() { - iterations.set(0); - totalTime.set(0); - success.set(0); - } -} diff --git a/testsuite/stress/src/main/java/org/keycloak/test/stress/StressTest.java b/testsuite/stress/src/main/java/org/keycloak/test/stress/StressTest.java deleted file mode 100755 index 363c5e2d8b..0000000000 --- a/testsuite/stress/src/main/java/org/keycloak/test/stress/StressTest.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.keycloak.test.stress; - -import jdk.nashorn.internal.codegen.CompilerConstants; - -import java.util.concurrent.Callable; -import java.util.concurrent.CountDownLatch; - -/** - * @author Bill Burke - * @version $Revision: 1 $ - */ -public class StressTest implements Callable { - protected StressResult result; - protected Callable test; - protected int iterations; - - public StressTest(StressResult result, Callable test, int iterations) { - this.result = result; - this.test = test; - this.iterations = iterations; - } - - @Override - public StressTest call() throws Exception { - for (int i = 0; i < iterations; i++) { - result.start(); - try { - if (test.call()) { - result.success(); - } - } catch (Throwable throwable) { - } - result.end(); - } - return this; - } -} diff --git a/testsuite/stress/src/main/java/org/keycloak/test/stress/Test.java b/testsuite/stress/src/main/java/org/keycloak/test/stress/Test.java deleted file mode 100755 index 04b7233ad1..0000000000 --- a/testsuite/stress/src/main/java/org/keycloak/test/stress/Test.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.keycloak.test.stress; - -import java.util.concurrent.Callable; - -/** - * @author Bill Burke - * @version $Revision: 1 $ - */ -public interface Test extends Callable { - void init(); -} diff --git a/testsuite/stress/src/main/java/org/keycloak/test/stress/TestFactory.java b/testsuite/stress/src/main/java/org/keycloak/test/stress/TestFactory.java deleted file mode 100755 index aee1f7b463..0000000000 --- a/testsuite/stress/src/main/java/org/keycloak/test/stress/TestFactory.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.keycloak.test.stress; - -/** - * @author Bill Burke - * @version $Revision: 1 $ - */ -public interface TestFactory { - Test create(); -} diff --git a/testsuite/stress/src/main/java/org/keycloak/test/stress/tests/LoginLogout.java b/testsuite/stress/src/main/java/org/keycloak/test/stress/tests/LoginLogout.java deleted file mode 100755 index 859bc45367..0000000000 --- a/testsuite/stress/src/main/java/org/keycloak/test/stress/tests/LoginLogout.java +++ /dev/null @@ -1,104 +0,0 @@ -package org.keycloak.test.stress.tests; - -import org.junit.Assert; -import org.keycloak.OAuth2Constants; -import org.keycloak.admin.client.Keycloak; -import org.keycloak.models.Constants; -import org.keycloak.protocol.oidc.OIDCLoginProtocolService; -import org.keycloak.test.stress.Test; -import org.keycloak.testsuite.OAuthClient; -import org.keycloak.testsuite.pages.LoginPage; -import org.keycloak.testsuite.rule.WebResource; -import org.keycloak.testsuite.rule.WebRule; -import org.openqa.selenium.WebDriver; - -import javax.ws.rs.core.UriBuilder; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -/** - * @author Bill Burke - * @version $Revision: 1 $ - */ -public class LoginLogout implements Test { - public WebRule webRule = new WebRule(this); - - protected String securedResourceUrl; - protected List containsInPage = new LinkedList<>(); - protected String realm; - protected String authServerUrl; - protected String username; - protected String password; - - protected String loginUrl; - protected String logoutUrl; - - @WebResource - protected WebDriver driver; - - @WebResource - protected LoginPage loginPage; - - public LoginLogout securedResourceUrl(String securedResourceUrl) { - this.securedResourceUrl = securedResourceUrl; - return this; - } - - public LoginLogout addPageContains(String contains) { - containsInPage.add(contains); - return this; - } - - public LoginLogout realm(String realm) { - this.realm = realm; - return this; - } - - public LoginLogout authServerUrl(String authServerUrl) { - this.authServerUrl = authServerUrl; - return this; - } - - public LoginLogout username(String username) { - this.username = username; - return this; - } - - public LoginLogout password(String password) { - this.password = password; - return this; - } - - @Override - public void init() { - - loginUrl = OIDCLoginProtocolService.authUrl(UriBuilder.fromUri(authServerUrl)).build(realm).toString(); - logoutUrl = OIDCLoginProtocolService.logoutUrl(UriBuilder.fromUri(authServerUrl)) - .queryParam(OAuth2Constants.REDIRECT_URI, securedResourceUrl).build(realm).toString(); - try { - webRule.before(); - } catch (Throwable e) { - throw new RuntimeException(e); - } - - } - - @Override - public Boolean call() throws Exception { - driver.navigate().to(securedResourceUrl); - Assert.assertTrue(driver.getCurrentUrl().startsWith(loginUrl)); - loginPage.login(username, password); - Assert.assertTrue(driver.getCurrentUrl().startsWith(securedResourceUrl)); - String pageSource = driver.getPageSource(); - for (String contains : containsInPage) { - Assert.assertTrue(pageSource.contains(contains)); - - } - - // test logout - driver.navigate().to(logoutUrl); - Assert.assertTrue(driver.getCurrentUrl().startsWith(loginUrl)); - return true; - } -} diff --git a/testsuite/stress/src/test/java/org/keycloak/test/CustomerDatabaseServlet.java b/testsuite/stress/src/test/java/org/keycloak/test/CustomerDatabaseServlet.java deleted file mode 100755 index 0115ef19e0..0000000000 --- a/testsuite/stress/src/test/java/org/keycloak/test/CustomerDatabaseServlet.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2016 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.test; - -import org.junit.Assert; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.PrintWriter; -import java.security.Principal; - -/** - * @author Bill Burke - * @version $Revision: 1 $ - */ -public class CustomerDatabaseServlet extends HttpServlet { - private static final String LINK = "%s"; - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - resp.setContentType("text/html"); - PrintWriter pw = resp.getWriter(); - Principal principal = req.getUserPrincipal(); - Assert.assertNotNull(principal); - pw.printf("%s", "Customer Portal"); - pw.println("Stian Thorgersen"); - pw.println("Bill Burke"); - pw.print(""); - pw.flush(); - - - } -} diff --git a/testsuite/stress/src/test/java/org/keycloak/test/LoginLogoutTest.java b/testsuite/stress/src/test/java/org/keycloak/test/LoginLogoutTest.java deleted file mode 100755 index 351f8f442e..0000000000 --- a/testsuite/stress/src/test/java/org/keycloak/test/LoginLogoutTest.java +++ /dev/null @@ -1,96 +0,0 @@ -package org.keycloak.test; - -import org.junit.ClassRule; -import org.junit.Test; -import org.keycloak.models.KeycloakSession; -import org.keycloak.models.RealmModel; -import org.keycloak.services.managers.RealmManager; -import org.keycloak.test.stress.MaxRateExecutor; -import org.keycloak.test.stress.StressExecutor; -import org.keycloak.test.stress.TestFactory; -import org.keycloak.test.stress.tests.LoginLogout; -import org.keycloak.testsuite.adapter.AdapterTestStrategy; -import org.keycloak.testsuite.adapter.CallAuthenticatedServlet; -import org.keycloak.testsuite.adapter.CustomerDatabaseServlet; -import org.keycloak.testsuite.adapter.CustomerServlet; -import org.keycloak.testsuite.adapter.InputServlet; -import org.keycloak.testsuite.adapter.ProductServlet; -import org.keycloak.testsuite.adapter.SessionServlet; -import org.keycloak.testsuite.rule.AbstractKeycloakRule; - -import java.net.URL; - -/** - * @author Bill Burke - * @version $Revision: 1 $ - */ -public class LoginLogoutTest { - @ClassRule - public static AbstractKeycloakRule keycloakRule = new AbstractKeycloakRule() { - @Override - protected void configure(KeycloakSession session, RealmManager manager, RealmModel adminRealm) { - RealmModel realm = AdapterTestStrategy.baseAdapterTestInitialization(session, manager, adminRealm, getClass()); - - URL url = getClass().getResource("/adapter-test/cust-app-keycloak.json"); - createApplicationDeployment() - .name("customer-portal").contextPath("/customer-portal") - .servletClass(org.keycloak.test.CustomerDatabaseServlet.class).adapterConfigPath(url.getPath()) - .role("user").deployApplication(); - - } - }; - - @Test - public void testStressExecutor() throws Exception { - System.out.println("*************************"); - System.out.println(); - System.out.println(); - StressExecutor executor = new StressExecutor(); - LoginLogout test = new LoginLogout(); - test.authServerUrl("http://localhost:8081/auth") - .realm("demo") - .username("bburke@redhat.com") - .password("password") - .securedResourceUrl("http://localhost:8081/customer-portal"); - test.init(); - executor.addTest(test, 5); - long time = executor.execute(); - System.out.println("Took: " + time ); - } - - /* -************************** -* Bill's Best Result * -************************** -Threads: 13 -Total Time: 1018 -Successes: 400 -Iterations: 400 -Average time: 32.8075 -Rate: 0.030480835174883793 - */ - - @Test - public void testRate() throws Exception { - System.out.println("*************************"); - System.out.println(); - System.out.println(); - TestFactory factory = new TestFactory() { - @Override - public org.keycloak.test.stress.Test create() { - LoginLogout test = new LoginLogout(); - test.authServerUrl("http://localhost:8081/auth") - .realm("demo") - .username("bburke@redhat.com") - .password("password") - .securedResourceUrl("http://localhost:8081/customer-portal"); - return test; - } - }; - MaxRateExecutor executor = new MaxRateExecutor(); - executor.best(factory, 10); - executor.printResults(); - executor.printSummary(); - } - -} diff --git a/testsuite/stress/src/test/resources/adapter-test/cust-app-keycloak.json b/testsuite/stress/src/test/resources/adapter-test/cust-app-keycloak.json deleted file mode 100755 index e9ad98722c..0000000000 --- a/testsuite/stress/src/test/resources/adapter-test/cust-app-keycloak.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "realm": "demo", - "resource": "customer-portal", - "realm-public-key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB", - "auth-server-url": "http://localhost:8081/auth", - "ssl-required" : "external", - "expose-token": true, - "credentials": { - "secret": "password" - } -} diff --git a/testsuite/stress/src/test/resources/testrealm.json b/testsuite/stress/src/test/resources/testrealm.json deleted file mode 100755 index b4718dde46..0000000000 --- a/testsuite/stress/src/test/resources/testrealm.json +++ /dev/null @@ -1,185 +0,0 @@ -{ - "id": "test", - "realm": "test", - "enabled": true, - "sslRequired": "external", - "registrationAllowed": true, - "resetPasswordAllowed": true, - "editUsernameAllowed" : true, - "privateKey": "MIICXAIBAAKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQABAoGAfmO8gVhyBxdqlxmIuglbz8bcjQbhXJLR2EoS8ngTXmN1bo2L90M0mUKSdc7qF10LgETBzqL8jYlQIbt+e6TH8fcEpKCjUlyq0Mf/vVbfZSNaVycY13nTzo27iPyWQHK5NLuJzn1xvxxrUeXI6A2WFpGEBLbHjwpx5WQG9A+2scECQQDvdn9NE75HPTVPxBqsEd2z10TKkl9CZxu10Qby3iQQmWLEJ9LNmy3acvKrE3gMiYNWb6xHPKiIqOR1as7L24aTAkEAtyvQOlCvr5kAjVqrEKXalj0Tzewjweuxc0pskvArTI2Oo070h65GpoIKLc9jf+UA69cRtquwP93aZKtW06U8dQJAF2Y44ks/mK5+eyDqik3koCI08qaC8HYq2wVl7G2QkJ6sbAaILtcvD92ToOvyGyeE0flvmDZxMYlvaZnaQ0lcSQJBAKZU6umJi3/xeEbkJqMfeLclD27XGEFoPeNrmdx0q10Azp4NfJAY+Z8KRyQCR2BEG+oNitBOZ+YXF9KCpH3cdmECQHEigJhYg+ykOvr1aiZUMFT72HU0jnmQe2FVekuG+LJUt2Tm7GtMjTFoGpf0JwrVuZN39fOYAlo+nTixgeW7X8Y=", - "publicKey": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB", - "requiredCredentials": [ "password" ], - "defaultRoles": [ "user" ], - "smtpServer": { - "from": "auto@keycloak.org", - "host": "localhost", - "port":"3025" - }, - "users" : [ - { - "username" : "test-user@localhost", - "enabled": true, - "email" : "test-user@localhost", - "firstName": "Tom", - "lastName": "Brady", - "credentials" : [ - { "type" : "password", - "value" : "password" } - ], - "realmRoles": ["user", "offline_access"], - "clientRoles": { - "test-app": [ "customer-user" ], - "account": [ "view-profile", "manage-account" ] - } - }, - { - "username" : "john-doh@localhost", - "enabled": true, - "email" : "john-doh@localhost", - "firstName": "John", - "lastName": "Doh", - "credentials" : [ - { "type" : "password", - "value" : "password" } - ], - "realmRoles": ["user"], - "clientRoles": { - "test-app": [ "customer-user" ], - "account": [ "view-profile", "manage-account" ] - } - }, - { - "username" : "keycloak-user@localhost", - "enabled": true, - "email" : "keycloak-user@localhost", - "credentials" : [ - { "type" : "password", - "value" : "password" } - ], - "realmRoles": ["user"], - "clientRoles": { - "test-app": [ "customer-user" ], - "account": [ "view-profile", "manage-account" ] - } - }, - { - "username" : "topGroupUser", - "enabled": true, - "email" : "top@redhat.com", - "credentials" : [ - { "type" : "password", - "value" : "password" } - ], - "groups": [ - "/topGroup" - ] - }, - { - "username" : "level2GroupUser", - "enabled": true, - "email" : "level2@redhat.com", - "credentials" : [ - { "type" : "password", - "value" : "password" } - ], - "groups": [ - "/topGroup/level2group" - ] - } - ], - "scopeMappings": [ - { - "client": "third-party", - "roles": ["user"] - }, - { - "client": "test-app", - "roles": ["user"] - } - ], - "clients": [ - { - "clientId": "test-app", - "enabled": true, - "baseUrl": "http://localhost:8081/app", - "redirectUris": [ - "http://localhost:8081/app/*" - ], - "adminUrl": "http://localhost:8081/app/logout", - "secret": "password" - }, - { - "clientId" : "third-party", - "enabled": true, - "consentRequired": true, - - "redirectUris": [ - "http://localhost:8081/app/*" - ], - "secret": "password" - } - ], - "roles" : { - "realm" : [ - { - "name": "user", - "description": "Have User privileges" - }, - { - "name": "admin", - "description": "Have Administrator privileges" - } - ], - "client" : { - "test-app" : [ - { - "name": "customer-user", - "description": "Have Customer User privileges" - }, - { - "name": "customer-admin", - "description": "Have Customer Admin privileges" - } - ] - } - - }, - "groups" : [ - { - "name": "topGroup", - "attributes": { - "topAttribute": ["true"] - - }, - "realmRoles": ["user"], - - "subGroups": [ - { - "name": "level2group", - "realmRoles": ["admin"], - "clientRoles": { - "test-app": ["customer-user"] - }, - "attributes": { - "level2Attribute": ["true"] - - } - } - ] - } - ], - - - "clientScopeMappings": { - "test-app": [ - { - "client": "third-party", - "roles": ["customer-user"] - } - ] - }, - - "internationalizationEnabled": true, - "supportedLocales": ["en", "de"], - "defaultLocale": "en" -} From a6af72cbbc4f788e950a6ca3f25bc40bd115b44a Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Fri, 24 Jun 2016 10:45:51 +0200 Subject: [PATCH 2/2] Removed perf package from testsuite/integration --- .../testsuite/perf/AccessTokenPerfTest.java | 272 ------------------ 1 file changed, 272 deletions(-) delete mode 100755 testsuite/integration/src/test/java/org/keycloak/testsuite/perf/AccessTokenPerfTest.java diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/perf/AccessTokenPerfTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/perf/AccessTokenPerfTest.java deleted file mode 100755 index 98bb73ebda..0000000000 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/perf/AccessTokenPerfTest.java +++ /dev/null @@ -1,272 +0,0 @@ -/* - * Copyright 2016 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.perf; - -import org.apache.http.NameValuePair; -import org.apache.http.client.CookieStore; -import org.apache.http.client.utils.URLEncodedUtils; -import org.apache.http.cookie.Cookie; -import org.apache.http.impl.client.DefaultHttpClient; -import org.jboss.resteasy.client.jaxrs.ResteasyClient; -import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; -import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine; -import org.junit.Assert; -import org.junit.ClassRule; -import org.junit.Test; -import org.keycloak.OAuth2Constants; -import org.keycloak.adapters.HttpClientBuilder; -import org.keycloak.protocol.oidc.OIDCLoginProtocolService; -import org.keycloak.services.resources.LoginActionsService; -import org.keycloak.testsuite.Constants; -import org.keycloak.testsuite.OAuthClient; -import org.keycloak.testsuite.OAuthClient.AccessTokenResponse; -import org.keycloak.testsuite.rule.KeycloakRule; -import org.keycloak.testsuite.rule.WebRule; -import org.keycloak.util.BasicAuthHelper; -import org.openqa.selenium.WebDriver; - -import javax.ws.rs.client.Entity; -import javax.ws.rs.core.Form; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriBuilder; -import java.net.URI; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicLong; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * @author Stian Thorgersen - */ -public class AccessTokenPerfTest { - - @ClassRule - public static KeycloakRule keycloakRule = new KeycloakRule(); - - public static class BrowserLogin implements Runnable - { - - private WebDriver driver; - - public BrowserLogin() { - driver = WebRule.createWebDriver(); - } - - @Override - public void run() { - driver.manage().deleteAllCookies(); - OAuthClient oauth = new OAuthClient(driver); - oauth.doLogin("test-user@localhost", "password"); - String code = oauth.getCurrentQuery().get(OAuth2Constants.CODE); - AccessTokenResponse response = oauth.doAccessTokenRequest(code, "password"); - Assert.assertEquals(200, response.getStatusCode()); - count.incrementAndGet(); - - } - } - - public static AtomicLong count = new AtomicLong(0); - - public static class JaxrsClientLogin implements Runnable - { - ResteasyClient client; - - private String baseUrl = Constants.AUTH_SERVER_ROOT; - - private String realm = "test"; - - private String responseType = OAuth2Constants.CODE; - - private String grantType = "authorization_code"; - - private String clientId = "test-app"; - - private String redirectUri = "http://localhost:8081/app/auth"; - - - public JaxrsClientLogin() { - DefaultHttpClient httpClient = (DefaultHttpClient) new HttpClientBuilder().build(); - httpClient.setCookieStore(new CookieStore() { - @Override - public void addCookie(Cookie cookie) { - //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public List getCookies() { - return Collections.emptyList(); - } - - @Override - public boolean clearExpired(Date date) { - return false; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public void clear() { - //To change body of implemented methods use File | Settings | File Templates. - } - }); - ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient); - this.client = new ResteasyClientBuilder().httpEngine(engine).build(); - } - - public String getLoginFormUrl(String state) { - UriBuilder b = OIDCLoginProtocolService.authUrl(UriBuilder.fromUri(baseUrl)); - if (responseType != null) { - b.queryParam(OAuth2Constants.RESPONSE_TYPE, responseType); - } - if (clientId != null) { - b.queryParam(OAuth2Constants.CLIENT_ID, clientId); - } - if (redirectUri != null) { - b.queryParam(OAuth2Constants.REDIRECT_URI, redirectUri); - } - if (state != null) { - b.queryParam(OAuth2Constants.STATE, state); - } - return b.build(realm).toString(); - } - - static Pattern actionParser = Pattern.compile("action=\"([^\"]+)\""); - - public void run() { - //this.client = new ResteasyClientBuilder().build(); - String state = "42"; - String loginFormUrl = getLoginFormUrl(state); - String html = client.target(loginFormUrl).request().get(String.class); - Matcher matcher = actionParser.matcher(html); - matcher.find(); - String actionUrl = matcher.group(1); - if (!actionUrl.startsWith("http")) { - actionUrl = UriBuilder.fromUri(actionUrl).scheme("http").host("localhost").port(8081).build().toString(); - } - Form form = new Form(); - form.param("username", "test-user@localhost"); - form.param("password", "password"); - Response response = client.target(actionUrl).request().post(Entity.form(form)); - URI uri = null; - Assert.assertEquals(302, response.getStatus()); - uri = response.getLocation(); - if (response.getStatus() == 302) { - while (uri.toString().contains("login-actions/")) { - response = client.target(uri).request().get(); - Assert.assertEquals(302, response.getStatus()); - uri = response.getLocation(); - } - } - - for (String header : response.getHeaders().keySet()) { - for (Object value : response.getHeaders().get(header)) { - System.out.println(header + ": " + value); - } - } - response.close(); - - Assert.assertNotNull(uri); - String code = getCode(uri); - Assert.assertNotNull(code); - - form = new Form(); - form.param(OAuth2Constants.GRANT_TYPE, grantType) - .param(OAuth2Constants.CODE, code) - .param(OAuth2Constants.REDIRECT_URI, redirectUri); - - String authorization = BasicAuthHelper.createHeader(clientId, "password"); - - String res = client.target(OIDCLoginProtocolService.tokenUrl(UriBuilder.fromUri(baseUrl)).build(realm)).request() - .header(HttpHeaders.AUTHORIZATION, authorization) - .post(Entity.form(form), String.class); - count.incrementAndGet(); - //client.close(); - } - - public String getCode(URI uri) { - Map m = new HashMap(); - List pairs = URLEncodedUtils.parse(uri, "UTF-8"); - for (NameValuePair p : pairs) { - if (p.getName().equals("code")) return p.getValue(); - m.put(p.getName(), p.getValue()); - } - return null; - } - - - public void close() - { - client.close(); - } - } - - @Test - public void perfJaxrsClientLogin() - { - long ITERATIONS = 3; - JaxrsClientLogin login = new JaxrsClientLogin(); - long start = System.currentTimeMillis(); - for (int i = 0; i < ITERATIONS; i++) { - //System.out.println("*************************"); - login.run(); - } - long end = System.currentTimeMillis() - start; - System.out.println("took: " + end); - } - - @Test - public void perfBrowserLogin() - { - long ITERATIONS = 3; - long start = System.currentTimeMillis(); - BrowserLogin login = new BrowserLogin(); - for (int i = 0; i < ITERATIONS; i++) { - //System.out.println("----------------------------------"); - login.run(); - } - long end = System.currentTimeMillis() - start; - System.out.println("took: " + end); - } - - @Test - public void multiThread() throws Exception { - int num_threads = 20; - Thread[] threads = new Thread[num_threads]; - for (int i = 0; i < num_threads; i++) { - threads[i] = new Thread(new Runnable() { - @Override - public void run() { - perfJaxrsClientLogin(); - } - }); - } - long start = System.currentTimeMillis(); - for (int i = 0; i < num_threads; i++) { - threads[i].start(); - } - for (int i = 0; i < num_threads; i++) { - threads[i].join(); - } - long end = System.currentTimeMillis() - start; - System.out.println(count.toString() + " took: " + end); - System.out.println(count.floatValue() / ((float)end) * 1000+ " logins/s"); - } - -}