2017-02-10 01:28:39 +00:00
|
|
|
import pytest
|
|
|
|
|
2018-05-29 17:50:51 +00:00
|
|
|
from config import build_requests_session
|
|
|
|
from util.config import URLSchemeAndHostname
|
|
|
|
from util.config.validator import ValidatorContext
|
2017-02-10 01:28:39 +00:00
|
|
|
from util.config.validators.validate_secscan import SecurityScannerValidator
|
|
|
|
from util.secscan.fake import fake_security_scanner
|
|
|
|
|
2017-04-24 18:52:30 +00:00
|
|
|
from test.fixtures import *
|
|
|
|
|
2017-02-10 01:28:39 +00:00
|
|
|
@pytest.mark.parametrize('unvalidated_config', [
|
|
|
|
({'DISTRIBUTED_STORAGE_PREFERENCE': []}),
|
|
|
|
])
|
|
|
|
def test_validate_noop(unvalidated_config, app):
|
2018-06-01 15:31:19 +00:00
|
|
|
|
|
|
|
unvalidated_config = ValidatorContext(unvalidated_config, feature_sec_scanner=False, is_testing=True,
|
|
|
|
http_client=build_requests_session(),
|
|
|
|
url_scheme_and_hostname=URLSchemeAndHostname('http', 'localhost:5000'))
|
2018-05-29 17:50:51 +00:00
|
|
|
|
|
|
|
SecurityScannerValidator.validate(unvalidated_config)
|
2017-02-10 01:28:39 +00:00
|
|
|
|
|
|
|
|
2017-03-24 21:28:16 +00:00
|
|
|
@pytest.mark.parametrize('unvalidated_config, expected_error', [
|
2017-02-10 01:28:39 +00:00
|
|
|
({
|
|
|
|
'TESTING': True,
|
|
|
|
'DISTRIBUTED_STORAGE_PREFERENCE': [],
|
|
|
|
'FEATURE_SECURITY_SCANNER': True,
|
|
|
|
'SECURITY_SCANNER_ENDPOINT': 'http://invalidhost',
|
2017-03-24 21:28:16 +00:00
|
|
|
}, Exception),
|
2017-02-10 01:28:39 +00:00
|
|
|
|
|
|
|
({
|
|
|
|
'TESTING': True,
|
|
|
|
'DISTRIBUTED_STORAGE_PREFERENCE': [],
|
|
|
|
'FEATURE_SECURITY_SCANNER': True,
|
|
|
|
'SECURITY_SCANNER_ENDPOINT': 'http://fakesecurityscanner',
|
2017-03-24 21:28:16 +00:00
|
|
|
}, None),
|
2017-02-10 01:28:39 +00:00
|
|
|
])
|
2017-03-24 21:28:16 +00:00
|
|
|
def test_validate(unvalidated_config, expected_error, app):
|
2018-06-01 15:31:19 +00:00
|
|
|
unvalidated_config = ValidatorContext(unvalidated_config, feature_sec_scanner=True, is_testing=True,
|
|
|
|
http_client=build_requests_session(),
|
|
|
|
url_scheme_and_hostname=URLSchemeAndHostname('http', 'localhost:5000'))
|
2018-05-29 17:50:51 +00:00
|
|
|
|
2017-02-10 01:28:39 +00:00
|
|
|
with fake_security_scanner(hostname='fakesecurityscanner'):
|
|
|
|
if expected_error is not None:
|
2017-03-24 21:28:16 +00:00
|
|
|
with pytest.raises(expected_error):
|
2018-05-29 17:50:51 +00:00
|
|
|
SecurityScannerValidator.validate(unvalidated_config)
|
2017-02-10 01:28:39 +00:00
|
|
|
else:
|
2018-05-29 17:50:51 +00:00
|
|
|
SecurityScannerValidator.validate(unvalidated_config)
|