Permalink
Browse files

CFID-142: add auth code load tests and mvn support

Change-Id: I0da71b2f002c8e7cd061d74c01b020b6ea72515a
  • Loading branch information...
1 parent 3938c95 commit 5a49b3f5289df1f051cbef4207b8ac844ad12196 @dsyer dsyer committed Feb 20, 2012
Showing with 13,596 additions and 184 deletions.
  1. +1 −0 .gitignore
  2. +1 −1 gatling/gatling
  3. +125 −0 gatling/pom.xml
  4. +0 −24 gatling/simulations/LoadLoginSimulation.scala
  5. +0 −96 gatling/simulations/uaa/OAuthComponents.scala
  6. +0 −62 gatling/simulations/uaa/ScimComponents.scala
  7. +1 −0 gatling/src/main/ab/login_marissa.txt
  8. +12,600 −0 gatling/src/main/resources/assets/js/highcharts.js
  9. +238 −0 gatling/src/main/resources/assets/js/highstock.js
  10. +4 −0 gatling/src/main/resources/assets/js/jquery.min.js
  11. +127 −0 gatling/src/main/resources/assets/js/theme.js
  12. BIN gatling/src/main/resources/assets/style/cible.png
  13. BIN gatling/src/main/resources/assets/style/logo.png
  14. BIN gatling/src/main/resources/assets/style/sou-menu-fleche-ouvert.png
  15. BIN gatling/src/main/resources/assets/style/sous-menu-fleche.png
  16. BIN gatling/src/main/resources/assets/style/stat-fleche-bas.png
  17. BIN gatling/src/main/resources/assets/style/stat-fond.png
  18. BIN gatling/src/main/resources/assets/style/stat-l-roue.png
  19. BIN gatling/src/main/resources/assets/style/stat-l-temps.png
  20. +133 −0 gatling/src/main/resources/assets/style/style.css
  21. +27 −0 gatling/src/main/resources/gatling.conf
  22. +19 −0 gatling/src/main/resources/logback.xml
  23. +21 −0 gatling/src/main/scala/AuthorizationCodeSimulation.scala
  24. +0 −1 gatling/{simulations → src/main/scala}/CreateUsersSimulation.scala
  25. +21 −0 gatling/src/main/scala/LoadLoginSimulation.scala
  26. 0 gatling/{simulations → src/main/scala}/uaa/Config.scala
  27. +181 −0 gatling/src/main/scala/uaa/OAuthComponents.scala
  28. +57 −0 gatling/src/main/scala/uaa/ScimComponents.scala
  29. 0 gatling/{simulations → src/main/scala}/uaa/UsernamePasswordFeeder.scala
  30. +12 −0 gatling/src/test/scala/Engine.scala
  31. +18 −0 gatling/src/test/scala/IDEPathHelper.scala
  32. +10 −0 gatling/src/test/scala/Recorder.scala
View
@@ -6,6 +6,7 @@ target/
*/src/main/*/WEB-INF/lib/
.access_token
.result
+.cache
.classpath
.project
.DS_Store
View
@@ -8,4 +8,4 @@ PWD=`pwd`
echo $PWD
-$GATLING_HOME/bin/gatling.sh -sf $PWD/simulations
+$GATLING_HOME/bin/gatling.sh -sf $PWD/src/main/scala
View
@@ -0,0 +1,125 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.cloudfoundry.runtime</groupId>
+ <artifactId>cloudfoundry-identity-gatling</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+
+ <properties>
+ <maven.compiler.source>1.6</maven.compiler.source>
+ <maven.compiler.target>1.6</maven.compiler.target>
+ <scala.version>2.9.1</scala.version>
+ <encoding>UTF-8</encoding>
+
+ <gatling.version>1.1.0-SNAPSHOT</gatling.version>
+ <gatling-highcharts.version>1.1.0-SNAPSHOT</gatling-highcharts.version>
+
+ <maven-scala-plugin.version>2.15.2</maven-scala-plugin.version>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>com.excilys.ebi.gatling</groupId>
+ <artifactId>gatling-app</artifactId>
+ <version>${gatling.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>com.excilys.ebi.gatling</groupId>
+ <artifactId>gatling-recorder</artifactId>
+ <version>${gatling.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.excilys.ebi.gatling.highcharts</groupId>
+ <artifactId>gatling-charts-highcharts</artifactId>
+ <version>${gatling-highcharts.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.scala-lang</groupId>
+ <artifactId>scala-library</artifactId>
+ <version>${scala.version}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>com.excilys.ebi.gatling</groupId>
+ <artifactId>gatling-app</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.excilys.ebi.gatling</groupId>
+ <artifactId>gatling-recorder</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.scala-lang</groupId>
+ <artifactId>scala-library</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.excilys.ebi.gatling.highcharts</groupId>
+ <artifactId>gatling-charts-highcharts</artifactId>
+ </dependency>
+ </dependencies>
+
+ <repositories>
+ <repository>
+ <id>repository.excilys.com</id>
+ <url>http://repository.excilys.com/content/repositories/releases</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ <repository>
+ <id>snapshots.excilys.com</id>
+ <url>http://repository.excilys.com/content/repositories/snapshots</url>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.scala-tools</groupId>
+ <artifactId>maven-scala-plugin</artifactId>
+ <version>${maven-scala-plugin.version}</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.scala-tools</groupId>
+ <artifactId>maven-scala-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>compile</goal>
+ <goal>testCompile</goal>
+ </goals>
+ <configuration><sourceDir></sourceDir>
+ <args>
+ <arg>-make:transitive</arg>
+ <arg>-dependencyfile</arg>
+ <arg>${project.build.directory}/.scala_dependencies</arg>
+ </args>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
@@ -1,24 +0,0 @@
-import com.excilys.ebi.gatling.app.Simulation
-import com.excilys.ebi.gatling.core.Predef._
-import com.excilys.ebi.gatling.http.Predef._
-
-import uaa.OAuthComponents._
-import uaa.Config._
-import uaa.UsernamePasswordFeeder
-
-class LoadLoginSimulation extends Simulation {
-
- def apply = {
- val scn = scenario("VMC Load Login")
- .feed(UsernamePasswordFeeder())
- .loop(
- chain.exec(
- // Uses the session values for username/password provided by the feeder
- vmcLogin ()
- )
- .pause(1,2)
- ).during(60)
-
- Seq(scn.configure users 10 ramp 10 protocolConfig uaaHttpConfig)
- }
-}
@@ -1,96 +0,0 @@
-package uaa
-
-import com.excilys.ebi.gatling.core.Predef._
-import com.excilys.ebi.gatling.http.Predef._
-import com.excilys.ebi.gatling.core.action.builder.AbstractActionBuilder
-import com.ning.http.client.Response
-import com.excilys.ebi.gatling.http.request.HttpPhase
-import com.excilys.ebi.gatling.core.check._
-import com.excilys.ebi.gatling.http.check.{HttpCheck, HttpCheckBuilder}
-import java.util.regex.Pattern
-
-/**
- * Checks for the presence of an access token in the fragment of the Location header or JSON body
- */
-object AccessTokenCheckBuilder {
- val fragmentTokenPattern = Pattern.compile(".*#.*access_token=([^&]+).*")
- val jsonBodyTokenPattern = Pattern.compile(""""access_token":"(.*?)"""")
-
- def fragmentToken = new FragmentTokenCheckBuilder
-
- def jsonToken = new JsonTokenCheckBuilder
-
- private[uaa] def fragmentExtractorFactory: ExtractorFactory[Response, String] = { (response: Response) => (expression: String) =>
- val matcher = fragmentTokenPattern.matcher(response.getHeader("Location"))
-
- if (matcher.find()) Some(matcher.group(1)) else None
- }
-
- private[uaa] def jsonExtractorFactory: ExtractorFactory[Response, String] = { (response: Response) => (expression: String) =>
- val matcher = jsonBodyTokenPattern.matcher(response.getResponseBody)
-
- if (matcher.find()) Some(matcher.group(1)) else None
- }
-
-}
-
-import AccessTokenCheckBuilder._
-
-private[uaa] class FragmentTokenCheckBuilder extends HttpCheckBuilder[String](s => "", HttpPhase.HeadersReceived) {
- def find = new CheckOneBuilder[HttpCheck[String], Response, String](httpCheckBuilderFactory, fragmentExtractorFactory)
-}
-
-private[uaa] class JsonTokenCheckBuilder extends HttpCheckBuilder[String](s => "", HttpPhase.CompletePageReceived) {
- def find = new CheckOneBuilder[HttpCheck[String], Response, String](httpCheckBuilderFactory, jsonExtractorFactory)
-}
-
-
-/**
- */
-object OAuthComponents {
- private val plainHeaders = Map(
- "Accept" -> "application/json",
- "Content-Type" -> "application/x-www-form-urlencoded")
-
- /**
- * Performs an oauth token request as the specific client and saves the returned token
- * in the client session under the key "access_token".
- *
- */
- def clientCredentialsAccessTokenRequest(
- username: String, password: String, client_id: String, scope: String): AbstractActionBuilder = {
-
- http("Client Credentials Token Request")
- .post("/oauth/token")
- .basicAuth(username, password)
- .param("client_id", client_id)
- .param("scope", scope)
- .param("grant_type", "client_credentials")
- .headers(plainHeaders)
- .check(status.is(200), jsonToken.saveAs("access_token"))
- }
-
- /**
- * Action which performs an implicit token request as VMC client.
- *
- * Requires a username and password in the session.
- */
- def vmcLogin(scope: String = "read"): AbstractActionBuilder = vmcLogin("${username}", "${password}", scope)
-
- /**
- * Single vmc login action with a specific username/password and scope
- */
- def vmcLogin(username: String, password: String, scope: String): AbstractActionBuilder = {
- http("VMC login")
- .post("/oauth/authorize")
- .param("client_id", "vmc")
- .param("scope", scope)
- .param("credentials", """{"username":"%s","%s":"password"}""".format(username, password))
- .param("redirect_uri", "uri:oauth:token")
- .param("response_type", "token")
- .headers(plainHeaders)
- .check(status.is(302), fragmentToken.saveAs("access_token"))
- }
-
-
-}
@@ -1,62 +0,0 @@
-package uaa
-
-import com.excilys.ebi.gatling.core.Predef._
-import com.excilys.ebi.gatling.http.Predef._
-import com.excilys.ebi.gatling.core.structure.ChainBuilder
-
-import uaa.OAuthComponents._
-import java.util.concurrent.TimeUnit
-
-/**
- */
-object ScimComponents {
-
- /**
- * Creates 'n' users by invoking the SCIM API.
- *
- * Usernames can optionally be prefixed
- */
- def createScimUsers(n: Int, usernamePrefix: String = "joe"): ChainBuilder = {
- chain.exec(clientCredentialsAccessTokenRequest(
- username = "scim",
- password = "scimsecret",
- client_id = "scim",
- scope = "write password"))
- .loop(
- chain.feed(UsernamePasswordFeeder(usernamePrefix))
- .insertChain(createScimUserChain)
- .pause(50,100, TimeUnit.MILLISECONDS)
- ).times(n)
- }
-
- /**
- * Creates a SCIM user.
- *
- * A suitable access token must already be available in the session, as well as username and password values.
- *
- */
- private val createScimUserChain: ChainBuilder = {
- chain.exec(
- http("Create User")
- .post("/User")
- .header("Authorization", "Bearer ${access_token}")
- .body("""{"name":{"givenName":"Joe","familyName":"User","formatted":"Joe User"},"userName":"${username}","emails":[{"value":"${username}@blah.com"}]}""")
- .asJSON()
- .check(status.is(201), regex(""""id":"(.*?)"""").saveAs("__scimUserId"))
- )
- .exec(
- http("Change Password")
- .put("/User/${__scimUserId}/password")
- .header("Authorization", "Bearer ${access_token}")
- .body("""{"password":"${password}"}""")
- .asJSON()
- .check(status.is(204))
- ).exec((s: Session) => {
- s.removeAttribute("__scimUserId")
- }
-
- )
-
- }
-
-}
@@ -0,0 +1 @@
+client_id=vmc&scope=read&credentials={"username":"marissa","password":"koala"}&redirect_uri=uri:oauth:token&response_type=token
Oops, something went wrong.

0 comments on commit 5a49b3f

Please sign in to comment.