2013-11-06 22:56:31 +00:00
|
|
|
import json
|
2015-10-02 18:01:12 +00:00
|
|
|
import hashlib
|
2013-11-06 22:56:31 +00:00
|
|
|
|
|
|
|
from flask import url_for
|
2013-11-07 22:10:57 +00:00
|
|
|
from base64 import b64encode
|
2013-11-06 22:56:31 +00:00
|
|
|
|
2014-03-18 20:48:09 +00:00
|
|
|
|
2013-11-07 22:10:57 +00:00
|
|
|
NO_REPO = None
|
2015-10-02 18:01:12 +00:00
|
|
|
PUBLIC = 'public'
|
|
|
|
PUBLIC_REPO_NAME = 'publicrepo'
|
|
|
|
PUBLIC_REPO = PUBLIC + '/' + PUBLIC_REPO_NAME
|
|
|
|
|
|
|
|
PRIVATE = 'devtable'
|
|
|
|
PRIVATE_REPO_NAME = 'shared'
|
|
|
|
PRIVATE_REPO = PRIVATE + '/' + PRIVATE_REPO_NAME
|
2013-11-06 22:56:31 +00:00
|
|
|
|
2013-11-08 03:43:43 +00:00
|
|
|
ORG = 'buynlarge'
|
2013-11-06 22:56:31 +00:00
|
|
|
ORG_REPO = ORG + '/orgrepo'
|
2016-08-04 20:23:09 +00:00
|
|
|
ANOTHER_ORG_REPO = ORG + '/anotherorgrepo'
|
|
|
|
NEW_ORG_REPO = ORG + '/neworgrepo'
|
|
|
|
|
2015-10-02 18:01:12 +00:00
|
|
|
ORG_REPO_NAME = 'orgrepo'
|
2013-11-06 22:56:31 +00:00
|
|
|
ORG_READERS = 'readers'
|
|
|
|
ORG_OWNER = 'devtable'
|
2013-11-07 04:21:12 +00:00
|
|
|
ORG_OWNERS = 'owners'
|
|
|
|
ORG_READERS = 'readers'
|
|
|
|
|
2015-10-02 18:01:12 +00:00
|
|
|
FAKE_MANIFEST = 'unknown_tag'
|
2018-06-01 21:06:43 +00:00
|
|
|
FAKE_DIGEST = 'sha256:' + hashlib.sha256('fake').hexdigest()
|
|
|
|
FAKE_IMAGE_ID = 'fake-image'
|
|
|
|
FAKE_UPLOAD_ID = 'fake-upload'
|
|
|
|
FAKE_TAG_NAME = 'fake-tag'
|
|
|
|
FAKE_USERNAME = 'fakeuser'
|
|
|
|
FAKE_TOKEN = 'fake-token'
|
|
|
|
FAKE_WEBHOOK = 'fake-webhook'
|
2013-11-07 04:21:12 +00:00
|
|
|
|
2014-02-26 18:45:49 +00:00
|
|
|
BUILD_UUID = '123'
|
|
|
|
TRIGGER_UUID = '123'
|
|
|
|
|
2013-11-07 04:21:12 +00:00
|
|
|
NEW_ORG_REPO_DETAILS = {
|
2018-06-01 21:06:43 +00:00
|
|
|
'repository': 'fake-repository',
|
2013-11-07 04:21:12 +00:00
|
|
|
'visibility': 'private',
|
|
|
|
'description': '',
|
|
|
|
'namespace': ORG,
|
|
|
|
}
|
2013-11-06 22:56:31 +00:00
|
|
|
|
2013-11-07 17:54:44 +00:00
|
|
|
NEW_USER_DETAILS = {
|
2013-12-02 21:16:45 +00:00
|
|
|
'username': 'bobby',
|
2013-11-07 17:54:44 +00:00
|
|
|
'password': 'password',
|
2013-12-02 21:16:45 +00:00
|
|
|
'email': 'bobby@tables.com',
|
2013-11-07 17:54:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SEND_RECOVERY_DETAILS = {
|
|
|
|
'email': 'jacob.moshenko@gmail.com',
|
|
|
|
}
|
|
|
|
|
|
|
|
SIGNIN_DETAILS = {
|
|
|
|
'username': 'devtable',
|
|
|
|
'password': 'password',
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE_DROP_DETAILS = {
|
|
|
|
'mimeType': 'application/zip',
|
|
|
|
}
|
|
|
|
|
|
|
|
CHANGE_PERMISSION_DETAILS = {
|
|
|
|
'role': 'admin',
|
|
|
|
}
|
|
|
|
|
|
|
|
CREATE_BUILD_DETAILS = {
|
2018-06-01 21:06:43 +00:00
|
|
|
'file_id': 'fake-file-id',
|
2013-11-07 17:54:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CHANGE_VISIBILITY_DETAILS = {
|
|
|
|
'visibility': 'public',
|
|
|
|
}
|
|
|
|
|
|
|
|
CREATE_TOKEN_DETAILS = {
|
|
|
|
'friendlyName': 'A new token',
|
|
|
|
}
|
|
|
|
|
|
|
|
UPDATE_REPO_DETAILS = {
|
|
|
|
'description': 'A new description',
|
|
|
|
}
|
|
|
|
|
2013-11-07 22:10:57 +00:00
|
|
|
|
2015-10-02 18:01:12 +00:00
|
|
|
class IndexV1TestSpec(object):
|
2013-11-07 22:10:57 +00:00
|
|
|
def __init__(self, url, sess_repo=None, anon_code=403, no_access_code=403,
|
2016-08-04 20:23:09 +00:00
|
|
|
read_code=200, creator_code=200, admin_code=200):
|
2013-11-07 22:10:57 +00:00
|
|
|
self._url = url
|
|
|
|
self._method = 'GET'
|
|
|
|
self._data = None
|
|
|
|
|
|
|
|
self.sess_repo = sess_repo
|
|
|
|
|
|
|
|
self.anon_code = anon_code
|
|
|
|
self.no_access_code = no_access_code
|
|
|
|
self.read_code = read_code
|
2016-08-04 20:23:09 +00:00
|
|
|
self.creator_code = creator_code
|
2013-11-07 22:10:57 +00:00
|
|
|
self.admin_code = admin_code
|
|
|
|
|
|
|
|
def gen_basic_auth(self, username, password):
|
|
|
|
encoded = b64encode('%s:%s' % (username, password))
|
|
|
|
return 'basic %s' % encoded
|
|
|
|
|
|
|
|
def set_data_from_obj(self, json_serializable):
|
|
|
|
self._data = json.dumps(json_serializable)
|
|
|
|
return self
|
|
|
|
|
|
|
|
def set_method(self, method):
|
|
|
|
self._method = method
|
|
|
|
return self
|
|
|
|
|
|
|
|
def get_client_args(self):
|
|
|
|
kwargs = {
|
|
|
|
'method': self._method
|
|
|
|
}
|
|
|
|
|
2015-10-02 18:01:12 +00:00
|
|
|
if self._data or self._method == 'POST' or self._method == 'PUT' or self._method == 'PATCH':
|
2013-11-07 22:10:57 +00:00
|
|
|
kwargs['data'] = self._data if self._data else '{}'
|
|
|
|
kwargs['content_type'] = 'application/json'
|
|
|
|
|
|
|
|
return self._url, kwargs
|
|
|
|
|
|
|
|
|
2015-10-02 18:01:12 +00:00
|
|
|
def build_v1_index_specs():
|
2013-11-07 22:10:57 +00:00
|
|
|
return [
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.get_image_layer', image_id=FAKE_IMAGE_ID),
|
2016-08-04 20:23:09 +00:00
|
|
|
PUBLIC_REPO, 404, 404, 404, 404, 404),
|
|
|
|
IndexV1TestSpec(url_for('v1.get_image_layer', image_id=FAKE_IMAGE_ID),
|
|
|
|
PRIVATE_REPO, 403, 403, 404, 403, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.get_image_layer', image_id=FAKE_IMAGE_ID),
|
2016-08-04 20:23:09 +00:00
|
|
|
ORG_REPO, 403, 403, 404, 403, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.get_image_layer', image_id=FAKE_IMAGE_ID),
|
2016-08-04 20:23:09 +00:00
|
|
|
ANOTHER_ORG_REPO, 403, 403, 403, 403, 404),
|
2013-11-07 22:10:57 +00:00
|
|
|
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.put_image_layer', image_id=FAKE_IMAGE_ID),
|
2016-08-04 20:23:09 +00:00
|
|
|
PUBLIC_REPO, 403, 403, 403, 403, 403).set_method('PUT'),
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.put_image_layer', image_id=FAKE_IMAGE_ID),
|
2016-08-04 20:23:09 +00:00
|
|
|
PRIVATE_REPO, 403, 403, 403, 403, 404).set_method('PUT'),
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.put_image_layer', image_id=FAKE_IMAGE_ID),
|
2016-08-04 20:23:09 +00:00
|
|
|
ORG_REPO, 403, 403, 403, 403, 404).set_method('PUT'),
|
|
|
|
IndexV1TestSpec(url_for('v1.put_image_layer', image_id=FAKE_IMAGE_ID),
|
|
|
|
ANOTHER_ORG_REPO, 403, 403, 403, 403, 404).set_method('PUT'),
|
2013-11-07 22:10:57 +00:00
|
|
|
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.put_image_checksum',
|
2014-01-31 00:06:26 +00:00
|
|
|
image_id=FAKE_IMAGE_ID),
|
2016-08-04 20:23:09 +00:00
|
|
|
PUBLIC_REPO, 403, 403, 403, 403, 403).set_method('PUT'),
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.put_image_checksum',
|
2014-01-31 00:06:26 +00:00
|
|
|
image_id=FAKE_IMAGE_ID),
|
2016-08-04 20:23:09 +00:00
|
|
|
PRIVATE_REPO, 403, 403, 403, 403, 400).set_method('PUT'),
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.put_image_checksum',
|
2014-01-31 00:06:26 +00:00
|
|
|
image_id=FAKE_IMAGE_ID),
|
2016-08-04 20:23:09 +00:00
|
|
|
ORG_REPO, 403, 403, 403, 403, 400).set_method('PUT'),
|
|
|
|
IndexV1TestSpec(url_for('v1.put_image_checksum',
|
|
|
|
image_id=FAKE_IMAGE_ID),
|
|
|
|
ANOTHER_ORG_REPO, 403, 403, 403, 403, 400).set_method('PUT'),
|
2013-11-07 22:10:57 +00:00
|
|
|
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.get_image_json', image_id=FAKE_IMAGE_ID),
|
2016-08-04 20:23:09 +00:00
|
|
|
PUBLIC_REPO, 404, 404, 404, 404, 404),
|
|
|
|
IndexV1TestSpec(url_for('v1.get_image_json', image_id=FAKE_IMAGE_ID),
|
|
|
|
PRIVATE_REPO, 403, 403, 404, 403, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.get_image_json', image_id=FAKE_IMAGE_ID),
|
2016-08-04 20:23:09 +00:00
|
|
|
ORG_REPO, 403, 403, 404, 403, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.get_image_json', image_id=FAKE_IMAGE_ID),
|
2016-08-04 20:23:09 +00:00
|
|
|
ANOTHER_ORG_REPO, 403, 403, 403, 403, 404),
|
2013-11-07 22:10:57 +00:00
|
|
|
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.get_image_ancestry', image_id=FAKE_IMAGE_ID),
|
2016-08-04 20:23:09 +00:00
|
|
|
PUBLIC_REPO, 404, 404, 404, 404, 404),
|
|
|
|
IndexV1TestSpec(url_for('v1.get_image_ancestry', image_id=FAKE_IMAGE_ID),
|
|
|
|
PRIVATE_REPO, 403, 403, 404, 403, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.get_image_ancestry', image_id=FAKE_IMAGE_ID),
|
2016-08-04 20:23:09 +00:00
|
|
|
ORG_REPO, 403, 403, 404, 403, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.get_image_ancestry', image_id=FAKE_IMAGE_ID),
|
2016-08-04 20:23:09 +00:00
|
|
|
ANOTHER_ORG_REPO, 403, 403, 403, 403, 404),
|
2013-11-07 22:10:57 +00:00
|
|
|
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.put_image_json', image_id=FAKE_IMAGE_ID),
|
2016-08-04 20:23:09 +00:00
|
|
|
PUBLIC_REPO, 403, 403, 403, 403, 403).set_method('PUT'),
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.put_image_json', image_id=FAKE_IMAGE_ID),
|
2016-08-04 20:23:09 +00:00
|
|
|
PRIVATE_REPO, 403, 403, 403, 403, 400).set_method('PUT'),
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.put_image_json', image_id=FAKE_IMAGE_ID),
|
2016-08-04 20:23:09 +00:00
|
|
|
ORG_REPO, 403, 403, 403, 403, 400).set_method('PUT'),
|
|
|
|
IndexV1TestSpec(url_for('v1.put_image_json', image_id=FAKE_IMAGE_ID),
|
|
|
|
ANOTHER_ORG_REPO, 403, 403, 403, 403, 400).set_method('PUT'),
|
2013-11-07 22:10:57 +00:00
|
|
|
|
2016-08-04 20:23:09 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.create_user'), NO_REPO, 400, 400, 400, 400,
|
2015-06-22 21:33:32 +00:00
|
|
|
400).set_method('POST').set_data_from_obj(NEW_USER_DETAILS),
|
2013-11-07 22:10:57 +00:00
|
|
|
|
2016-08-04 20:23:09 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.get_user'), NO_REPO, 404, 200, 200, 200, 200),
|
2013-11-07 22:10:57 +00:00
|
|
|
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.update_user', username=FAKE_USERNAME),
|
2016-08-04 20:23:09 +00:00
|
|
|
NO_REPO, 403, 403, 403, 403, 403).set_method('PUT'),
|
2013-11-07 22:10:57 +00:00
|
|
|
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.create_repository', repository=PUBLIC_REPO),
|
2016-08-04 20:23:09 +00:00
|
|
|
NO_REPO, 403, 403, 403, 403, 403).set_method('PUT'),
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.create_repository', repository=PRIVATE_REPO),
|
2016-08-04 20:23:09 +00:00
|
|
|
NO_REPO, 403, 403, 403, 403, 201).set_method('PUT'),
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.create_repository', repository=ORG_REPO),
|
2016-08-04 20:23:09 +00:00
|
|
|
NO_REPO, 403, 403, 403, 403, 201).set_method('PUT'),
|
|
|
|
IndexV1TestSpec(url_for('v1.create_repository', repository=ANOTHER_ORG_REPO),
|
|
|
|
NO_REPO, 403, 403, 403, 403, 201).set_method('PUT'),
|
|
|
|
IndexV1TestSpec(url_for('v1.create_repository', repository=NEW_ORG_REPO),
|
|
|
|
NO_REPO, 401, 403, 403, 201, 201).set_method('PUT'),
|
2013-11-07 22:10:57 +00:00
|
|
|
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.update_images', repository=PUBLIC_REPO),
|
2016-08-04 20:23:09 +00:00
|
|
|
NO_REPO, 403, 403, 403, 403, 403).set_method('PUT'),
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.update_images', repository=PRIVATE_REPO),
|
2016-08-04 20:23:09 +00:00
|
|
|
NO_REPO, 403, 403, 403, 403, 204).set_method('PUT'),
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.update_images', repository=ORG_REPO), NO_REPO,
|
2016-08-04 20:23:09 +00:00
|
|
|
403, 403, 403, 403, 204).set_method('PUT'),
|
|
|
|
IndexV1TestSpec(url_for('v1.update_images', repository=ANOTHER_ORG_REPO), NO_REPO,
|
|
|
|
403, 403, 403, 403, 204).set_method('PUT'),
|
2013-11-07 22:10:57 +00:00
|
|
|
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.get_repository_images',
|
2014-01-31 00:06:26 +00:00
|
|
|
repository=PUBLIC_REPO),
|
2016-08-04 20:23:09 +00:00
|
|
|
NO_REPO, 200, 200, 200, 200, 200),
|
|
|
|
IndexV1TestSpec(url_for('v1.get_repository_images',
|
|
|
|
repository=PRIVATE_REPO),
|
|
|
|
NO_REPO, 403, 403, 200, 403, 200),
|
|
|
|
IndexV1TestSpec(url_for('v1.get_repository_images',
|
|
|
|
repository=ORG_REPO),
|
|
|
|
NO_REPO, 403, 403, 200, 403, 200),
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.get_repository_images',
|
2016-08-04 20:23:09 +00:00
|
|
|
repository=ANOTHER_ORG_REPO),
|
|
|
|
NO_REPO, 403, 403, 403, 403, 200),
|
2013-11-07 22:10:57 +00:00
|
|
|
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.delete_repository_images',
|
2014-01-31 00:06:26 +00:00
|
|
|
repository=PUBLIC_REPO),
|
2016-08-04 20:23:09 +00:00
|
|
|
NO_REPO, 501, 501, 501, 501, 501).set_method('DELETE'),
|
2013-11-07 22:10:57 +00:00
|
|
|
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.put_repository_auth', repository=PUBLIC_REPO),
|
2016-08-04 20:23:09 +00:00
|
|
|
NO_REPO, 501, 501, 501, 501, 501).set_method('PUT'),
|
2013-11-07 22:10:57 +00:00
|
|
|
|
2016-08-04 20:23:09 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.get_search'), NO_REPO, 200, 200, 200, 200, 200),
|
2013-11-07 22:10:57 +00:00
|
|
|
|
2016-08-04 20:23:09 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.ping'), NO_REPO, 200, 200, 200, 200, 200),
|
2013-11-07 22:10:57 +00:00
|
|
|
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.get_tags', repository=PUBLIC_REPO), NO_REPO,
|
2016-08-04 20:23:09 +00:00
|
|
|
200, 200, 200, 200, 200),
|
|
|
|
IndexV1TestSpec(url_for('v1.get_tags', repository=PRIVATE_REPO), NO_REPO,
|
|
|
|
403, 403, 200, 403, 200),
|
|
|
|
IndexV1TestSpec(url_for('v1.get_tags', repository=ORG_REPO), NO_REPO,
|
|
|
|
403, 403, 200, 403, 200),
|
|
|
|
IndexV1TestSpec(url_for('v1.get_tags', repository=ANOTHER_ORG_REPO), NO_REPO,
|
|
|
|
403, 403, 403, 403, 200),
|
2013-11-07 22:10:57 +00:00
|
|
|
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.get_tag', repository=PUBLIC_REPO,
|
2016-08-04 20:23:09 +00:00
|
|
|
tag=FAKE_TAG_NAME), NO_REPO, 404, 404, 404, 404, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.get_tag', repository=PRIVATE_REPO,
|
2016-08-04 20:23:09 +00:00
|
|
|
tag=FAKE_TAG_NAME), NO_REPO, 403, 403, 404, 403, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.get_tag', repository=ORG_REPO,
|
2016-08-04 20:23:09 +00:00
|
|
|
tag=FAKE_TAG_NAME), NO_REPO, 403, 403, 404, 403, 404),
|
|
|
|
IndexV1TestSpec(url_for('v1.get_tag', repository=ANOTHER_ORG_REPO,
|
|
|
|
tag=FAKE_TAG_NAME), NO_REPO, 403, 403, 403, 403, 404),
|
2013-11-07 22:10:57 +00:00
|
|
|
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.put_tag', repository=PUBLIC_REPO,
|
2013-11-07 22:10:57 +00:00
|
|
|
tag=FAKE_TAG_NAME),
|
2016-08-04 20:23:09 +00:00
|
|
|
NO_REPO, 403, 403, 403, 403, 403).set_method('PUT'),
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.put_tag', repository=PRIVATE_REPO,
|
2013-11-07 22:10:57 +00:00
|
|
|
tag=FAKE_TAG_NAME),
|
2016-08-04 20:23:09 +00:00
|
|
|
NO_REPO, 403, 403, 403, 403, 400).set_method('PUT'),
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.put_tag', repository=ORG_REPO,
|
2014-01-31 00:06:26 +00:00
|
|
|
tag=FAKE_TAG_NAME),
|
2016-08-04 20:23:09 +00:00
|
|
|
NO_REPO, 403, 403, 403, 403, 400).set_method('PUT'),
|
|
|
|
IndexV1TestSpec(url_for('v1.put_tag', repository=ANOTHER_ORG_REPO,
|
|
|
|
tag=FAKE_TAG_NAME),
|
|
|
|
NO_REPO, 403, 403, 403, 403, 400).set_method('PUT'),
|
2013-11-07 22:10:57 +00:00
|
|
|
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.delete_tag', repository=PUBLIC_REPO,
|
2013-11-07 22:10:57 +00:00
|
|
|
tag=FAKE_TAG_NAME),
|
2016-08-04 20:23:09 +00:00
|
|
|
NO_REPO, 403, 403, 403, 403, 403).set_method('DELETE'),
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.delete_tag', repository=PRIVATE_REPO,
|
2013-11-07 22:10:57 +00:00
|
|
|
tag=FAKE_TAG_NAME),
|
2016-08-04 20:23:09 +00:00
|
|
|
NO_REPO, 403, 403, 403, 403, 400).set_method('DELETE'),
|
2015-10-02 18:01:12 +00:00
|
|
|
IndexV1TestSpec(url_for('v1.delete_tag', repository=ORG_REPO,
|
2013-11-07 22:10:57 +00:00
|
|
|
tag=FAKE_TAG_NAME),
|
2016-08-04 20:23:09 +00:00
|
|
|
NO_REPO, 403, 403, 403, 403, 400).set_method('DELETE'),
|
|
|
|
IndexV1TestSpec(url_for('v1.delete_tag', repository=ANOTHER_ORG_REPO,
|
|
|
|
tag=FAKE_TAG_NAME),
|
|
|
|
NO_REPO, 403, 403, 403, 403, 400).set_method('DELETE'),
|
2013-12-02 20:36:39 +00:00
|
|
|
]
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
class IndexV2TestSpec(object):
|
|
|
|
def __init__(self, index_name, method_name, repo_name, scope=None, **kwargs):
|
|
|
|
self.index_name = index_name
|
|
|
|
self.repo_name = repo_name
|
|
|
|
self.method_name = method_name
|
|
|
|
|
|
|
|
default_scope = 'push,pull' if method_name != 'GET' and method_name != 'HEAD' else 'pull'
|
|
|
|
self.scope = scope or default_scope
|
|
|
|
|
|
|
|
self.kwargs = kwargs
|
|
|
|
|
|
|
|
self.anon_code = 401
|
|
|
|
self.no_access_code = 403
|
|
|
|
self.read_code = 200
|
|
|
|
self.admin_code = 200
|
2016-08-04 20:23:09 +00:00
|
|
|
self.creator_code = 200
|
|
|
|
|
2015-10-02 18:01:12 +00:00
|
|
|
|
2016-08-04 20:23:09 +00:00
|
|
|
def request_status(self, anon_code=401, no_access_code=403, read_code=200, creator_code=200,
|
|
|
|
admin_code=200):
|
2015-10-02 18:01:12 +00:00
|
|
|
self.anon_code = anon_code
|
|
|
|
self.no_access_code = no_access_code
|
|
|
|
self.read_code = read_code
|
2016-08-04 20:23:09 +00:00
|
|
|
self.creator_code = creator_code
|
2015-10-02 18:01:12 +00:00
|
|
|
self.admin_code = admin_code
|
|
|
|
return self
|
|
|
|
|
|
|
|
def get_url(self):
|
2016-01-21 20:40:51 +00:00
|
|
|
return url_for(self.index_name, repository=self.repo_name, **self.kwargs)
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
def gen_basic_auth(self, username, password):
|
|
|
|
encoded = b64encode('%s:%s' % (username, password))
|
|
|
|
return 'basic %s' % encoded
|
|
|
|
|
|
|
|
def get_scope_string(self):
|
|
|
|
return 'repository:%s:%s' % (self.repo_name, self.scope)
|
|
|
|
|
|
|
|
|
|
|
|
def build_v2_index_specs():
|
|
|
|
return [
|
|
|
|
# v2.list_all_tags
|
|
|
|
IndexV2TestSpec('v2.list_all_tags', 'GET', PUBLIC_REPO).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(200, 200, 200, 200, 200),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
IndexV2TestSpec('v2.list_all_tags', 'GET', PRIVATE_REPO).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(401, 401, 200, 401, 200),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
IndexV2TestSpec('v2.list_all_tags', 'GET', ORG_REPO).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(401, 401, 200, 401, 200),
|
|
|
|
|
|
|
|
IndexV2TestSpec('v2.list_all_tags', 'GET', ANOTHER_ORG_REPO).
|
|
|
|
request_status(401, 401, 401, 401, 200),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
# v2.fetch_manifest_by_tagname
|
|
|
|
IndexV2TestSpec('v2.fetch_manifest_by_tagname', 'GET', PUBLIC_REPO, manifest_ref=FAKE_MANIFEST).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(404, 404, 404, 404, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
2016-08-04 20:23:09 +00:00
|
|
|
IndexV2TestSpec('v2.fetch_manifest_by_tagname', 'GET', PRIVATE_REPO,
|
|
|
|
manifest_ref=FAKE_MANIFEST).
|
|
|
|
request_status(401, 401, 404, 401, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
IndexV2TestSpec('v2.fetch_manifest_by_tagname', 'GET', ORG_REPO, manifest_ref=FAKE_MANIFEST).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(401, 401, 404, 401, 404),
|
|
|
|
|
|
|
|
IndexV2TestSpec('v2.fetch_manifest_by_tagname', 'GET', ANOTHER_ORG_REPO,
|
|
|
|
manifest_ref=FAKE_MANIFEST).
|
|
|
|
request_status(401, 401, 401, 401, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
# v2.fetch_manifest_by_digest
|
|
|
|
IndexV2TestSpec('v2.fetch_manifest_by_digest', 'GET', PUBLIC_REPO, manifest_ref=FAKE_DIGEST).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(404, 404, 404, 404, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
IndexV2TestSpec('v2.fetch_manifest_by_digest', 'GET', PRIVATE_REPO, manifest_ref=FAKE_DIGEST).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(401, 401, 404, 401, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
IndexV2TestSpec('v2.fetch_manifest_by_digest', 'GET', ORG_REPO, manifest_ref=FAKE_DIGEST).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(401, 401, 404, 401, 404),
|
|
|
|
|
|
|
|
IndexV2TestSpec('v2.fetch_manifest_by_digest', 'GET', ANOTHER_ORG_REPO,
|
|
|
|
manifest_ref=FAKE_DIGEST).
|
|
|
|
request_status(401, 401, 401, 401, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
# v2.write_manifest_by_tagname
|
|
|
|
IndexV2TestSpec('v2.write_manifest_by_tagname', 'PUT', PUBLIC_REPO, manifest_ref=FAKE_MANIFEST).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(401, 401, 401, 401, 401),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
2016-08-04 20:23:09 +00:00
|
|
|
IndexV2TestSpec('v2.write_manifest_by_tagname', 'PUT', PRIVATE_REPO,
|
|
|
|
manifest_ref=FAKE_MANIFEST).
|
|
|
|
request_status(401, 401, 401, 401, 400),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
IndexV2TestSpec('v2.write_manifest_by_tagname', 'PUT', ORG_REPO, manifest_ref=FAKE_MANIFEST).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(401, 401, 401, 401, 400),
|
|
|
|
|
|
|
|
IndexV2TestSpec('v2.write_manifest_by_tagname', 'PUT', ANOTHER_ORG_REPO,
|
|
|
|
manifest_ref=FAKE_MANIFEST).
|
|
|
|
request_status(401, 401, 401, 401, 400),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
# v2.write_manifest_by_digest
|
|
|
|
IndexV2TestSpec('v2.write_manifest_by_digest', 'PUT', PUBLIC_REPO, manifest_ref=FAKE_DIGEST).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(401, 401, 401, 401, 401),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
IndexV2TestSpec('v2.write_manifest_by_digest', 'PUT', PRIVATE_REPO, manifest_ref=FAKE_DIGEST).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(401, 401, 401, 401, 400),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
IndexV2TestSpec('v2.write_manifest_by_digest', 'PUT', ORG_REPO, manifest_ref=FAKE_DIGEST).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(401, 401, 401, 401, 400),
|
|
|
|
|
|
|
|
IndexV2TestSpec('v2.write_manifest_by_digest', 'PUT', ANOTHER_ORG_REPO,
|
|
|
|
manifest_ref=FAKE_DIGEST).
|
|
|
|
request_status(401, 401, 401, 401, 400),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
# v2.delete_manifest_by_digest
|
2016-08-04 20:23:09 +00:00
|
|
|
IndexV2TestSpec('v2.delete_manifest_by_digest', 'DELETE', PUBLIC_REPO,
|
|
|
|
manifest_ref=FAKE_DIGEST).
|
|
|
|
request_status(401, 401, 401, 401, 401),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
2016-08-04 20:23:09 +00:00
|
|
|
IndexV2TestSpec('v2.delete_manifest_by_digest', 'DELETE', PRIVATE_REPO,
|
|
|
|
manifest_ref=FAKE_DIGEST).
|
|
|
|
request_status(401, 401, 401, 401, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
IndexV2TestSpec('v2.delete_manifest_by_digest', 'DELETE', ORG_REPO, manifest_ref=FAKE_DIGEST).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(401, 401, 401, 401, 404),
|
|
|
|
|
|
|
|
IndexV2TestSpec('v2.delete_manifest_by_digest', 'DELETE', ANOTHER_ORG_REPO,
|
|
|
|
manifest_ref=FAKE_DIGEST).
|
|
|
|
request_status(401, 401, 401, 401, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
# v2.check_blob_exists
|
|
|
|
IndexV2TestSpec('v2.check_blob_exists', 'HEAD', PUBLIC_REPO, digest=FAKE_DIGEST).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(404, 404, 404, 404, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
IndexV2TestSpec('v2.check_blob_exists', 'HEAD', PRIVATE_REPO, digest=FAKE_DIGEST).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(401, 401, 404, 401, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
IndexV2TestSpec('v2.check_blob_exists', 'HEAD', ORG_REPO, digest=FAKE_DIGEST).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(401, 401, 404, 401, 404),
|
|
|
|
|
|
|
|
IndexV2TestSpec('v2.check_blob_exists', 'HEAD', ANOTHER_ORG_REPO, digest=FAKE_DIGEST).
|
|
|
|
request_status(401, 401, 401, 401, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
# v2.download_blob
|
|
|
|
IndexV2TestSpec('v2.download_blob', 'GET', PUBLIC_REPO, digest=FAKE_DIGEST).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(404, 404, 404, 404, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
IndexV2TestSpec('v2.download_blob', 'GET', PRIVATE_REPO, digest=FAKE_DIGEST).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(401, 401, 404, 401, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
IndexV2TestSpec('v2.download_blob', 'GET', ORG_REPO, digest=FAKE_DIGEST).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(401, 401, 404, 401, 404),
|
|
|
|
|
|
|
|
IndexV2TestSpec('v2.download_blob', 'GET', ANOTHER_ORG_REPO, digest=FAKE_DIGEST).
|
|
|
|
request_status(401, 401, 401, 401, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
# v2.start_blob_upload
|
|
|
|
IndexV2TestSpec('v2.start_blob_upload', 'POST', PUBLIC_REPO).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(401, 401, 401, 401, 401),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
IndexV2TestSpec('v2.start_blob_upload', 'POST', PRIVATE_REPO).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(401, 401, 401, 401, 202),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
IndexV2TestSpec('v2.start_blob_upload', 'POST', ORG_REPO).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(401, 401, 401, 401, 202),
|
|
|
|
|
|
|
|
IndexV2TestSpec('v2.start_blob_upload', 'POST', ANOTHER_ORG_REPO).
|
|
|
|
request_status(401, 401, 401, 401, 202),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
# v2.fetch_existing_upload
|
2016-08-04 20:23:09 +00:00
|
|
|
IndexV2TestSpec('v2.fetch_existing_upload', 'GET', PUBLIC_REPO, 'push,pull',
|
|
|
|
upload_uuid=FAKE_UPLOAD_ID).
|
|
|
|
request_status(401, 401, 401, 401, 401),
|
|
|
|
|
|
|
|
IndexV2TestSpec('v2.fetch_existing_upload', 'GET', PRIVATE_REPO, 'push,pull',
|
|
|
|
upload_uuid=FAKE_UPLOAD_ID).
|
|
|
|
request_status(401, 401, 401, 401, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
2016-08-04 20:23:09 +00:00
|
|
|
IndexV2TestSpec('v2.fetch_existing_upload', 'GET', ORG_REPO, 'push,pull',
|
|
|
|
upload_uuid=FAKE_UPLOAD_ID).
|
|
|
|
request_status(401, 401, 401, 401, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
2016-08-04 20:23:09 +00:00
|
|
|
IndexV2TestSpec('v2.fetch_existing_upload', 'GET', ANOTHER_ORG_REPO, 'push,pull',
|
|
|
|
upload_uuid=FAKE_UPLOAD_ID).
|
|
|
|
request_status(401, 401, 401, 401, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
# v2.upload_chunk
|
|
|
|
IndexV2TestSpec('v2.upload_chunk', 'PATCH', PUBLIC_REPO, upload_uuid=FAKE_UPLOAD_ID).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(401, 401, 401, 401, 401),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
IndexV2TestSpec('v2.upload_chunk', 'PATCH', PRIVATE_REPO, upload_uuid=FAKE_UPLOAD_ID).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(401, 401, 401, 401, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
IndexV2TestSpec('v2.upload_chunk', 'PATCH', ORG_REPO, upload_uuid=FAKE_UPLOAD_ID).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(401, 401, 401, 401, 404),
|
|
|
|
|
|
|
|
IndexV2TestSpec('v2.upload_chunk', 'PATCH', ANOTHER_ORG_REPO, upload_uuid=FAKE_UPLOAD_ID).
|
|
|
|
request_status(401, 401, 401, 401, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
# v2.monolithic_upload_or_last_chunk
|
2016-08-04 20:23:09 +00:00
|
|
|
IndexV2TestSpec('v2.monolithic_upload_or_last_chunk', 'PUT', PUBLIC_REPO,
|
|
|
|
upload_uuid=FAKE_UPLOAD_ID).
|
|
|
|
request_status(401, 401, 401, 401, 401),
|
|
|
|
|
|
|
|
IndexV2TestSpec('v2.monolithic_upload_or_last_chunk', 'PUT', PRIVATE_REPO,
|
|
|
|
upload_uuid=FAKE_UPLOAD_ID).
|
|
|
|
request_status(401, 401, 401, 401, 400),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
2016-08-04 20:23:09 +00:00
|
|
|
IndexV2TestSpec('v2.monolithic_upload_or_last_chunk', 'PUT', ORG_REPO,
|
|
|
|
upload_uuid=FAKE_UPLOAD_ID).
|
|
|
|
request_status(401, 401, 401, 401, 400),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
2016-08-04 20:23:09 +00:00
|
|
|
IndexV2TestSpec('v2.monolithic_upload_or_last_chunk', 'PUT', ANOTHER_ORG_REPO,
|
|
|
|
upload_uuid=FAKE_UPLOAD_ID).
|
|
|
|
request_status(401, 401, 401, 401, 400),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
# v2.cancel_upload
|
|
|
|
IndexV2TestSpec('v2.cancel_upload', 'DELETE', PUBLIC_REPO, upload_uuid=FAKE_UPLOAD_ID).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(401, 401, 401, 401, 401),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
IndexV2TestSpec('v2.cancel_upload', 'DELETE', PRIVATE_REPO, upload_uuid=FAKE_UPLOAD_ID).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(401, 401, 401, 401, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
|
|
|
|
IndexV2TestSpec('v2.cancel_upload', 'DELETE', ORG_REPO, upload_uuid=FAKE_UPLOAD_ID).
|
2016-08-04 20:23:09 +00:00
|
|
|
request_status(401, 401, 401, 401, 404),
|
|
|
|
|
|
|
|
IndexV2TestSpec('v2.cancel_upload', 'DELETE', ANOTHER_ORG_REPO, upload_uuid=FAKE_UPLOAD_ID).
|
|
|
|
request_status(401, 401, 401, 401, 404),
|
2015-10-02 18:01:12 +00:00
|
|
|
]
|
2017-03-22 22:29:53 +00:00
|
|
|
|