37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
|
import pytest
|
||
|
|
||
|
from util.config.validators import ConfigValidationException
|
||
|
from util.config.validators.validate_secscan import SecurityScannerValidator
|
||
|
from util.secscan.fake import fake_security_scanner
|
||
|
|
||
|
@pytest.mark.parametrize('unvalidated_config', [
|
||
|
({'DISTRIBUTED_STORAGE_PREFERENCE': []}),
|
||
|
])
|
||
|
def test_validate_noop(unvalidated_config, app):
|
||
|
SecurityScannerValidator.validate(unvalidated_config, None, None)
|
||
|
|
||
|
|
||
|
@pytest.mark.parametrize('unvalidated_config, expected_error, error_message', [
|
||
|
({
|
||
|
'TESTING': True,
|
||
|
'DISTRIBUTED_STORAGE_PREFERENCE': [],
|
||
|
'FEATURE_SECURITY_SCANNER': True,
|
||
|
'SECURITY_SCANNER_ENDPOINT': 'http://invalidhost',
|
||
|
}, Exception, 'Connection error when trying to connect to security scanner endpoint'),
|
||
|
|
||
|
({
|
||
|
'TESTING': True,
|
||
|
'DISTRIBUTED_STORAGE_PREFERENCE': [],
|
||
|
'FEATURE_SECURITY_SCANNER': True,
|
||
|
'SECURITY_SCANNER_ENDPOINT': 'http://fakesecurityscanner',
|
||
|
}, None, None),
|
||
|
])
|
||
|
def test_validate(unvalidated_config, expected_error, error_message, app):
|
||
|
with fake_security_scanner(hostname='fakesecurityscanner'):
|
||
|
if expected_error is not None:
|
||
|
with pytest.raises(expected_error) as ipe:
|
||
|
SecurityScannerValidator.validate(unvalidated_config, None, None)
|
||
|
assert ipe.value.message == error_message
|
||
|
else:
|
||
|
SecurityScannerValidator.validate(unvalidated_config, None, None)
|