The API’s I am testing have a complex authorization scheme that involves generating an MD5 value based on the payload, requestType and uri of the service. Values in that payload and uri will need to be parameterized so I have that defined in an external file and am feeding it in. Simple enough. The problem I am having is in the exec statement when I am generating the new session with the computed values, the ${} variables that are defined in the feeder document are not getting escaped. Unfortunately the SignatureCalculator that generates the Authorization header requires the payload, requestType and uri to be passed in so I need to have those ${} values resolved in that exec.
Take this code for example. This is a simple Get call that has no payload. The problem I am having is resolving the ${userid}, which is defined in get_user_data_request.csv:
object GetUserDataRequest extends BaseRequest {
val getUserDataRequestScenario = scenario(“Get User Data Request”)
.feed(csv(“get_user_data_request.csv”).random)
.exec(session => { val payload : String = “”
val requestType : String = “GET”
val uri : String = “/services/userids/${userid}”
val newSession : Session = session.set(“payload”, payload)
.set(“requestType”, requestType)
.set(“uri”, uri)
.set(“signatureCalculator”, new CustomSignatureCalculator(payload, requestType, uri, MainController.environment))
.set(“contentMd5”, Authorization.getMD5MessageDigest(payload))
newSession})
.exec(http(“get_user_data_request”)
.get("${uri}")
.headers(baseHeader)
.header(HttpHeaderNames.ContentMD5, “${contentMd5}”)
.signatureCalculator("${signatureCalculator}")
.check(status.is(200), bodyString.transform(string => string).saveAs(“responseBody”)))
.exec(session => { println(session(“responseBody”).as[String])
session})
}
I need to replace the value of ${userid} with a value coming in from an external CSV file from the feed statement. The way it is written now the request that is being made is not replacing the ${userid} parameter with it’s proper value and the request looks like this:
http://servername/services/userids/${userid}
when it should look like this:
http://servername/services/userids/szaluk
I need that replacement to happen in the exec where I am generating the new session as I need that uri and payload to have any ${} values replaced before I can generate the MD5 and Signature Calculator.
How can I get the ${userid} value replaced in the exec statement? Is this possible?
Sorry for the rambling. This is difficult to explain in a short email.
Thanks,
Steve