예제 #1
0
class TestTokenUpdateProject(TestToken):
    def setUp(self):
        super(TestTokenUpdateProject, self).setUp()
        self.req_d = project_models.ProjectCreateRequest('vping')
        fake_pymongo.tokens.insert({"access_token": "12345"})
        self.basePath = '/api/v1/projects'
        self.headers['X-Auth-Token'] = '12345'
        self.create_d()

    @executor.update(httplib.FORBIDDEN, message.invalid_token())
    def test_projectUpdateTokenIvalid(self):
        self.headers['X-Auth-Token'] = '1234'
        req = project_models.ProjectUpdateRequest('newName', 'new description')
        return req, self.req_d.name

    @executor.update(httplib.UNAUTHORIZED, message.unauthorized())
    def test_projectUpdateTokenUnauthorized(self):
        self.headers.pop('X-Auth-Token')
        req = project_models.ProjectUpdateRequest('newName', 'new description')
        return req, self.req_d.name

    @executor.update(httplib.OK, '_update_success')
    def test_projectUpdateTokenSuccess(self):
        req = project_models.ProjectUpdateRequest('newName', 'new description')
        return req, self.req_d.name

    def _update_success(self, request, body):
        self.assertIn(request.name, body)
예제 #2
0
class TestTokenCreateResult(test_result.TestResultBase):
    def get_app(self):
        from opnfv_testapi.router import url_mappings
        return web.Application(
            url_mappings.mappings,
            db=fake_pymongo,
            debug=True,
            auth=True
        )

    def setUp(self):
        super(TestTokenCreateResult, self).setUp()
        fake_pymongo.tokens.insert({"access_token": "12345"})

    @executor.create(httplib.FORBIDDEN, message.invalid_token())
    def test_resultCreateTokenInvalid(self):
        self.headers['X-Auth-Token'] = '1234'
        return self.req_d

    @executor.create(httplib.UNAUTHORIZED, message.unauthorized())
    def test_resultCreateTokenUnauthorized(self):
        if 'X-Auth-Token' in self.headers:
            self.headers.pop('X-Auth-Token')
        return self.req_d

    @executor.create(httplib.OK, '_create_success')
    def test_resultCreateTokenSuccess(self):
        self.headers['X-Auth-Token'] = '12345'
        return self.req_d

    def _create_success(self, body):
        self.assertIn('CreateResponse', str(type(body)))
예제 #3
0
class TestTokenCreateProject(TestToken):
    def setUp(self):
        super(TestTokenCreateProject, self).setUp()
        self.req_d = project_models.ProjectCreateRequest('vping')
        fake_pymongo.tokens.insert({"access_token": "12345"})
        self.basePath = '/api/v1/projects'

    @executor.create(httplib.FORBIDDEN, message.invalid_token())
    def test_projectCreateTokenInvalid(self):
        self.headers['X-Auth-Token'] = '1234'
        return self.req_d

    @executor.create(httplib.UNAUTHORIZED, message.unauthorized())
    def test_projectCreateTokenUnauthorized(self):
        if 'X-Auth-Token' in self.headers:
            self.headers.pop('X-Auth-Token')
        return self.req_d

    @executor.create(httplib.OK, '_create_success')
    def test_projectCreateTokenSuccess(self):
        self.headers['X-Auth-Token'] = '12345'
        return self.req_d

    def _create_success(self, body):
        self.assertIn('CreateResponse', str(type(body)))
예제 #4
0
 def test_projectDeleteTokenIvalid(self):
     self.headers['X-Auth-Token'] = '12345'
     self.create_d()
     self.headers['X-Auth-Token'] = '1234'
     code, body = self.delete(self.req_d.name)
     self.assertEqual(code, httplib.FORBIDDEN)
     self.assertIn(message.invalid_token(), body)
예제 #5
0
 def test_projectUpdateTokenIvalid(self):
     self.headers['X-Auth-Token'] = '12345'
     self.create_d()
     code, body = self.get(self.req_d.name)
     self.headers['X-Auth-Token'] = '1234'
     req = project_models.ProjectUpdateRequest('newName', 'new description')
     code, body = self.update(req, self.req_d.name)
     self.assertEqual(code, httplib.FORBIDDEN)
     self.assertIn(message.invalid_token(), body)
예제 #6
0
 def post(self):
     input_token = self.request.headers._dict['Token']
     mc = memcache.Client(['127.0.0.1:11211'], debug=0)
     token = mc.get("token")
     if not token or not input_token == token:
         raises.Unauthorized(message.invalid_token())
     mc.set("token", '')
     resp = {'Message': 'You have been logged out successfully.'}
     self.finish_request(resp)
예제 #7
0
파일: handlers.py 프로젝트: boucherv/releng
 def wrapper(self, *args, **kwargs):
     if self.auth:
         try:
             token = self.request.headers['X-Auth-Token']
         except KeyError:
             raises.Unauthorized(message.unauthorized())
         query = {'access_token': token}
         check = yield self._eval_db_find_one(query, 'tokens')
         if not check:
             raises.Forbidden(message.invalid_token())
     ret = yield gen.coroutine(method)(self, *args, **kwargs)
     raise gen.Return(ret)
예제 #8
0
    def post(self):
        """
            @description: create a test
            @param body: test to be created
            @type body: L{TestCreateRequest}
            @in body: body
            @rtype: L{CreateResponse}
            @return 200: test is created.
            @raise 404: pod/project/testcase not exist
            @raise 400: body/pod_name/project_name/case_name not provided
        """
        mc = memcache.Client(['127.0.0.1:11211'], debug=0)
        token = mc.get("token")
        openid = self.request.headers._dict['Openid']
        if openid:
            self.json_args['owner'] = openid
        input_token = self.request.headers._dict['Token']
        if not token or not input_token == token:
            raises.Unauthorized(message.invalid_token())

        self._post()
예제 #9
0
 def post(self):
     """
         @description: upload and create a test result
         @param body: result to be created
         @type body: L{ResultCreateRequest}
         @in body: body
         @rtype: L{CreateResponse}
         @return 200: result is created.
         @raise 404: pod/project/testcase not exist
         @raise 400: body/pod_name/project_name/case_name not provided
     """
     mc = memcache.Client(['127.0.0.1:11211'], debug=0)
     token = mc.get("token")
     input_token = self.request.headers._dict['Token']
     if not token or not input_token == token:
         raises.Unauthorized(message.invalid_token())
     file_array = self.request.files.get('file', None)
     if file_array is None:
         msg = 'Please upload a file.'
         self.finish_request({'code': 403, 'msg': msg})
         return
     fileinfo = file_array[0]
     try:
         tar_in = tarfile.open(fileobj=io.BytesIO(fileinfo['body']),
                               mode="r:gz")
     except tarfile.ReadError:
         msg = 'Please upload a valid gzip file.'
         self.finish_request({'code': 403, 'msg': msg})
         return
     try:
         # Deal with results that are in the 'root' of the tar
         # file, instead of in results/
         missing_results_dir = ''
         tar_files = tar_in.getnames()
         if 'results/results.json' not in tar_files:
             missing_results_dir = '/results'
             results = tar_in.extractfile('results.json').read()
         else:
             results = tar_in.extractfile('results/results.json').read()
     except KeyError:
         msg = 'Uploaded results must contain at least one passing test.'
         self.finish_request({'code': 403, 'msg': msg})
         return
     # results = results.split('\n')
     result_ids = []
     version = ''
     vnf_type = None
     vnf_checksum = None
     try:
         self.json_args = json.loads(results).copy()
         openid = self.get_secure_cookie(auth_const.OPENID)
         if openid:
             self.json_args['owner'] = openid
         if self.is_onap:
             self.json_args['is_onap'] = 'true'
             vnf_type = self.json_args['vnf_type']
             vnf_checksum = self.json_args['vnf_checksum']
         # the result files used in the first release of OVP did not
         # specify an OVP version
         if (self.json_args['version'] == 'master'
                 or self.json_args['version'] == 'unknown'):
             version = '2018.01'
         else:
             version = self.json_args['version']
         build_tag = self.json_args['build_tag']
         _id = yield self._inner_create()
         result_ids.append(str(_id))
     except ValueError:
         msg = 'Uploaded results don''t appear to contain a '\
               'valid results.json file!'
         self.finish_request({'code': 403, 'msg': msg})
         return
     # Build a test id from the build_tag, where this field takes a couple
     # of different formats between Dovetail NFVI testing and VNF testing.
     # If a valid UUID isn't part of the build_tag, we will generate one
     # here.
     test_id_match = re.search('[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-'
                               '[0-9A-F]{4}-[0-9A-F]{12}', build_tag)
     if not test_id_match:
         print('test_id doesn''t look to be a valid UUID, generating a '
               'new one...')
         test_id = str(uuid.uuid4())
     else:
         test_id = test_id_match.group(1)
     log_path = '/home/testapi/logs/%s%s' % (test_id, missing_results_dir)
     tar_in.extractall(log_path)
     log_filename = "/home/testapi/logs/log_%s.tar.gz" % (test_id)
     with open(log_filename, "wb") as tar_out:
         tar_out.write(fileinfo['body'])
     resp = {'id': test_id, 'results': result_ids, 'version': version}
     if vnf_type:
         resp['vnf_type'] = vnf_type
         resp['vnf_checksum'] = vnf_checksum
     self.finish_request(resp)