Forum Discussion
Based on some stackoverflow answers a possible solution is splitting the WWW-Authenticate header by comma, then put each key value pair in a map collection.
https://stackoverflow.com/questions/45361721/groovy-digest-authentication
See if this groovy script sets the property values that you want.
import org.apache.commons.codec.digest.DigestUtils def user = "sip:381117508016@ims.telekomsrbija.com"; def pass = "bzlops16"; def request = testRunner.testCase.testSteps["HTTP_Get_FirstHit"].testRequest; def headerauth = request.response.responseHeaders["WWW-Authenticate"][0]; def values = headerauth.split(',(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)', 0); def map = [:]; values.eachWithIndex {it, index -> def pair = values[index].tokenize('=') map.put(pair[0].trim(), pair[1].trim().replace('"','')) } def realm = map["Digest realm"]; def qop = map["qop"]; def nonce = map["nonce"]; def opaque = map["opaque"]; def method = request.getMethod() def uri = request.getEndpoint(); def response = md5(user, realm, pass, method, uri, nonce); log.info response def md5(user, realm, pass, method, String uri, nonce) { def A1 = DigestUtils.md5Hex ("$user:$realm:$pass") def A2 = DigestUtils.md5Hex ("$method:$uri") DigestUtils.md5Hex ("$A1:$nonce:$A2") } def init = testRunner.testCase.getTestStepByName( "Properties" ); init.setPropertyValue( "realm", realm); init.setPropertyValue( "nonce", nonce); init.setPropertyValue( "opaque", opaque); init.setPropertyValue( "response", response); init.setPropertyValue( "uri", uri);
- asherhancong8 years agoNew Contributor
Hi Paul,
Thx a lot for your kind and detailed reply. The groovy script your shared is working fine and digest response is successfully calculated.
But when it comes to send the request again with Authorization Header, the server keeps replying 401 with new nonce challenge. the updated project and Wireshark trace are as attached.
- PaulMS8 years agoSuper Contributor
A couple of things to add.
One property value was missing in the groovy script
init.setPropertyValue( "qop", qop);
Close bracket was missing after ${Properties#opaque" in the request Authorization header
The request Raw tab is an easy way to check the header to see if anything is missing
Related Content
- 3 months ago
- 7 years ago
Recent Discussions
- 15 years ago