Source code for api.assets.v1.test_helpers.host.search_host_assets



[docs]def success(function): """Mock https://portal.mnemonic.no/web/api/assets/v1/host/search, respond with HTTP 200""" import requests_mock from argus_api.helpers.tests import fake_response def mock_response(*args, **kwargs): with requests_mock.Mocker(real_http=True) as mock: mock.register_uri( "POST", r"https://portal.mnemonic.no/web/api/assets/v1/host/search", status_code=200, json=fake_response({'offset': {'type': 'int', 'name': 'offset'}, 'limit': {'type': 'int', 'name': 'limit'}, 'responseCode': {'type': 'int', 'name': 'responseCode'}, 'count': {'type': 'int', 'name': 'count'}, 'data': {'type': 'list', 'items': {'id': {'type': 'str'}, 'ownedByUser': {'id': {'type': 'int'}, 'customerID': {'type': 'int'}, 'domain': {'$ref': '#/definitions/DomainInfo'}, 'userName': {'type': 'str'}, 'name': {'type': 'str'}, 'type': 'str', 'options': ['user', 'group']}, 'customer': {'id': {'type': 'int'}, 'name': {'type': 'str'}, 'shortName': {'type': 'str'}, 'domain': {'$ref': '#/definitions/DomainInfo'}}, 'name': {'type': 'str', 'position': 0, 'description': 'The authorative name of the asset '}, 'description': {'type': 'str', 'position': 0, 'description': 'Asset description '}, 'criticality': {'confidentiality': {'type': 'str', 'position': 0, 'description': 'The confidentiality criticality level ', 'enum': ['unknown', 'low', 'medium', 'high', 'critical']}, 'integrity': {'type': 'str', 'position': 0, 'description': 'The integrity criticality level ', 'enum': ['unknown', 'low', 'medium', 'high', 'critical']}, 'availability': {'type': 'str', 'position': 0, 'description': 'The availability criticality level ', 'enum': ['unknown', 'low', 'medium', 'high', 'critical']}}, 'totalCvss': {'type': 'int', 'position': 0, 'description': 'The total CVSS score for this asset '}, 'vulnerabilitiesCount': {'type': 'int', 'position': 0, 'description': 'The total number of active vulnerabilities for this asset '}, 'createdTimestamp': {'type': 'int', 'position': 0, 'description': 'The timestamp when this asset was created '}, 'createdByUser': {'id': {'type': 'int'}, 'customerID': {'type': 'int'}, 'domain': {'$ref': '#/definitions/DomainInfo'}, 'userName': {'type': 'str'}, 'name': {'type': 'str'}, 'type': 'str', 'options': ['user', 'group']}, 'lastUpdatedTimestamp': {'type': 'int', 'position': 0, 'description': 'The timestamp when this asset was last updated '}, 'lastUpdatedByUser': {'id': {'type': 'int'}, 'customerID': {'type': 'int'}, 'domain': {'$ref': '#/definitions/DomainInfo'}, 'userName': {'type': 'str'}, 'name': {'type': 'str'}, 'type': 'str', 'options': ['user', 'group']}, 'deletedTimestamp': {'type': 'int', 'position': 0, 'description': 'The timestamp when this asset was deleted '}, 'deletedByUser': {'id': {'type': 'int'}, 'customerID': {'type': 'int'}, 'domain': {'$ref': '#/definitions/DomainInfo'}, 'userName': {'type': 'str'}, 'name': {'type': 'str'}, 'type': 'str', 'options': ['user', 'group']}, 'flags': {'type': 'list', 'position': 0, 'description': 'Flags assigned to the object. ', 'uniqueItems': True, 'items': {'type': 'str', 'enum': ['DELETED', 'CONTROLLED_VERSION', 'CREATED_BY_CVM', 'UPDATED_BY_CVM', 'DETECTED_BY_CVM', 'MISSING_FROM_CVM', 'DELETED_FROM_CVM', 'HAS_HIGH_VULN', 'HAS_CRITICAL_VULN', 'MERGED']}}, 'properties': {'type': 'dict', 'position': 0, 'description': 'Properties set for this asset ', 'additionalProperties': {'type': 'str'}}, 'type': 'str', 'firstSeenTimestamp': {'type': 'int', 'position': 0, 'description': 'The timestamp when this asset was first seen (in a scan) '}, 'lastSeenTimestamp': {'type': 'int', 'position': 0, 'description': 'The timestamp when this asset was last seen (in a scan) '}, 'lastScanTimestamp': {'type': 'int', 'position': 0, 'description': 'The timestamp when this asset was last scanned for '}, 'ipAddresses': {'type': 'list', 'position': 0, 'description': 'The IP addresses this asset is marked with ', 'uniqueItems': True, 'items': {'host': {'type': 'bool', 'xml': {'attribute': True}, 'readOnly': True, 'default': False}, 'maskBits': {'type': 'int'}, 'ipv6': {'type': 'bool', 'xml': {'attribute': True}, 'readOnly': True, 'default': False}, 'multicast': {'type': 'bool', 'default': False}, 'public': {'type': 'bool', 'default': False}, 'address': {'type': 'str', 'xml': {'attribute': True}, 'readOnly': True}}}, 'aliases': {'type': 'list', 'position': 0, 'description': 'Any (non-authorative) domainname aliases this asset is marked with ', 'uniqueItems': True, 'items': {'fqdn': {'type': 'str'}}}, 'services': {'type': 'list', 'position': 0, 'description': 'The services this host asset is bound to ', 'uniqueItems': True, 'items': {'id': {'type': 'str'}, 'name': {'type': 'str', 'position': 0, 'description': 'The authorative name of the asset '}}}, 'applications': {'type': 'list', 'position': 0, 'description': 'The applications registered on this asset ', 'uniqueItems': True, 'items': {'id': {'type': 'str'}, 'host': {'$ref': '#/definitions/HostAssetInfo'}, 'name': {'type': 'str'}, 'description': {'type': 'str'}, 'role': {'$ref': '#/definitions/RoleDefinition'}, 'createdTimestamp': {'type': 'int'}, 'createdByUser': {'$ref': '#/definitions/UserInfo'}, 'lastUpdatedTimestamp': {'type': 'int'}, 'lastUpdatedByUser': {'$ref': '#/definitions/UserInfo'}, 'deletedTimestamp': {'type': 'int'}, 'deletedByUser': {'$ref': '#/definitions/UserInfo'}, 'firstSeenTimestamp': {'type': 'int'}, 'lastSeenTimestamp': {'type': 'int'}, 'flags': {'type': 'list', 'position': 0, 'description': 'Flags assigned to the object. ', 'uniqueItems': True, 'items': {'type': 'str', 'enum': ['DELETED', 'CONTROLLED_VERSION', 'CREATED_BY_CVM', 'UPDATED_BY_CVM', 'DETECTED_BY_CVM', 'MISSING_FROM_CVM', 'DELETED_FROM_CVM']}}, 'properties': {'type': 'dict', 'additionalProperties': {'type': 'str'}}, 'customer': {'$ref': '#/definitions/CustomerInfo'}, 'cpe': {'type': 'str', 'readOnly': True}, 'sockets': {'type': 'list', 'readOnly': True, 'uniqueItems': True, 'items': {'type': 'str'}}}}, 'vulnerabilities': {'type': 'list', 'position': 0, 'description': 'The vulnerabilities registered on this asset ', 'uniqueItems': True, 'items': {'id': {'type': 'str'}, 'vulnerabilityID': {'type': 'str'}, 'host': {'$ref': '#/definitions/HostAssetInfo'}, 'references': {'type': 'list', 'uniqueItems': True, 'items': {'type': 'str'}}, 'name': {'type': 'str'}, 'description': {'type': 'str'}, 'conclusion': {'type': 'str'}, 'solution': {'type': 'str'}, 'rawOutput': {'type': 'str'}, 'cvss': {'type': 'int'}, 'createdTimestamp': {'type': 'int'}, 'createdByUser': {'$ref': '#/definitions/UserInfo'}, 'lastUpdatedTimestamp': {'type': 'int'}, 'lastUpdatedByUser': {'$ref': '#/definitions/UserInfo'}, 'deletedTimestamp': {'type': 'int'}, 'deletedByUser': {'$ref': '#/definitions/UserInfo'}, 'firstSeenTimestamp': {'type': 'int'}, 'lastSeenTimestamp': {'type': 'int'}, 'resolutionTimestamp': {'type': 'int'}, 'resolvedByUser': {'$ref': '#/definitions/UserInfo'}, 'resolutionComment': {'type': 'str'}, 'resolution': {'type': 'str', 'enum': ['ACCEPTED', 'FALSE_POSITIVE', 'SERVICE_NOT_AVAILABLE', 'NO_LONGER_VULNERABLE', 'UNRESOLVED']}, 'flags': {'type': 'list', 'position': 0, 'description': 'Flags assigned to the object. ', 'uniqueItems': True, 'items': {'type': 'str', 'enum': ['DELETED', 'CONTROLLED_VERSION', 'CREATED_BY_CVM', 'UPDATED_BY_CVM', 'DETECTED_BY_CVM', 'MISSING_FROM_CVM', 'DELETED_FROM_CVM', 'EXPLOIT_AVAILABLE']}}, 'properties': {'type': 'dict', 'additionalProperties': {'type': 'str'}}, 'customer': {'$ref': '#/definitions/CustomerInfo'}, 'severity': {'type': 'str', 'enum': ['info', 'low', 'medium', 'high', 'critical']}, 'socket': {'type': 'str', 'readOnly': True}}}, 'operatingSystemCPE': {'type': 'str', 'readOnly': True}, 'options': ['SERVER', 'CLIENT']}, 'name': 'data'}, 'metaData': {'type': 'dict', 'additionalProperties': {'type': 'dict'}, 'name': 'metaData'}, 'messages': {'type': 'list', 'items': {'message': {'type': 'str'}, 'messageTemplate': {'type': 'str'}, 'type': 'str', 'field': {'type': 'str'}, 'parameter': {'type': 'dict'}, 'timestamp': {'type': 'int'}, 'options': ['FIELD_ERROR', 'ACTION_ERROR', 'WARNING', 'NOTIFICATION', 'INFO']}, 'name': 'messages'}, 'currentPage': {'type': 'int', 'name': 'currentPage'}, 'size': {'type': 'int', 'name': 'size'}}) ) return function(*args, **kwargs) return mock_response return decorator
[docs]def unauthorized(function): """Mock https://portal.mnemonic.no/web/api/assets/v1/host/search, respond with HTTP 401""" import requests_mock from argus_api.helpers.tests import fake_response def mock_response(*args, **kwargs): with requests_mock.Mocker(real_http=True) as mock: mock.register_uri( "POST", r"https://portal.mnemonic.no/web/api/assets/v1/host/search", status_code=401, json=None ) return function(*args, **kwargs) return mock_response return decorator
[docs]def access_denied(function): """Mock https://portal.mnemonic.no/web/api/assets/v1/host/search, respond with HTTP 403""" import requests_mock from argus_api.helpers.tests import fake_response def mock_response(*args, **kwargs): with requests_mock.Mocker(real_http=True) as mock: mock.register_uri( "POST", r"https://portal.mnemonic.no/web/api/assets/v1/host/search", status_code=403, json=None ) return function(*args, **kwargs) return mock_response return decorator
[docs]def not_found(function): """Mock https://portal.mnemonic.no/web/api/assets/v1/host/search, respond with HTTP 404""" import requests_mock from argus_api.helpers.tests import fake_response def mock_response(*args, **kwargs): with requests_mock.Mocker(real_http=True) as mock: mock.register_uri( "POST", r"https://portal.mnemonic.no/web/api/assets/v1/host/search", status_code=404, json=None ) return function(*args, **kwargs) return mock_response return decorator