Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_rstr_empty_string(self):
with six.assertRaisesRegex(self, Exception, 'Received empty RSTR response body.') as cm:
wstrustResponse = WSTrustResponse(_call_context, '', WSTrustVersion.WSTRUST13)
wstrustResponse.parse()
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
def test_rstr_unparseable_xml(self):
with six.assertRaisesRegex(self, Exception, 'Failed to parse RSTR in to DOM'):
wstrustResponse = WSTrustResponse(_call_context, '
def test_token_parsing_happy_path(self):
wstrustFile = open(os.path.join(os.getcwd(), 'tests', 'wstrust', 'RSTR.xml'))
wstrustResponse = WSTrustResponse(_call_context, wstrustFile.read(), WSTrustVersion.WSTRUST13)
wstrustResponse.parse()
wstrustFile.close()
self.assertEqual(wstrustResponse.token_type, 'urn:oasis:names:tc:SAML:1.0:assertion', 'TokenType did not match expected value: ' + wstrustResponse.token_type)
attribute_values = ET.fromstring(wstrustResponse.token).findall('saml:AttributeStatement/saml:Attribute/saml:AttributeValue', _namespaces)
self.assertEqual(2, len(attribute_values))
self.assertEqual('1TIu064jGEmmf+hnI+F0Jg==', attribute_values[1].text)