Make QSS validation errors more descriptive
This commit is contained in:
parent
de07dc1a78
commit
b017133cc6
2 changed files with 14 additions and 12 deletions
|
@ -11,26 +11,25 @@ def test_validate_noop(unvalidated_config, app):
|
||||||
SecurityScannerValidator.validate(unvalidated_config, None, None)
|
SecurityScannerValidator.validate(unvalidated_config, None, None)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('unvalidated_config, expected_error, error_message', [
|
@pytest.mark.parametrize('unvalidated_config, expected_error', [
|
||||||
({
|
({
|
||||||
'TESTING': True,
|
'TESTING': True,
|
||||||
'DISTRIBUTED_STORAGE_PREFERENCE': [],
|
'DISTRIBUTED_STORAGE_PREFERENCE': [],
|
||||||
'FEATURE_SECURITY_SCANNER': True,
|
'FEATURE_SECURITY_SCANNER': True,
|
||||||
'SECURITY_SCANNER_ENDPOINT': 'http://invalidhost',
|
'SECURITY_SCANNER_ENDPOINT': 'http://invalidhost',
|
||||||
}, Exception, 'Connection error when trying to connect to security scanner endpoint'),
|
}, Exception),
|
||||||
|
|
||||||
({
|
({
|
||||||
'TESTING': True,
|
'TESTING': True,
|
||||||
'DISTRIBUTED_STORAGE_PREFERENCE': [],
|
'DISTRIBUTED_STORAGE_PREFERENCE': [],
|
||||||
'FEATURE_SECURITY_SCANNER': True,
|
'FEATURE_SECURITY_SCANNER': True,
|
||||||
'SECURITY_SCANNER_ENDPOINT': 'http://fakesecurityscanner',
|
'SECURITY_SCANNER_ENDPOINT': 'http://fakesecurityscanner',
|
||||||
}, None, None),
|
}, None),
|
||||||
])
|
])
|
||||||
def test_validate(unvalidated_config, expected_error, error_message, app):
|
def test_validate(unvalidated_config, expected_error, app):
|
||||||
with fake_security_scanner(hostname='fakesecurityscanner'):
|
with fake_security_scanner(hostname='fakesecurityscanner'):
|
||||||
if expected_error is not None:
|
if expected_error is not None:
|
||||||
with pytest.raises(expected_error) as ipe:
|
with pytest.raises(expected_error):
|
||||||
SecurityScannerValidator.validate(unvalidated_config, None, None)
|
SecurityScannerValidator.validate(unvalidated_config, None, None)
|
||||||
assert ipe.value.message == error_message
|
|
||||||
else:
|
else:
|
||||||
SecurityScannerValidator.validate(unvalidated_config, None, None)
|
SecurityScannerValidator.validate(unvalidated_config, None, None)
|
||||||
|
|
|
@ -166,15 +166,18 @@ class SecurityScannerAPI(object):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return self._call('GET', _API_METHOD_PING)
|
return self._call('GET', _API_METHOD_PING)
|
||||||
except requests.exceptions.Timeout:
|
except requests.exceptions.Timeout as tie:
|
||||||
logger.exception('Timeout when trying to connect to security scanner endpoint')
|
logger.exception('Timeout when trying to connect to security scanner endpoint')
|
||||||
raise Exception('Timeout when trying to connect to security scanner endpoint')
|
msg = 'Timeout when trying to connect to security scanner endpoint: %s' % tie.message
|
||||||
except requests.exceptions.ConnectionError:
|
raise Exception(msg)
|
||||||
|
except requests.exceptions.ConnectionError as ce:
|
||||||
logger.exception('Connection error when trying to connect to security scanner endpoint')
|
logger.exception('Connection error when trying to connect to security scanner endpoint')
|
||||||
raise Exception('Connection error when trying to connect to security scanner endpoint')
|
msg = 'Connection error when trying to connect to security scanner endpoint: %s' % ce.message
|
||||||
except (requests.exceptions.RequestException, ValueError):
|
raise Exception(msg)
|
||||||
|
except (requests.exceptions.RequestException, ValueError) as ve:
|
||||||
logger.exception('Exception when trying to connect to security scanner endpoint')
|
logger.exception('Exception when trying to connect to security scanner endpoint')
|
||||||
raise Exception('Exception when trying to connect to security scanner endpoint')
|
msg = 'Exception when trying to connect to security scanner endpoint: %s' % ve
|
||||||
|
raise Exception(msg)
|
||||||
|
|
||||||
def delete_layer(self, layer):
|
def delete_layer(self, layer):
|
||||||
""" Calls DELETE on the given layer in the security scanner, removing it from
|
""" Calls DELETE on the given layer in the security scanner, removing it from
|
||||||
|
|
Reference in a new issue