Extract app from torrent handling code
Fixes https://jira.coreos.com/browse/QUAY-969
This commit is contained in:
parent
c92c0ca5e1
commit
0fdefd78e9
7 changed files with 63 additions and 53 deletions
|
@ -102,7 +102,7 @@ class ValidatorContext(object):
|
|||
def __init__(self, config, user_password=None, http_client=None, context=None,
|
||||
url_scheme_and_hostname=None, jwt_auth_max=None, registry_title=None,
|
||||
ip_resolver=None, feature_sec_scanner=False, is_testing=False,
|
||||
uri_creator=None, config_provider=None):
|
||||
uri_creator=None, config_provider=None, instance_keys=None):
|
||||
self.config = config
|
||||
self.user = get_authenticated_user()
|
||||
self.user_password = user_password
|
||||
|
@ -116,14 +116,17 @@ class ValidatorContext(object):
|
|||
self.is_testing = is_testing
|
||||
self.uri_creator = uri_creator
|
||||
self.config_provider = config_provider
|
||||
self.instance_keys = instance_keys
|
||||
|
||||
@classmethod
|
||||
def from_app(cls, app, config, user_password, ip_resolver, client=None, config_provider=None):
|
||||
def from_app(cls, app, config, user_password, ip_resolver, instance_keys, client=None,
|
||||
config_provider=None):
|
||||
"""
|
||||
Creates a ValidatorContext from an app config, with a given config to validate
|
||||
:param app: the Flask app to pull configuration information from
|
||||
:param config: the config to validate
|
||||
:param user_password: request password
|
||||
:param instance_keys: The instance keys handler
|
||||
:param ip_resolver: an App
|
||||
:param client:
|
||||
:param config_provider:
|
||||
|
@ -139,11 +142,8 @@ class ValidatorContext(object):
|
|||
app.config.get('JWT_AUTH_MAX_FRESH_S', 300),
|
||||
app.config['REGISTRY_TITLE'],
|
||||
ip_resolver,
|
||||
instance_keys,
|
||||
app.config.get('FEATURE_SECURITY_SCANNER', False),
|
||||
app.config.get('TESTING', False),
|
||||
get_blob_download_uri_getter(app.test_request_context('/'), url_scheme_and_hostname),
|
||||
config_provider)
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import pytest
|
||||
|
||||
from config import build_requests_session
|
||||
from httmock import urlmatch, HTTMock
|
||||
|
||||
from config import build_requests_session
|
||||
from app import instance_keys
|
||||
from util.config.validator import ValidatorContext
|
||||
from util.config.validators import ConfigValidationException
|
||||
from util.config.validators.validate_torrent import BittorrentValidator
|
||||
|
@ -25,13 +26,13 @@ def test_validate_torrent(unvalidated_config, expected, app):
|
|||
validator = BittorrentValidator()
|
||||
if expected is not None:
|
||||
with pytest.raises(expected):
|
||||
config = ValidatorContext(unvalidated_config)
|
||||
config = ValidatorContext(unvalidated_config, instance_keys=instance_keys)
|
||||
config.http_client = build_requests_session()
|
||||
|
||||
validator.validate(config)
|
||||
assert not announcer_hit[0]
|
||||
else:
|
||||
config = ValidatorContext(unvalidated_config)
|
||||
config = ValidatorContext(unvalidated_config, instance_keys=instance_keys)
|
||||
config.http_client = build_requests_session()
|
||||
|
||||
validator.validate(config)
|
||||
|
|
|
@ -3,9 +3,7 @@ import logging
|
|||
from hashlib import sha1
|
||||
|
||||
from util.config.validators import BaseValidator, ConfigValidationException
|
||||
# Temporarily removed because registry.torrent imports from app, add encoded_jwt back once extracted
|
||||
# TODO(jschorr): extract app from following package and re-enable jwt_from_infohash in validator
|
||||
# from util.registry.torrent import jwt_from_infohash
|
||||
from util.registry.torrent import jwt_from_infohash, TorrentConfiguration
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -33,8 +31,10 @@ class BittorrentValidator(BaseValidator):
|
|||
'port': 80,
|
||||
}
|
||||
|
||||
# encoded_jwt = jwt_from_infohash(params['info_hash'])
|
||||
# params['jwt'] = encoded_jwt
|
||||
torrent_config = TorrentConfiguration.for_testing(validator_context.instance_keys, announce_url,
|
||||
validator_context.registry_title)
|
||||
encoded_jwt = jwt_from_infohash(torrent_config, params['info_hash'])
|
||||
params['jwt'] = encoded_jwt
|
||||
|
||||
resp = client.get(announce_url, timeout=5, params=params)
|
||||
logger.debug('Got tracker response: %s: %s', resp.status_code, resp.text)
|
||||
|
|
Reference in a new issue