Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create_wstrust_request_stub(self, err, tokenType, noToken=None):
wstrust_response = WSTrustResponse(cp['callContext'],'')
wstrust_response.error_code = err
wstrust_response.parse = mock.MagicMock()
if not noToken:
wstrust_response.token = 'This is a stubbed token'
wstrust_response._tokenType = tokenType
wstrust_response.token_type = tokenType
wstrust_request = WSTrustRequest(cp['callContext'], '', '')
def side_effect (username, password):
if err:
raise AdalError("Throwing error from Unit test")
return wstrust_response
wstrust_request.acquire_token = mock.MagicMock(side_effect=side_effect)
return wstrust_request
@httpretty.activate
def test_happy_path(self):
username = 'test_username'
password = 'test_password'
appliesTo = 'test_appliesTo'
wstrustFile = open(os.path.join(os.getcwd(), 'tests', 'wstrust', 'RST.xml'), mode='r')
templateRST = wstrustFile.read()
rst = templateRST \
.replace('%USERNAME%', username) \
.replace('%PASSWORD%', password) \
.replace('%APPLIES_TO%', appliesTo) \
.replace('%WSTRUST_ENDPOINT%', wstrustEndpoint)
#rstRequest = setupUpOutgoingRSTCompare(rst)
request = WSTrustRequest(_call_context, wstrustEndpoint, appliesTo, WSTrustVersion.WSTRUST13)
# TODO: handle rstr should be mocked out to prevent handling here.
# TODO: setupUpOutgoingRSTCompare. Use this to get messageid, created, expires, etc comparisons.
httpretty.register_uri(method=httpretty.POST, uri=wstrustEndpoint, status=200, body='')
request._handle_rstr =mock.MagicMock()
request.acquire_token(username, password)
wstrustFile.close()
def _create_wstrust_request(self, wstrust_endpoint, applies_to, wstrust_endpoint_version):
return wstrust_request.WSTrustRequest(self._call_context, wstrust_endpoint,
applies_to, wstrust_endpoint_version)
@staticmethod
def _populate_rst_username_password(template, username, password):
password = WSTrustRequest._escape_password(password)
return template.replace(_USERNAME_PLACEHOLDER, username).replace(_PASSWORD_PLACEHOLDER, password)
if self._wstrust_endpoint_version == WSTrustVersion.WSTRUST2005:
soap_action = 'http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue'
rst_trust_namespace = 'http://schemas.xmlsoap.org/ws/2005/02/trust'
key_type = 'http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey'
request_type = 'http://schemas.xmlsoap.org/ws/2005/02/trust/Issue'
rst_template = ("".format(schema_location) +
"" +
"{}".format(soap_action) +
"urn:uuid:{}".format(message_id) +
"" +
"http://www.w3.org/2005/08/addressing/anonymous" +
"" +
"{}".format(self._wstrust_endpoint_url) +
WSTrustRequest._build_security_header() +
"" +
"" +
"".format(rst_trust_namespace) +
"" +
"" +
"{}".format(self._applies_to) +
"" +
"" +
"{}".format(key_type) +
"{}".format(request_type) +
"" +
"" +
"")
self._log.debug('Created RST: \n %(rst_template)s',
{"rst_template": rst_template})
"" +
"".format(rst_trust_namespace) +
"" +
"" +
"{}".format(self._applies_to) +
"" +
"" +
"{}".format(key_type) +
"{}".format(request_type) +
"" +
"" +
"")
self._log.debug('Created RST: \n %(rst_template)s',
{"rst_template": rst_template})
return WSTrustRequest._populate_rst_username_password(rst_template, username, password)