示例#1
0
    def test_failed_delete_role_bad_role(self, mKCC):
        ctxMgr = mKCC.return_value.__enter__.return_value

        request = self.makeRequest(delete='/' + version + '/sso/user-role/test/test')
        response = BossUserRole.as_view()(request, 'test', 'test')

        self.assertEqual(response.status_code, 403)
示例#2
0
    def test_failed_delete_role_bad_role(self, mKCC):
        ctxMgr = mKCC.return_value.__enter__.return_value

        request = self.makeRequest(delete='/' + version + '/sso/user-role/test/test')
        response = BossUserRole.as_view()(request, 'test', 'test')

        self.assertEqual(response.status_code, 403)
示例#3
0
    def test_failed_get_role_bad_role(self, mKCC):
        ctxMgr = mKCC.return_value.__enter__.return_value
        ctxMgr.get_realm_roles.return_value = [{'name': 'test'},{'name': 'admin'}]

        request = self.makeRequest(get='/' + version + '/sso/user-role/test/test')
        response = BossUserRole.as_view()(request, 'test', 'test')

        self.assertEqual(response.status_code, 403)
示例#4
0
    def test_failed_delete_role(self, mKCC):
        ctxMgr = mKCC.return_value.__enter__.return_value
        ctxMgr.remove_role_from_user.side_effect = raise_error

        request = self.makeRequest(delete='/' + version + '/sso/user-role/test/resource-manager')
        response = BossUserRole.as_view()(request, 'test', 'resource-manager')

        self.assertEqual(response.status_code, 500)
示例#5
0
    def test_failed_get_role(self, mKCC):
        ctxMgr = mKCC.return_value.__enter__.return_value
        ctxMgr.get_realm_roles.side_effect = raise_error

        request = self.makeRequest(get='/' + version + '/sso/user-role/test')
        response = BossUserRole.as_view()(request, 'test')

        self.assertEqual(response.status_code, 500)
示例#6
0
    def test_failed_post_role(self, mKCC):
        ctxMgr = mKCC.return_value.__enter__.return_value
        ctxMgr.map_role_to_user.side_effect = raise_error

        request = self.makeRequest(post='/v0.6/sso/user-role/test/admin')
        response = BossUserRole.as_view()(request, 'test', 'admin')

        self.assertEqual(response.status_code, 500)
示例#7
0
    def test_failed_get_role(self, mKCC):
        ctxMgr = mKCC.return_value.__enter__.return_value
        ctxMgr.get_realm_roles.side_effect = raise_error

        request = self.makeRequest(get='/' + version + '/sso/user-role/test')
        response = BossUserRole.as_view()(request, 'test')

        self.assertEqual(response.status_code, 500)
示例#8
0
    def test_failed_get_role_bad_role(self, mKCC):
        ctxMgr = mKCC.return_value.__enter__.return_value
        ctxMgr.get_realm_roles.return_value = [{'name': 'test'},{'name': 'admin'}]

        request = self.makeRequest(get='/' + version + '/sso/user-role/test/test')
        response = BossUserRole.as_view()(request, 'test', 'test')

        self.assertEqual(response.status_code, 403)
示例#9
0
    def test_failed_post_admin_role(self, mKCC):
        """The admin roles is not allowed to be assigned through the API"""
        ctxMgr = mKCC.return_value.__enter__.return_value

        request = self.makeRequest(post='/' + version + '/sso/user-role/test/admin')
        response = BossUserRole.as_view()(request, 'test', 'admin')

        self.assertEqual(response.status_code, 403)
示例#10
0
    def test_failed_post_admin_role(self, mKCC):
        """The admin roles is not allowed to be assigned through the API"""
        ctxMgr = mKCC.return_value.__enter__.return_value

        request = self.makeRequest(post='/' + version + '/sso/user-role/test/admin')
        response = BossUserRole.as_view()(request, 'test', 'admin')

        self.assertEqual(response.status_code, 403)
示例#11
0
    def test_failed_delete_role(self, mKCC):
        ctxMgr = mKCC.return_value.__enter__.return_value
        ctxMgr.remove_role_from_user.side_effect = raise_error

        request = self.makeRequest(delete='/' + version + '/sso/user-role/test/resource-manager')
        response = BossUserRole.as_view()(request, 'test', 'resource-manager')

        self.assertEqual(response.status_code, 500)
示例#12
0
    def test_delete_role(self, mKCC):
        ctxMgr = mKCC.return_value.__enter__.return_value

        request = self.makeRequest(delete='/' + version + '/sso/user-role/test/resource-manager')
        response = BossUserRole.as_view()(request, 'test', 'resource-manager')

        self.assertEqual(response.status_code, 204)
        self.assertIsNone(response.data)

        call = mock.call.remove_role_from_user('test', 'resource-manager')
        self.assertEqual(ctxMgr.mock_calls, [call])
示例#13
0
    def test_post_role(self, mKCC):
        ctxMgr = mKCC.return_value.__enter__.return_value

        request = self.makeRequest(post='/v0.6/sso/user-role/test/admin')
        response = BossUserRole.as_view()(request, 'test', 'admin')

        self.assertEqual(response.status_code, 201)
        self.assertIsNone(response.data)

        call = mock.call.map_role_to_user('test', 'admin')
        self.assertEqual(ctxMgr.mock_calls, [call])
示例#14
0
    def test_post_role(self, mKCC):
        ctxMgr = mKCC.return_value.__enter__.return_value

        request = self.makeRequest(post='/' + version + '/sso/user-role/test/resource-manager')
        response = BossUserRole.as_view()(request, 'test', 'resource-manager')

        self.assertEqual(response.status_code, 201)
        self.assertIsNone(response.data)

        call = mock.call.map_role_to_user('test', 'resource-manager')
        self.assertEqual(ctxMgr.mock_calls, [call])
示例#15
0
    def test_get_role_with_role1(self, mKCC):
        ctxMgr = mKCC.return_value.__enter__.return_value
        ctxMgr.get_realm_roles.return_value = [{'name': 'test'},{'name': 'admin'}]

        request = self.makeRequest(get='/' + version + '/sso/user-role/test/admin')
        response = BossUserRole.as_view()(request, 'test', role_name='admin')

        self.assertEqual(response.status_code, 200)

        self.assertEqual(response.data, True)

        call = mock.call.get_realm_roles('test')
        self.assertEqual(ctxMgr.mock_calls, [call])
示例#16
0
    def test_get_role_with_role1(self, mKCC):
        ctxMgr = mKCC.return_value.__enter__.return_value
        ctxMgr.get_realm_roles.return_value = [{'name': 'test'},{'name': 'admin'}]

        request = self.makeRequest(get='/' + version + '/sso/user-role/test/admin')
        response = BossUserRole.as_view()(request, 'test', role_name='admin')

        self.assertEqual(response.status_code, 200)

        self.assertEqual(response.data, True)

        call = mock.call.get_realm_roles('test')
        self.assertEqual(ctxMgr.mock_calls, [call])
示例#17
0
    def test_get_role_no_role(self, mKCC):
        ctxMgr = mKCC.return_value.__enter__.return_value
        ctxMgr.get_realm_roles.return_value = [{'name': 'test'},{'name': 'admin'}]

        request = self.makeRequest(get='/' + version + '/sso/user-role/test')
        response = BossUserRole.as_view()(request, 'test')

        self.assertEqual(response.status_code, 200)

        # Role 'test' will be filtered out by the view
        self.assertEqual(response.data, ['admin'])

        call = mock.call.get_realm_roles('test')
        self.assertEqual(ctxMgr.mock_calls, [call])
示例#18
0
    def test_get_role_no_role(self, mKCC):
        ctxMgr = mKCC.return_value.__enter__.return_value
        ctxMgr.get_realm_roles.return_value = [{'name': 'test'},{'name': 'admin'}]

        request = self.makeRequest(get='/' + version + '/sso/user-role/test')
        response = BossUserRole.as_view()(request, 'test')

        self.assertEqual(response.status_code, 200)

        # Role 'test' will be filtered out by the view
        self.assertEqual(response.data, ['admin'])

        call = mock.call.get_realm_roles('test')
        self.assertEqual(ctxMgr.mock_calls, [call])