Beispiel #1
0
    def test_happy_path(self):
        username = '******'
        password = '******'
        appliesTo = 'test_appliesTo'
        templateRST = open(os.path.join(os.getcwd(), 'tests', 'wstrust', 'RST.xml'), mode='r').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)

        # 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()

        def callback():
            pass

        request.acquire_token(username, password, callback)
    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
Beispiel #4
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
Beispiel #5
0
    def test_fail_to_parse_rstr(self):
        username = '******'
        password = '******'
        appliesTo = 'test_appliesTo'
        templateRST = open(os.path.join(os.getcwd(), 'tests', 'wstrust', 'RST.xml'), mode='r').read()
        rst = templateRST \
            .replace('%USERNAME%', username) \
            .replace('%PASSWORD%', password) \
            .replace('%APPLIES_TO%', appliesTo) \
            .replace('%WSTRUST_ENDPOINT%', wstrustEndpoint)

        httpretty.register_uri(method=httpretty.POST, uri=wstrustEndpoint, status=200, body='fake response body')

        def callback(err, token):
            self.assertEqual(err.args[0], 'Failed to parse RSTR in to DOM')

        request = WSTrustRequest(_call_context, wstrustEndpoint, appliesTo)
        request.acquire_token(username, password, callback)
    def test_fail_to_parse_rstr(self):
        username = '******'
        password = '******'
        appliesTo = 'test_appliesTo'
        templateFile = open(os.path.join(os.getcwd(), 'tests', 'wstrust', 'RST.xml'), mode='r')
        templateRST = templateFile.read()
        templateFile.close()
        rst = templateRST \
            .replace('%USERNAME%', username) \
            .replace('%PASSWORD%', password) \
            .replace('%APPLIES_TO%', appliesTo) \
            .replace('%WSTRUST_ENDPOINT%', wstrustEndpoint)

        httpretty.register_uri(method=httpretty.POST, uri=wstrustEndpoint, status=200, body='fake response body')

        request = WSTrustRequest(_call_context, wstrustEndpoint, appliesTo, WSTrustVersion.WSTRUST13)
        with self.assertRaises(Exception):
            request.acquire_token(username, password)
Beispiel #7
0
    def test_fail_to_parse_rstr(self):
        username = '******'
        password = '******'
        appliesTo = 'test_appliesTo'
        templateFile = open(os.path.join(os.getcwd(), 'tests', 'wstrust',
                                         'RST.xml'),
                            mode='r')
        templateRST = templateFile.read()
        templateFile.close()
        rst = templateRST \
            .replace('%USERNAME%', username) \
            .replace('%PASSWORD%', password) \
            .replace('%APPLIES_TO%', appliesTo) \
            .replace('%WSTRUST_ENDPOINT%', wstrustEndpoint)

        httpretty.register_uri(method=httpretty.POST,
                               uri=wstrustEndpoint,
                               status=200,
                               body='fake response body')

        request = WSTrustRequest(_call_context, wstrustEndpoint, appliesTo,
                                 WSTrustVersion.WSTRUST13)
        with self.assertRaises(Exception):
            request.acquire_token(username, password)