def test_parse_error_happy_path(self):
        errorResponse = '''
            <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
              <s:Header>
               <a:Action s:mustUnderstand="1">http://www.w3.org/2005/08/addressing/soap/fault</a:Action>
               <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
                 <u:Timestamp u:Id="_0">
                 <u:Created>2013-07-30T00:32:21.989Z</u:Created>
                 <u:Expires>2013-07-30T00:37:21.989Z</u:Expires>
                 </u:Timestamp>
               </o:Security>
               </s:Header>
             <s:Body>
               <s:Fault>
                 <s:Code>
                   <s:Value>s:Sender</s:Value>
                   <s:Subcode>
                   <s:Value xmlns:a="http://docs.oasis-open.org/ws-sx/ws-trust/200512">a:RequestFailed</s:Value>
                   </s:Subcode>
                 </s:Code>
                 <s:Reason>
                 <s:Text xml:lang="en-US">MSIS3127: The specified request failed.</s:Text>
                 </s:Reason>
               </s:Fault>
            </s:Body>
            </s:Envelope>'''

        wstrustResponse = WSTrustResponse(_call_context, errorResponse, WSTrustVersion.WSTRUST13)

        exception_text = "Server returned error in RSTR - ErrorCode: RequestFailed : FaultMessage: MSIS3127: The specified request failed"
        with six.assertRaisesRegex(self, Exception, exception_text) as cm:
            wstrustResponse.parse()
 def test_rstr_unparseable_xml(self):
     with six.assertRaisesRegex(self, Exception,
                                'Failed to parse RSTR in to DOM'):
         wstrustResponse = WSTrustResponse(
             _call_context, '<This is not parseable as an RSTR',
             WSTrustVersion.WSTRUST13)
         wstrustResponse.parse()
    def test_parse_error_happy_path(self):
        errorResponse = '''
            <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
              <s:Header>
               <a:Action s:mustUnderstand="1">http://www.w3.org/2005/08/addressing/soap/fault</a:Action>
               <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
                 <u:Timestamp u:Id="_0">
                 <u:Created>2013-07-30T00:32:21.989Z</u:Created>
                 <u:Expires>2013-07-30T00:37:21.989Z</u:Expires>
                 </u:Timestamp>
               </o:Security>
               </s:Header>
             <s:Body>
               <s:Fault>
                 <s:Code>
                   <s:Value>s:Sender</s:Value>
                   <s:Subcode>
                   <s:Value xmlns:a="http://docs.oasis-open.org/ws-sx/ws-trust/200512">a:RequestFailed</s:Value>
                   </s:Subcode>
                 </s:Code>
                 <s:Reason>
                 <s:Text xml:lang="en-US">MSIS3127: The specified request failed.</s:Text>
                 </s:Reason>
               </s:Fault>
            </s:Body>
            </s:Envelope>'''

        wstrustResponse = WSTrustResponse(_call_context, errorResponse,
                                          WSTrustVersion.WSTRUST13)

        exception_text = "Server returned error in RSTR - ErrorCode: RequestFailed : FaultMessage: MSIS3127: The specified request failed"
        with six.assertRaisesRegex(self, Exception, exception_text) as cm:
            wstrustResponse.parse()
 def test_findall_content_for_real(self):
     with open(os.path.join(os.getcwd(), 'tests', 'wstrust', 'RSTR.xml')) as f:
         rstr = f.read()
     wstrustResponse = WSTrustResponse(_call_context, rstr, WSTrustVersion.WSTRUST13)
     wstrustResponse.parse()
     self.assertIn("<X509Data>", rstr)
     self.assertIn(b"<X509Data>", wstrustResponse.token)  # It is in bytes
    def test_token_parsing_happy_path(self):
        wstrustResponse = WSTrustResponse(_call_context, open(os.path.join(os.getcwd(), 'tests', 'wstrust', 'RSTR.xml')).read())
        wstrustResponse.parse()

        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)
示例#6
0
 def test_findall_content_for_real(self):
     with open(os.path.join(os.getcwd(), 'tests', 'wstrust',
                            'RSTR.xml')) as f:
         rstr = f.read()
     wstrustResponse = WSTrustResponse(_call_context, rstr,
                                       WSTrustVersion.WSTRUST13)
     wstrustResponse.parse()
     self.assertIn("<X509Data>", rstr)
     self.assertIn(b"<X509Data>", wstrustResponse.token)  # It is in bytes
    def create_wstrust_request_stub(self, err, tokenType, noToken=None):
        wstrust_response = WSTrustResponse(cp['callContext'],'')

        wstrust_response.parse = mock.MagicMock()
        if not noToken:
            wstrust_response.token = 'This is a stubbed token'
            wstrust_response._tokenType = tokenType

        wstrust_request = WSTrustRequest(cp['callContext'], '', '')

        def side_effect (username, password, callback):
            callback(err, wstrust_response)
        wstrust_request.acquire_token = mock.MagicMock(side_effect=side_effect)

        return wstrust_request
    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 = b'This is a stubbed token'
            wstrust_response.token_type = tokenType

        wstrust_request = WSTrustRequest(cp['callContext'], '', '', '')

        def side_effect (username, password):
            if err:
                raise err
            return wstrust_response
        wstrust_request.acquire_token = mock.MagicMock(side_effect=side_effect)

        return wstrust_request
    def test_token_parsing_happy_path(self):
        wstrustResponse = WSTrustResponse(
            _call_context,
            open(os.path.join(os.getcwd(), 'tests', 'wstrust',
                              'RSTR.xml')).read())
        wstrustResponse.parse()

        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)
示例#10
0
    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 = b'This is a stubbed token'
            wstrust_response.token_type = tokenType

        wstrust_request = WSTrustRequest(cp['callContext'], '', '', '')

        def side_effect (username, password):
            if err:
                raise err
            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, '<This is not parseable as an RSTR', WSTrustVersion.WSTRUST13)
         wstrustResponse.parse()
 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 test_rstr_unparseable_xml(self):
     with self.assertRaisesRegexp(Exception,
                                  'Failed to parse RSTR in to DOM'):
         wstrustResponse = WSTrustResponse(
             _call_context, '<This is not parseable as an RSTR')
         wstrustResponse.parse()
 def test_rstr_unparseable_xml(self):
     with self.assertRaisesRegexp(Exception, 'Failed to parse RSTR in to DOM'):
         wstrustResponse = WSTrustResponse(_call_context, '<This is not parseable as an RSTR')
         wstrustResponse.parse()
 def test_rstr_empty_string(self):
     with self.assertRaisesRegexp(Exception, 'Received empty RSTR response body.') as cm:
         wstrustResponse = WSTrustResponse(_call_context, '')
         wstrustResponse.parse()
 def test_rstr_none(self):
     with six.assertRaisesRegex(self, Exception,
                                'Received empty RSTR response body.') as cm:
         wstrustResponse = WSTrustResponse(_call_context, None,
                                           WSTrustVersion.WSTRUST13)
         wstrustResponse.parse()
 def test_rstr_none(self):
     with self.assertRaisesRegexp(
             Exception, 'Received empty RSTR response body.') as cm:
         wstrustResponse = WSTrustResponse(_call_context, None)
         wstrustResponse.parse()