/
ScimComponents.scala
57 lines (50 loc) · 1.71 KB
/
ScimComponents.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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 = {
clientCredentialsAccessTokenRequest(
username = "scim",
password = "scimsecret",
client_id = "scim",
scope = "write password").insertChain(
chain.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")
})
}
}