Example #1
0
    def test_add_api_superuser_to_project_logs_error(self):
        auth.api_client_set().AndRaise(RuntimeError('catch me'))
        self.app.logger.exception(IsA(basestring), 'PID', IsA(RuntimeError))

        self.mox.ReplayAll()
        with self.app.test_request_context():
            auth.add_api_superuser_to_project('PID')
Example #2
0
    def test_add_api_superuser_to_project_logs_error(self):
        auth.api_client_set().AndRaise(RuntimeError('catch me'))
        self.app.logger.exception(IsA(basestring), 'PID', IsA(RuntimeError))

        self.mox.ReplayAll()
        with self.app.test_request_context():
            auth.add_api_superuser_to_project('PID')
Example #3
0
    def test_api_cs_for_project_denied_at_last(self):
        auth._client_set('test_admin', 'test_p@ssw0rd',
                         tenant_id='PID') \
                .AndRaise(Unauthorized('denied'))
        auth.add_api_superuser_to_project('PID')
        auth._client_set('test_admin', 'test_p@ssw0rd',
                         tenant_id='PID') \
                .AndReturn('FAKE_CS')
        auth.admin_role_id('FAKE_CS').AndReturn(None)

        self.mox.ReplayAll()
        with self.app.test_request_context():
            self.assertRaises(RuntimeError, auth.api_client_set, 'PID')
Example #4
0
    def test_api_cs_for_project_denied_at_last(self):
        auth._client_set('test_admin', 'test_p@ssw0rd',
                         tenant_id='PID') \
                .AndRaise(Unauthorized('denied'))
        auth.add_api_superuser_to_project('PID')
        auth._client_set('test_admin', 'test_p@ssw0rd',
                         tenant_id='PID') \
                .AndReturn('FAKE_CS')
        auth.admin_role_id('FAKE_CS').AndReturn(None)

        self.mox.ReplayAll()
        with self.app.test_request_context():
            self.assertRaises(RuntimeError, auth.api_client_set, 'PID')
Example #5
0
    def test_add_api_superuser_to_project_works(self):
        tcs = self._fake_client_set_factory()
        tcs.http_client.access['user'] = {
            'id': 'API_SU_UID',
            'roles': [ { 'id': 'AR_ID', 'name': 'admin' } ]
        }

        auth.api_client_set().AndReturn(tcs)
        tcs.identity_admin.roles.add_user_role('API_SU_UID', 'AR_ID', 'PID')

        self.mox.ReplayAll()
        with self.app.test_request_context():
            auth.add_api_superuser_to_project('PID')
Example #6
0
    def test_api_cs_for_project_denied_at_first(self):
        auth._client_set('test_admin', 'test_p@ssw0rd',
                         tenant_id='PID') \
                .AndRaise(Unauthorized('denied'))
        auth.add_api_superuser_to_project('PID')
        auth._client_set('test_admin', 'test_p@ssw0rd',
                         tenant_id='PID') \
                .AndReturn('FAKE_CS')
        auth.admin_role_id('FAKE_CS').AndReturn('ROLE')

        self.mox.ReplayAll()
        with self.app.test_request_context():
            cs = auth.api_client_set('PID')
        self.assertEquals(cs, 'FAKE_CS')
Example #7
0
    def test_api_cs_for_project_denied_at_first(self):
        auth._client_set('test_admin', 'test_p@ssw0rd',
                         tenant_id='PID') \
                .AndRaise(Unauthorized('denied'))
        auth.add_api_superuser_to_project('PID')
        auth._client_set('test_admin', 'test_p@ssw0rd',
                         tenant_id='PID') \
                .AndReturn('FAKE_CS')
        auth.admin_role_id('FAKE_CS').AndReturn('ROLE')

        self.mox.ReplayAll()
        with self.app.test_request_context():
            cs = auth.api_client_set('PID')
        self.assertEquals(cs, 'FAKE_CS')
Example #8
0
    def test_add_api_superuser_to_project_works(self):
        tcs = self._fake_client_set_factory()
        tcs.http_client.access['user'] = {
            'id': 'API_SU_UID',
            'roles': [{
                'id': 'AR_ID',
                'name': 'admin'
            }]
        }

        auth.api_client_set().AndReturn(tcs)
        tcs.identity_admin.roles.add_user_role('API_SU_UID', 'AR_ID', 'PID')

        self.mox.ReplayAll()
        with self.app.test_request_context():
            auth.add_api_superuser_to_project('PID')