-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsoapui-basic-authentication-script.txt
More file actions
32 lines (31 loc) · 1.1 KB
/
soapui-basic-authentication-script.txt
File metadata and controls
32 lines (31 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import com.eviware.soapui.support.types.StringToStringsMap;
// Get the global properties
def globalProperties = com.eviware.soapui.model.propertyexpansion.PropertyExpansionUtils.globalProperties;
String httpUsername = globalProperties['httpUsername'].value;
String httpPassword = globalProperties['httpPassword'].value;
// Setup error results
def errorResult = {
def response = new com.eviware.soapui.impl.wsdl.mock.WsdlMockResult( mockRequest )
mockRequest.httpResponse.status = 401
mockRequest.httpResponse.writer << "ERROR"
return response
}
// Get the Request Headers
def auth = mockRequest.requestHeaders["Authorization"]
if ( auth ) {
def value = auth[0]
if ( value.startsWith("Basic ")) {
value = value.substring( 6 )
def up = new String(value.decodeBase64()).split(":")
def user = up[0]
def pass = up[1]
log.info "$user $pass"
if( !(user == httpUsername && pass == httpPassword) ) {
return errorResult.call()
}
} else {
return errorResult.call()
}
} else {
return errorResult.call()
}