Is there a way to run this "JWT-generator/http("ConnectToken")" once per user? Now it is ran once and then the same JWT is used every time.
import java.io.File
import java.util.Properties
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import config.Config._
import util._
import headers.Headers._
object GetTokenRequest extends JwtGeneratorRSA{
val get_token = {
val feeder = csv("data/TestDataTest.csv")
val current = new File(".").getCanonicalPath
System.out.println("Current dir:" + current)
val currentDir = System.getProperty("user.dir")
System.out.println("Current dir using System:" + currentDir)
val props = new Properties
props.put("issuer","cfa9c8fb-8dd6-4d7c-b142-786c3d774f64");
props.put("audience",app_url+"/connect/token");
props.put("resource","testRes");
props.put("consumer_org","testOrg");
props.put("scope","openid profile helseid://scopes/identity/pid");
props.put("token.endpoint",app_url + "/connect/token");
props.put("keystore.file",current+"/src/test/resources/data/cfa9c8fb-8dd6-4d7c-b142-786c3d774f64.p12");
props.put("keystore.password","AYiPf1mZYOY60XV0tCuPIFk9UaGiOg1K");
props.put("keystore.alias","");
props.put("keystore.alias.password","");
// Generate Json Web Token
val jwt = makeJwt(props)
println("J W T : ")
println(jwt)
http("ConnectToken")
.post(app_url + "/connect/token")
.headers(headers_0)
.formParam("grant_type", "${grant_type}")
.formParam("client_assertion", jwt)
.formParam("client_assertion_type", "urn:ietf:params:oauth:client-assertion-type:jwt-bearer")
.formParam("client_id", "${client_id}")
.formParam("scope", "${scope}")
.check(regex("access_token\":\"(.*?)\"").saveAs("access_token"))
}
}
The execution is like this:
.exec(GetTokenRequest.get_token)
I want each user to run the JWT generator. I guess the problem lies in this part:
http("ConnectToken") .post(app_url + "/connect/token") .headers(headers_0) .formParam("grant_type", "${grant_type}") .formParam("client_assertion", jwt) ...
I see several problems here. One of the problems is that you mix different logics and actions in one method. You need to decompose it into small pieces.
Now let's get back to the problem itself. In order for the token to be loaded for each user, just place it in the feeder. You even have an example in your code:
"${grant_type}"
"${client_id}"
just do it now for
"${jwt}"