コード例 #1
0
 def wrapper(self, *args, **kwargs):
     if CONF.api_authenticate and self.table in [
             'pods', 'projects', 'testcases', 'scenarios'
     ]:
         testapi_id = self.get_secure_cookie(constants.TESTAPI_ID)
         if not testapi_id:
             raises.Unauthorized(message.not_login())
         user_info = yield dbapi.db_find_one('users', {'user': testapi_id})
         if not user_info:
             raises.Unauthorized(message.not_lfid())
         if method.__name__ == "_create":
             kwargs['owner'] = testapi_id
         if self.table in ['projects']:
             query = kwargs.get('query')
             if type(query) is not dict:
                 query_data = query()
             else:
                 if self.json_args is None:
                     query_data = query
                 else:
                     query_data = self.json_args
             group = "opnfv-gerrit-" + query_data['name'] + "-submitters"
             if group not in user_info['groups']:
                 raises.Unauthorized(message.no_permission())
     ret = yield gen.coroutine(method)(self, *args, **kwargs)
     raise gen.Return(ret)
コード例 #2
0
ファイル: check.py プロジェクト: xudan2189/releng
 def wrapper(self, *args, **kwargs):
     if self.table in ['pods']:
         testapi_id = self.get_secure_cookie(constants.TESTAPI_ID)
         if not testapi_id:
             raises.Unauthorized(message.not_login())
         user_info = yield dbapi.db_find_one('users', {'user': testapi_id})
         if not user_info:
             raises.Unauthorized(message.not_lfid())
         kwargs['owner'] = testapi_id
     ret = yield gen.coroutine(method)(self, *args, **kwargs)
     raise gen.Return(ret)
コード例 #3
0
ファイル: test_pod.py プロジェクト: xudan2189/releng
class TestPodCreate(TestPodBase):
    @executor.create(httplib.BAD_REQUEST, message.not_login())
    def test_notlogin(self):
        return self.req_d

    @executor.mock_invalid_lfid()
    @executor.create(httplib.BAD_REQUEST, message.not_lfid())
    def test_invalidLfid(self):
        return self.req_d

    @executor.mock_valid_lfid()
    @executor.create(httplib.BAD_REQUEST, message.no_body())
    def test_withoutBody(self):
        return None

    @executor.mock_valid_lfid()
    @executor.create(httplib.BAD_REQUEST, message.missing('name'))
    def test_emptyName(self):
        return pod_models.PodCreateRequest('')

    @executor.mock_valid_lfid()
    @executor.create(httplib.BAD_REQUEST, message.missing('name'))
    def test_noneName(self):
        return pod_models.PodCreateRequest(None)

    @executor.mock_valid_lfid()
    @executor.create(httplib.OK, 'assert_create_body')
    def test_success(self):
        return self.req_d

    @executor.mock_valid_lfid()
    @executor.create(httplib.FORBIDDEN, message.exist_base)
    def test_alreadyExist(self):
        fake_pymongo.pods.insert(self.pod_d.format())
        return self.req_d

    @executor.mock_valid_lfid()
    @executor.create(httplib.FORBIDDEN, message.exist_base)
    def test_alreadyExistCaseInsensitive(self):
        fake_pymongo.pods.insert(self.pod_d.format())
        self.req_d.name = self.req_d.name.upper()
        return self.req_d