Created
May 1, 2014 08:41
-
-
Save js1972/11447197 to your computer and use it in GitHub Desktop.
Basic Auth check in groovy for SoapUI.
When using a SOAP Mock in SoapUI there is no standard way to check the authentication provided by the caller. This script can be added to your mock in the "OnRequest Script" section and allows you to check for the correct credentials.
If you test this from SoapUI as well then you need to set the Authenticat…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.eviware.soapui.support.types.StringToStringsMap | |
def authSucceeded = false | |
// get the request headers | |
StringToStringsMap headers = mockRequest.getRequestHeaders() | |
headers.each { | |
if (it.key.equals("Authorization")) { | |
String content = it.value | |
String[] contentArray = content.split() | |
if (contentArray.length == 2) { | |
// decode the auth string | |
String base64Enc = contentArray[1].minus("]") | |
byte[] decoded = base64Enc.decodeBase64() | |
String s = new String(decoded) | |
log.info "Given credentials are: " + s | |
def credentials = s.split(":") | |
assert credentials[0].equals("jscott") | |
assert credentials[1].equals("zzz") | |
log.info "Mock service authenticated for credentials: " + s | |
authSucceeded = true | |
} | |
} | |
} | |
assert authSucceeded == true |
On what level do you copy/paste credentials???
Style=Header this only its fetching,is thereany way to get the Style=Template values
Perfect! Thank you!
Good! Thank you mate!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Exactly what i was looking for! Thank you! Copy/Paste edit credentials - Done!