예제 #1
0
파일: test_auth.py 프로젝트: thudoan/otter
    def test_impersonate_user(self):
        """
        impersonate_user makes an impersonation request to the RAX-AUTH
        impersonation endpoint.
        """
        response = mock.Mock(code=200)
        response_body = {
            'access': {
                'token': {'id': '1111111111'}
            }
        }
        self.treq.json_content.return_value = succeed(response_body)
        self.treq.post.return_value = succeed(response)

        d = impersonate_user('http://identity/v2.0', 'auth-token', 'foo')

        self.assertEqual(self.successResultOf(d), response_body)

        self.treq.post.assert_called_once_with(
            'http://identity/v2.0/RAX-AUTH/impersonation-tokens',
            SameJSON({
                'RAX-AUTH:impersonation': {
                    'user': {'username': '******'},
                    'expire-in-seconds': 10800
                }
            }),
            headers=expected_headers)
예제 #2
0
파일: test_auth.py 프로젝트: thudoan/otter
    def test_impersonate_user_expire_in_seconds(self):
        """
        impersonate_user sends it's expire_in keyword argument as the
        expire-in-seconds option.
        """
        response = mock.Mock(code=200)
        response_body = {
            'access': {
                'token': {'id': '1111111111'}
            }
        }
        self.treq.json_content.return_value = succeed(response_body)
        self.treq.post.return_value = succeed(response)

        d = impersonate_user('http://identity/v2.0', 'auth-token', 'foo',
                             expire_in=60)

        self.assertEqual(self.successResultOf(d), response_body)

        self.treq.post.assert_called_once_with(
            'http://identity/v2.0/RAX-AUTH/impersonation-tokens',
            SameJSON({
                'RAX-AUTH:impersonation': {
                    'user': {'username': '******'},
                    'expire-in-seconds': 60
                }
            }),
            headers=expected_headers)
예제 #3
0
파일: test_auth.py 프로젝트: sharwell/otter
    def test_impersonate_user(self):
        """
        impersonate_user makes an impersonation request to the RAX-AUTH
        impersonation endpoint.
        """
        response = mock.Mock(code=200)
        response_body = {'access': {'token': {'id': '1111111111'}}}
        self.treq.json_content.return_value = succeed(response_body)
        self.treq.post.return_value = succeed(response)

        d = impersonate_user('http://identity/v2.0', 'auth-token', 'foo')

        self.assertEqual(self.successResultOf(d), response_body)

        self.treq.post.assert_called_once_with(
            'http://identity/v2.0/RAX-AUTH/impersonation-tokens',
            SameJSON({
                'RAX-AUTH:impersonation': {
                    'user': {
                        'username': '******'
                    },
                    'expire-in-seconds': 10800
                }
            }),
            headers=expected_headers)
예제 #4
0
파일: test_auth.py 프로젝트: sharwell/otter
    def test_impersonate_user_expire_in_seconds(self):
        """
        impersonate_user sends it's expire_in keyword argument as the
        expire-in-seconds option.
        """
        response = mock.Mock(code=200)
        response_body = {'access': {'token': {'id': '1111111111'}}}
        self.treq.json_content.return_value = succeed(response_body)
        self.treq.post.return_value = succeed(response)

        d = impersonate_user('http://identity/v2.0',
                             'auth-token',
                             'foo',
                             expire_in=60)

        self.assertEqual(self.successResultOf(d), response_body)

        self.treq.post.assert_called_once_with(
            'http://identity/v2.0/RAX-AUTH/impersonation-tokens',
            SameJSON({
                'RAX-AUTH:impersonation': {
                    'user': {
                        'username': '******'
                    },
                    'expire-in-seconds': 60
                }
            }),
            headers=expected_headers)
예제 #5
0
파일: test_auth.py 프로젝트: thudoan/otter
    def test_impersonate_user_propogates_errors(self):
        """
        impersonate_user propagates API errors.
        """
        response = mock.Mock(code=500)
        self.treq.content.return_value = succeed('error_body')
        self.treq.post.return_value = succeed(response)

        d = impersonate_user('http://identity/v2.0', 'auth-token', 'foo',
                             expire_in=60)
        failure = self.failureResultOf(d)

        self.assertTrue(failure.check(RequestError))
        real_failure = failure.value.reason

        self.assertTrue(real_failure.check(APIError))
        self.assertEqual(real_failure.value.code, 500)
        self.assertEqual(real_failure.value.body, 'error_body')
예제 #6
0
파일: test_auth.py 프로젝트: sharwell/otter
    def test_impersonate_user_propogates_errors(self):
        """
        impersonate_user propagates API errors.
        """
        response = mock.Mock(code=500)
        self.treq.content.return_value = succeed('error_body')
        self.treq.post.return_value = succeed(response)

        d = impersonate_user('http://identity/v2.0',
                             'auth-token',
                             'foo',
                             expire_in=60)
        failure = self.failureResultOf(d)

        self.assertTrue(failure.check(RequestError))
        real_failure = failure.value.reason

        self.assertTrue(real_failure.check(APIError))
        self.assertEqual(real_failure.value.code, 500)
        self.assertEqual(real_failure.value.body, 'error_body')