test: add qss read failover case
This commit is contained in:
parent
dd033e4feb
commit
c2c6bc1e90
2 changed files with 47 additions and 1 deletions
|
@ -28,10 +28,17 @@ class FakeSecurityScanner(object):
|
|||
self.notifications = {}
|
||||
self.layer_vulns = {}
|
||||
|
||||
self.ok_layer_id = None
|
||||
self.fail_layer_id = None
|
||||
self.internal_error_layer_id = None
|
||||
self.error_layer_id = None
|
||||
|
||||
def set_ok_layer_id(self, ok_layer_id):
|
||||
""" Sets a layer ID that, if encountered when the analyze call is made, causes a 200
|
||||
to be immediately returned.
|
||||
"""
|
||||
self.ok_layer_id = ok_layer_id
|
||||
|
||||
def set_fail_layer_id(self, fail_layer_id):
|
||||
""" Sets a layer ID that, if encountered when the analyze call is made, causes a 422
|
||||
to be raised.
|
||||
|
@ -167,6 +174,12 @@ class FakeSecurityScanner(object):
|
|||
@urlmatch(netloc=r'(.*\.)?' + self.hostname, path=r'/v1/layers/(.+)', method='GET')
|
||||
def get_layer_mock(url, request):
|
||||
layer_id = url.path[len('/v1/layers/'):]
|
||||
if layer_id == self.ok_layer_id:
|
||||
return {
|
||||
'status_code': 200,
|
||||
'content': json.dumps({'Layer': {}}),
|
||||
}
|
||||
|
||||
if layer_id == self.internal_error_layer_id:
|
||||
return {
|
||||
'status_code': 500,
|
||||
|
@ -305,7 +318,10 @@ class FakeSecurityScanner(object):
|
|||
|
||||
@all_requests
|
||||
def response_content(url, _):
|
||||
raise Exception('Unknown endpoint: ' + str(url))
|
||||
return {
|
||||
'status_code': 500,
|
||||
'content': '',
|
||||
}
|
||||
|
||||
return [get_layer_mock, post_layer_mock, remove_layer_mock, get_notification,
|
||||
delete_notification, response_content]
|
||||
|
|
Reference in a new issue