Example #1
0
 def get_one(self, test_id, key):
     """Get value for key from test run metadata."""
     role = api_utils.get_user_role(test_id)
     if role in (const.ROLE_FOUNDATION, const.ROLE_OWNER):
         return db.get_test_meta_key(test_id, key)
     elif role in (const.ROLE_USER) and key in self.rw_access_keys:
         return db.get_test_meta_key(test_id, key)
     pecan.abort(403)
Example #2
0
    def put(self, test_id, **kw):
        """Update a test result."""
        test_info = {'id': test_id}
        is_foundation_admin = api_utils.check_user_is_foundation_admin()

        if 'product_version_id' in kw:
            test = db.get_test(test_id)
            if test['verification_status'] == const.TEST_VERIFIED:
                pecan.abort(
                    403, 'Can not update product_version_id for a '
                    'verified test run.')

            if kw['product_version_id']:
                # Verify that the user is a member of the product's vendor.
                version = db.get_product_version(kw['product_version_id'],
                                                 allowed_keys=['product_id'])
                is_vendor_admin = (api_utils.check_user_is_product_admin(
                    version['product_id']))
            else:
                # No product vendor to check membership for, so just set
                # is_vendor_admin to True.
                is_vendor_admin = True
                kw['product_version_id'] = None

            if not is_vendor_admin and not is_foundation_admin:
                pecan.abort(403, 'Forbidden.')

            test_info['product_version_id'] = kw['product_version_id']

        if 'verification_status' in kw:
            if not is_foundation_admin:
                pecan.abort(
                    403, 'You do not have permission to change a '
                    'verification status.')

            if kw['verification_status'] not in (0, 1):
                pecan.abort(
                    400, 'Invalid verification_status value: %d' %
                    kw['verification_status'])

            # Check pre-conditions are met to mark a test verified.
            if (kw['verification_status'] == 1
                    and not (db.get_test_meta_key(test_id, 'target')
                             and db.get_test_meta_key(test_id, 'guideline')
                             and db.get_test_meta_key(test_id,
                                                      const.SHARED_TEST_RUN))):

                pecan.abort(
                    403, 'In order to mark a test verified, the '
                    'test must be shared and have been '
                    'associated to a guideline and target '
                    'program.')

            test_info['verification_status'] = kw['verification_status']

        test = db.update_test(test_info)
        pecan.response.status = 201
        return test
Example #3
0
def check_user(test_id):
    """Check that user has access to shared test run."""
    test_owner = db.get_test_meta_key(test_id, const.USER)
    if not test_owner:
        return True
    elif db.get_test_meta_key(test_id, const.SHARED_TEST_RUN):
        return True
    else:
        return check_owner(test_id)
Example #4
0
def _check_user(test_id):
    """Check that user has access to shared test run."""
    test_pubkey = db.get_test_meta_key(test_id, const.PUBLIC_KEY)
    if not test_pubkey:
        return True
    elif db.get_test_meta_key(test_id, const.SHARED_TEST_RUN):
        return True
    else:
        return _check_owner(test_id)
Example #5
0
def _check_owner(test_id):
    """Check that user has access to specified test run as owner."""
    if not is_authenticated():
        return False
    test_pubkey = db.get_test_meta_key(test_id, const.PUBLIC_KEY)
    return test_pubkey in [' '.join((pk['format'], pk['pubkey']))
                           for pk in get_user_public_keys()]
Example #6
0
def check_owner(test_id):
    """Check that user has access to specified test run as owner."""
    if not is_authenticated():
        return False

    test = db.get_test(test_id)
    # If the test is owned by a product.
    if test.get('product_version_id'):
        version = db.get_product_version(test['product_version_id'])
        return check_user_is_product_admin(version['product_id'])
    # Otherwise, check the user ownership.
    else:
        user = db.get_test_meta_key(test_id, const.USER)
        return user and user == get_user_id()
Example #7
0
def _check_owner(test_id):
    """Check that user has access to specified test run as owner."""
    if not is_authenticated():
        return False

    # Check that test has pubkey attached that equals to user key
    test_pubkey = db.get_test_meta_key(test_id, const.PUBLIC_KEY)
    pubkeys = [' '.join((pk['format'], pk['pubkey']))
               for pk in get_user_public_keys()]
    if test_pubkey in pubkeys:
        return True

    # Check that test has link to cloud that belongs to user
    test = db.get_test(test_id)
    cloud = db.get_cloud(test['cpid'])
    if cloud and cloud['openid'] == get_user_id():
        return True

    return False
Example #8
0
 def get_one(self, test_id, key):
     """Get value for key from test run metadata."""
     return db.get_test_meta_key(test_id, key)