示例#1
0
    def setUp(self):
        """
        Shortcut by mocking all the helper functions that do IO.
        """
        self.authenticate_user = patch(self, 'otter.auth.authenticate_user')

        self.authenticate_user.side_effect = lambda *a, **kw: succeed({
            'access': {
                'token': {
                    'id': 'auth-token'
                },
                'serviceCatalog': fake_service_catalog
            }
        })

        self.url = 'http://identity/v2.0'
        self.user = '******'
        self.password = '******'
        self.st = SingleTenantAuthenticator(self.user, self.password, self.url)
        self.log = mock_log()
示例#2
0
    def setUp(self):
        """
        Shortcut by mocking all the helper functions that do IO.
        """
        self.authenticate_user = patch(
            self, 'otter.auth.authenticate_user')

        self.authenticate_user.side_effect = lambda *a, **kw: succeed(
            {'access': {'token': {'id': 'auth-token'},
                        'serviceCatalog': fake_service_catalog}})

        self.url = 'http://identity/v2.0'
        self.user = '******'
        self.password = '******'
        self.st = SingleTenantAuthenticator(self.user, self.password, self.url)
        self.log = mock_log()
示例#3
0
class SingleTenantAuthenticatorTests(SynchronousTestCase):
    """
    Tests for the end-to-end single tenant workflow.
    """
    def setUp(self):
        """
        Shortcut by mocking all the helper functions that do IO.
        """
        self.authenticate_user = patch(
            self, 'otter.auth.authenticate_user')

        self.authenticate_user.side_effect = lambda *a, **kw: succeed(
            {'access': {'token': {'id': 'auth-token'},
                        'serviceCatalog': fake_service_catalog}})

        self.url = 'http://identity/v2.0'
        self.user = '******'
        self.password = '******'
        self.st = SingleTenantAuthenticator(self.user, self.password, self.url)
        self.log = mock_log()

    def test_verifyObject(self):
        """
        ImpersonatingAuthenticator provides the IAuthenticator interface.
        """
        verifyObject(IAuthenticator, self.st)

    def test_authenticate_user_as_specified_tenant(self):
        """
        authenticate_tenant authenticates as the given tenant
        """
        self.successResultOf(self.st.authenticate_tenant('111111'))
        self.authenticate_user.assert_called_once_with(
            self.url, self.user, self.password, tenant_id='111111', log=None)

        self.authenticate_user.reset_mock()

        self.successResultOf(
            self.st.authenticate_tenant('111111', log=self.log))

        self.authenticate_user.assert_called_once_with(
            self.url, self.user, self.password, tenant_id='111111',
            log=self.log)
        self.log.msg.assert_called_once_with(
            'Authenticating as new tenant', auth_tenant_id='111111')

    def test_authenticate_user_returns_endpoint_list(self):
        """
        authenticate_tenant returns the impersonation token and the endpoint
        list.
        """
        result = self.successResultOf(self.st.authenticate_tenant('1111111'))
        self.assertEqual(result, ('auth-token', fake_service_catalog))

    def test_authenticate_tenant_propagates_user_list_errors(self):
        """
        authenticate_tenant propagates errors from user_for_tenant
        """
        self.authenticate_user.side_effect = lambda *a, **kw: fail(
            UpstreamError(Failure(APIError(500, '500')), 'identity', 'o'))

        f = self.failureResultOf(self.st.authenticate_tenant('111111'),
                                 UpstreamError)
        self.assertEqual(f.value.reason.value.code, 500)
示例#4
0
class SingleTenantAuthenticatorTests(SynchronousTestCase):
    """
    Tests for the end-to-end single tenant workflow.
    """
    def setUp(self):
        """
        Shortcut by mocking all the helper functions that do IO.
        """
        self.authenticate_user = patch(self, 'otter.auth.authenticate_user')

        self.authenticate_user.side_effect = lambda *a, **kw: succeed({
            'access': {
                'token': {
                    'id': 'auth-token'
                },
                'serviceCatalog': fake_service_catalog
            }
        })

        self.url = 'http://identity/v2.0'
        self.user = '******'
        self.password = '******'
        self.st = SingleTenantAuthenticator(self.user, self.password, self.url)
        self.log = mock_log()

    def test_verifyObject(self):
        """
        ImpersonatingAuthenticator provides the IAuthenticator interface.
        """
        verifyObject(IAuthenticator, self.st)

    def test_authenticate_user_as_specified_tenant(self):
        """
        authenticate_tenant authenticates as the given tenant
        """
        self.successResultOf(self.st.authenticate_tenant('111111'))
        self.authenticate_user.assert_called_once_with(self.url,
                                                       self.user,
                                                       self.password,
                                                       tenant_id='111111',
                                                       log=None)

        self.authenticate_user.reset_mock()

        self.successResultOf(
            self.st.authenticate_tenant('111111', log=self.log))

        self.authenticate_user.assert_called_once_with(self.url,
                                                       self.user,
                                                       self.password,
                                                       tenant_id='111111',
                                                       log=self.log)
        self.log.msg.assert_called_once_with('Authenticating as new tenant',
                                             auth_tenant_id='111111')

    def test_authenticate_user_returns_endpoint_list(self):
        """
        authenticate_tenant returns the impersonation token and the endpoint
        list.
        """
        result = self.successResultOf(self.st.authenticate_tenant('1111111'))
        self.assertEqual(result, ('auth-token', fake_service_catalog))

    def test_authenticate_tenant_propagates_user_list_errors(self):
        """
        authenticate_tenant propagates errors from user_for_tenant
        """
        self.authenticate_user.side_effect = lambda *a, **kw: fail(
            UpstreamError(Failure(APIError(500, '500')), 'identity', 'o'))

        f = self.failureResultOf(self.st.authenticate_tenant('111111'),
                                 UpstreamError)
        self.assertEqual(f.value.reason.value.code, 500)