JKelsey
14 years agoOccasional Contributor
[Res] How to set Authorization header value dynamically
I'm testing a REST web service. I have a soapUI project with hundreds of test steps and dozens of test cases. We're about to add support for authentication. Once that is in, each of my REST requests needs to send an Authorization header where the value is calculated based on a string made up of the URI of the request and a timestamp that is then encrypted.
I'm looking for ideas on how I can add the authorization header with the least amount of pain.
I suspect I need to modify each of the test steps with a REST request to at least add the Authorization header.
Once each test step has the Authorization header, how do I populate it with the correct value each time the test step runs?
I thought about having a DataGen step at the start of each testcase, with a script property in READ mode that calculates the header value and encrypts it. Then I can use property expansion in each REST request test step that reads the header value. Will that work? If so, how does the DataGen script get the URI for the test step that is trying to read the header value?
In pseudo code I thought my DataGen script would look something like this
step = figure out which step is running (how??)
uri = get the request uri for the test step (how?? what about steps that don't have a uri, like property transfers??)
timestamp = now
rawHeader = uri + now // concatenate the uri and the timestamp together
authorization = encrypt (rawHeader)
Even better would be if I could have a global script somewhere that can be called by each REST test step to get the authorization value for that request. I'm not sure if that is possible.
Thanks.
I'm looking for ideas on how I can add the authorization header with the least amount of pain.
I suspect I need to modify each of the test steps with a REST request to at least add the Authorization header.
Once each test step has the Authorization header, how do I populate it with the correct value each time the test step runs?
I thought about having a DataGen step at the start of each testcase, with a script property in READ mode that calculates the header value and encrypts it. Then I can use property expansion in each REST request test step that reads the header value. Will that work? If so, how does the DataGen script get the URI for the test step that is trying to read the header value?
In pseudo code I thought my DataGen script would look something like this
step = figure out which step is running (how??)
uri = get the request uri for the test step (how?? what about steps that don't have a uri, like property transfers??)
timestamp = now
rawHeader = uri + now // concatenate the uri and the timestamp together
authorization = encrypt (rawHeader)
Even better would be if I could have a global script somewhere that can be called by each REST test step to get the authorization value for that request. I'm not sure if that is possible.
Thanks.