def test_current_user(security_center): ''' test current user ''' user = security_center.current.user(fields=['id', 'name']) assert isinstance(user, dict) check(user, 'id', str) check(user, 'name', str)
def test_server_status(api): ''' test to get server status ''' status = api.server.status() assert isinstance(status, dict) check(status, 'code', int) check(status, 'status', str)
def test_current_org(security_center): ''' test current organization ''' org = security_center.current.org(fields=['id', 'name']) assert isinstance(org, dict) check(org, 'id', str) check(org, 'name', str)
def test_current_associate_cert(security_center): ''' test current associate certificate ''' resp = security_center.current.associate_cert() assert isinstance(resp, dict) check(resp, 'success', str) assert resp[ 'success'] == 'certificate is associated successfully to the current user'
def test_network_asset_count_network_success(api): ''' test to raise exception when type of network_id param does not match the expected type. ''' network = '00000000-0000-0000-0000-000000000000' resp = api.networks.network_asset_count(network, 180) assert isinstance(resp, dict) check(resp, 'numAssetsTotal', int) check(resp, 'numAssetsNotSeen', int)
def test_users_list_auths_success(api, user): ''' test to list user auths ''' user_auth = api.users.list_auths(user['id']) assert isinstance(user, dict) check(user_auth, 'account_uuid', 'uuid') check(user_auth, 'api_permitted', bool) check(user_auth, 'password_permitted', bool) check(user_auth, 'saml_permitted', bool) check(user_auth, 'user_uuid', 'uuid')
def test_remedyscan_create_scan_document_template_pass(api): ''' test to create scan document basic template ''' templates = api.policies.templates() resp = getattr(api.remediationscans, '_create_scan_document')({ 'template': 'basic' }) assert isinstance(resp, dict) check(resp, 'uuid', 'scanner-uuid') assert resp['uuid'] == templates['basic']
def test_remedyscan_create_scan_document_policies_id_pass(api): ''' test to create scan document policy param using id ''' policies = api.policies.list() policy = policies[0] resp = getattr(api.remediationscans, '_create_scan_document')({ 'policy': policy['id'] }) assert isinstance(resp, dict) check(resp, 'settings', dict) check(resp['settings'], 'policy_id', int) assert resp['settings']['policy_id'] == policy['id']
def test_remedyscan_create_scan_document_scanner_name_pass(api): ''' test to create scan document with scanner name param ''' scanners = api.scanners.allowed_scanners() scanner = scanners[1] resp = getattr(api.remediationscans, '_create_scan_document')({ 'scanner': scanner['name'] }) assert isinstance(resp, dict) check(resp, 'settings', dict) check(resp['settings'], 'scanner_id', str) assert resp['settings']['scanner_id'] == scanner['id']
def test_agentconfig_edit_success_fields(api): """ test to edit the agent_config and verify their types """ resp = api.agent_config.edit(scanner_id=False) assert isinstance(resp, dict) check(resp, 'auto_unlink', dict, allow_none=True) check(resp, 'software_update', bool, allow_none=True) check(resp['auto_unlink'], 'enabled', bool) check(resp['auto_unlink'], 'expiration', int)
def test_agentconfig_show_details_fields(api): ''' test to show agent_config details ''' resp = api.agent_config.details(scanner_id=0) assert isinstance(resp, dict) check(resp, 'auto_unlink', dict) check(resp['auto_unlink'], 'enabled', bool) check(resp['auto_unlink'], 'expiration', int) check(resp, 'software_update', bool)
def test_groups_edit_success(api, group): ''' test to edit group ''' edited = api.groups.edit(group['id'], 'New Example Name') assert isinstance(edited, dict) check(edited, 'uuid', 'uuid') check(edited, 'name', str) check(edited, 'user_count', int) check(edited, 'id', int)
def test_agentconfig_edit_set_autounlink(api): ''' test to edit autounlink param. ''' resp = api.agent_config.edit(auto_unlink=31) assert isinstance(resp, dict) check(resp, 'auto_unlink', dict) check(resp['auto_unlink'], 'enabled', bool) check(resp['auto_unlink'], 'expiration', int) check(resp, 'software_update', bool) assert resp['auto_unlink']['expiration'] == 31
def test_remedyscan_check_auto_targets_success(api): ''' test to evaluates a list of targets and/or tags against the scan route configuration of scanner groups ''' resp = api.scans.check_auto_targets(10, 5, targets=['127.0.0.1']) assert isinstance(resp, dict) check(resp, 'matched_resource_uuids', list) check(resp, 'missed_targets', list) check(resp, 'total_matched_resource_uuids', int) check(resp, 'total_missed_targets', int)
def test_assets_bulk_delete_success(api): ''' test to delete multiple assets ''' ip_addr = '192.168.254.2' # import assets first_asset = api.assets.asset_import( 'pytest', { 'fqdn': ['example1.py.test'], 'ipv4': [ip_addr], 'netbios_name': '', 'mac_address': [] }) second_asset = api.assets.asset_import( 'pytest', { 'fqdn': ['example2.py.test'], 'ipv4': [ip_addr], 'netbios_name': '', 'mac_address': [] }) # wait for asset to import iterate = True iterate_count = 0 while iterate: time.sleep(5) job = api.assets.list_import_jobs() asset = [ data['status'] for data in job if first_asset in data['job_id'] or second_asset in data['job_id'] ] iterate_count = iterate_count + 1 # break iteration if iterate_count == 5 or (len(asset) == 2 and len(set(asset)) == 1 and asset[0] == 'COMPLETE'): break # remove imported asset time.sleep(45) resp = api.assets.bulk_delete(('ipv4', 'eq', ip_addr)) check(resp['response']['data'], 'asset_count', int) assert resp['response']['data']['asset_count'] == 2
def test_agentconfig_edit_disable_softwareupdate(api): ''' test to disable software_update param. ''' resp = api.agent_config.edit(software_update=False) assert isinstance(resp, dict) check(resp, 'auto_unlink', dict) check(resp['auto_unlink'], 'enabled', bool) check(resp['auto_unlink'], 'expiration', int) check(resp, 'software_update', bool) assert resp['software_update'] is False
def test_groups_list(api): ''' test to get list of group ''' groups = api.groups.list() assert isinstance(groups, list) for group in groups: assert isinstance(group, dict) check(group, 'id', int) check(group, 'name', str) check(group, 'user_count', int) check(group, 'uuid', 'uuid')
def test_groups_create(group): ''' test to create group ''' assert isinstance(group, dict) check(group, 'uuid', 'uuid') check(group, 'name', str) check(group, 'id', int)
def test_assets_move_assets_success(api, network): ''' test to move assets from the specified network to another network ''' ip_addr = '192.168.254.1' # import asset job_id = api.assets.asset_import( 'pytest', { 'fqdn': ['example.py.test'], 'ipv4': [ip_addr], 'netbios_name': '', 'mac_address': [] }) # wait for asset to import iterate = True iterate_count = 0 while iterate: time.sleep(5) job = api.assets.list_import_jobs() asset = [data['status'] for data in job if job_id in data['job_id']] iterate_count = iterate_count + 1 # break iteration if iterate_count == 5 or (len(asset) == 1 and asset[0] == 'COMPLETE'): break # move asset to new network time.sleep(45) resp = api.assets.move_assets('00000000-0000-0000-0000-000000000000', network['uuid'], ['192.168.254.1']) # remove imported asset api.assets.bulk_delete(('ipv4', 'eq', ip_addr)) check(resp['response']['data'], 'asset_count', int) assert resp['response']['data']['asset_count'] == 1
def test_access_groups_details_success(api, agroup): ''' test to get details of specific access group ''' group = api.access_groups.details(agroup['id']) assert isinstance(group, dict) check(group, 'created_at', 'datetime') check(group, 'updated_at', 'datetime') check(group, 'id', 'uuid') check(group, 'name', str) check(group, 'all_assets', bool) check(group, 'all_users', bool) check(group, 'rules', list) for rule in group['rules']: check(rule, 'type', str) check(rule, 'operator', str) check(rule, 'terms', list) if 'principals' in group and group['principals']: check(group, 'principals', list) for principal in group['principals']: check(principal, 'type', str) check(principal, 'principal_id', 'uuid') check(principal, 'principal_name', str) check(group, 'created_by_uuid', 'uuid') check(group, 'updated_by_uuid', 'uuid') check(group, 'created_by_name', str) check(group, 'updated_by_name', str) check(group, 'processing_percent_complete', int)
def test_access_groups_create_success(agroup): ''' test to create access group ''' assert isinstance(agroup, dict) check(agroup, 'created_at', 'datetime') check(agroup, 'updated_at', 'datetime') check(agroup, 'id', 'uuid') check(agroup, 'name', str) check(agroup, 'all_assets', bool) check(agroup, 'all_users', bool) check(agroup, 'rules', list) for rule in agroup['rules']: check(rule, 'type', str) check(rule, 'operator', str) check(rule, 'terms', list) if 'principals' in agroup and agroup['principals']: check(agroup, 'principals', list) for principal in agroup['principals']: check(principal, 'type', str) check(principal, 'principal_id', 'uuid') check(principal, 'principal_name', str) check(agroup, 'created_by_uuid', 'uuid') check(agroup, 'updated_by_uuid', 'uuid') check(agroup, 'created_by_name', str) check(agroup, 'updated_by_name', str) check(agroup, 'processing_percent_complete', int)
def test_workbench_vuln_outputs(api): ''' test to get workbench vulnerability output ''' vulns = api.workbenches.vulns() if vulns: outputs = api.workbenches.vuln_outputs(vulns[0]['plugin_id']) assert isinstance(outputs, list) if outputs: output = outputs[0] check(output, 'plugin_output', str) check(output, 'states', list) for state in output['states']: check(state, 'name', str) check(state, 'results', list) for result in state['results']: check(result, 'application_protocol', str, allow_none=True) check(result, 'assets', list) for asset in result['assets']: check(asset, 'first_seen', 'datetime', allow_none=True) check(asset, 'fqdn', str, allow_none=True) check(asset, 'hostname', str) check(asset, 'id', 'uuid') check(asset, 'ipv4', str, allow_none=True) check(asset, 'last_seen', 'datetime', allow_none=True) check(asset, 'netbios_name', str, allow_none=True) check(asset, 'uuid', 'uuid') check(result, 'port', int) check(result, 'severity', int) check(result, 'transport_protocol', str)
def test_workbench_vuln_info(api): ''' test to get workbench vulnerability info ''' vulns = api.workbenches.vulns() if vulns: info = api.workbenches.vuln_info(vulns[0]['plugin_id']) assert isinstance(info, dict) check(info, 'accepted_count', int) check(info, 'count', int) check(info, 'discovery', dict) check(info['discovery'], 'seen_first', 'datetime', allow_none=True) check(info['discovery'], 'seen_last', 'datetime', allow_none=True) check(info, 'plugin_details', dict) check(info['plugin_details'], 'family', str) check(info['plugin_details'], 'modification_date', 'datetime', allow_none=True) check(info['plugin_details'], 'name', str) check(info['plugin_details'], 'publication_date', 'datetime', allow_none=True) check(info['plugin_details'], 'severity', int) check(info['plugin_details'], 'type', str, allow_none=True) check(info['plugin_details'], 'version', str, allow_none=True) check(info, 'recasted_count', int) check(info, 'reference_information', list) check(info, 'risk_information', dict) check(info['risk_information'], 'cvss3_base_score', str, allow_none=True) check(info['risk_information'], 'cvss3_temporal_score', str, allow_none=True) check(info['risk_information'], 'cvss3_temporal_vector', str, allow_none=True) check(info['risk_information'], 'cvss3_vector', str, allow_none=True) check(info['risk_information'], 'cvss_base_score', str, allow_none=True) check(info['risk_information'], 'cvss_temporal_score', str, allow_none=True) check(info['risk_information'], 'cvss_temporal_vector', str, allow_none=True) check(info['risk_information'], 'cvss_vector', str, allow_none=True) check(info['risk_information'], 'risk_factor', str, allow_none=True) check(info['risk_information'], 'stig_severity', str, allow_none=True) check(info, 'see_also', list) check(info, 'severity', int) check(info, 'vuln_count', int)
def test_workbench_vulns(api): ''' test to get workbench vulnerabilities ''' vulns = api.workbenches.vulns() assert isinstance(vulns, list) if vulns: vulnerability = vulns[0] check(vulnerability, 'accepted_count', int) check(vulnerability, 'counts_by_severity', list) for counts_by_severity in vulnerability['counts_by_severity']: check(counts_by_severity, 'count', int) check(counts_by_severity, 'value', int) check(vulnerability, 'plugin_family', str) check(vulnerability, 'plugin_id', int) check(vulnerability, 'plugin_name', str) check(vulnerability, 'recasted_count', int) check(vulnerability, 'vulnerability_state', str)
def test_workbench_vuln_assets(api): ''' test to get workbench vulnerability assets ''' assets = api.workbenches.vuln_assets() assert isinstance(assets, list) asset = assets[0] check(asset, 'fqdn', list) check(asset, 'id', 'uuid') check(asset, 'ipv4', list) check(asset, 'ipv6', list) check(asset, 'severities', list) for severity in asset['severities']: check(severity, 'count', int) check(severity, 'level', int) check(severity, 'name', str) check(asset, 'total', int) # loop on list of keys which may be present in response for key, value in { 'agent_name': list, 'last_seen': 'datetime', 'netbios_name': list }.items(): if key in asset: check(asset, key, value)
def test_workbench_asset_vulns_filtered(api): ''' test to get filtered workbench asset vulnerabilities ''' assets = api.workbenches.assets() if assets: vulns = api.workbenches.asset_vulns(assets[0]['id'], ('severity', 'eq', 'Info')) assert isinstance(vulns, list) if vulns: vulnerability = vulns[0] check(vulnerability, 'accepted_count', int) check(vulnerability, 'count', int) check(vulnerability, 'counts_by_severity', list) for counts_by_severity in vulnerability['counts_by_severity']: check(counts_by_severity, 'count', int) check(counts_by_severity, 'value', int) check(vulnerability, 'plugin_family', str) check(vulnerability, 'plugin_id', int) check(vulnerability, 'plugin_name', str) check(vulnerability, 'severity', int) check(vulnerability, 'vulnerability_state', str)
def test_workbench_asset_activity(api): ''' test to get workbench asset activity ''' assets = api.workbenches.assets() try: if assets: history = api.workbenches.asset_activity(assets[0]['id']) assert isinstance(history, list) for data in history: check(data, 'timestamp', 'datetime') check(data, 'type', str) if data['type'] in ['tagging', 'updated']: check(data, 'updates', list) for update in data['updates']: check(update, 'method', str) check(update, 'property', str) check(update, 'value', str) if data['type'] == 'discovered': check(data, 'details', dict) check(data['details'], 'assetId', 'uuid') check(data['details'], 'createdAt', 'datetime') check(data['details'], 'firstScanTime', 'datetime') check(data['details'], 'hasAgent', bool) check(data['details'], 'lastLicensedScanTime', 'datetime') check(data['details'], 'lastLicensedScanTimeV2', 'datetime') check(data['details'], 'lastScanTime', 'datetime') check(data['details'], 'properties', dict) for keys in data['details']['properties'].keys(): check(data['details']['properties'][keys], 'values', list) check(data['details'], 'sources', list) for status in data['details']['sources']: check(status, 'firstSeen', 'datetime') check(status, 'lastSeen', 'datetime') check(status, 'name', str) check(data['details'], 'updatedAt', 'datetime') if data['type'] in ['discovered', 'seen']: check(data, 'scan_id', 'scanner-uuid') check(data, 'schedule_id', str) check(data, 'source', str) except NotFoundError: print('Activity for the asset uuid is not found')
def test_access_groups_list(api): ''' test to get list of access groups ''' count = 0 access_groups = api.access_groups.list() for group in access_groups: count += 1 assert isinstance(group, dict) check(group, 'created_at', 'datetime') check(group, 'updated_at', 'datetime') check(group, 'id', 'uuid') check(group, 'name', str) check(group, 'all_assets', bool) check(group, 'all_users', bool) #check(group, 'created_by_uuid', 'uuid') # Will not return for default group if 'updated_by_uuid' in group: check(group, 'updated_by_uuid', 'uuid') check(group, 'created_by_name', str) check(group, 'updated_by_name', str) check(group, 'processing_percent_complete', int) check(group, 'status', str) assert count == access_groups.total
def test_access_groups_list_fields(api): ''' test to raise the exception to list the access groups ''' count = 0 access_groups = api.access_groups.list(filter_type='or', limit=45, offset=2, wildcard='match', wildcard_fields=['name']) for group in access_groups: count += 1 assert isinstance(group, dict) check(group, 'created_at', 'datetime') check(group, 'updated_at', 'datetime') check(group, 'id', 'uuid') check(group, 'name', str) check(group, 'all_assets', bool) check(group, 'all_users', bool) # check(i, 'created_by_uuid', 'uuid') # Will not return for default group check(group, 'updated_by_uuid', 'uuid') check(group, 'created_by_name', str) check(group, 'updated_by_name', str) check(group, 'processing_percent_complete', int) check(group, 'status', str) assert count == access_groups.total
def test_workbench_assets(api): ''' test to get workbench assets ''' assets = api.workbenches.assets() assert isinstance(assets, list) if assets: asset = assets[0] check(asset, 'access_group_id', list) check(asset, 'agent_name', list) check(asset, 'aws_availability_zone', list) check(asset, 'aws_ec2_instance_ami_id', list) check(asset, 'aws_ec2_instance_group_name', list) check(asset, 'aws_ec2_instance_id', list) check(asset, 'aws_ec2_instance_state_name', list) check(asset, 'aws_ec2_instance_type', list) check(asset, 'aws_ec2_name', list) check(asset, 'aws_ec2_product_code', list) check(asset, 'aws_owner_id', list) check(asset, 'aws_region', list) check(asset, 'aws_subnet_id', list) check(asset, 'aws_vpc_id', list) check(asset, 'azure_resource_id', list) check(asset, 'azure_vm_id', list) check(asset, 'bios_uuid', list) check(asset, 'created_at', 'datetime') check(asset, 'first_scan_time', 'datetime', allow_none=True) check(asset, 'first_seen', 'datetime', allow_none=True) check(asset, 'fqdn', list) check(asset, 'gcp_instance_id', list) check(asset, 'gcp_project_id', list) check(asset, 'gcp_zone', list) check(asset, 'has_agent', bool) check(asset, 'hostname', list) check(asset, 'id', 'uuid') check(asset, 'installed_software', list) check(asset, 'interfaces', list) for interface in asset['interfaces']: check(interface, 'fqdn', list) check(interface, 'ipv4', list) check(interface, 'ipv6', list) check(interface, 'mac_address', list) check(interface, 'name', str) check(asset, 'ipv4', list) check(asset, 'ipv6', list) check(asset, 'last_authenticated_scan_date', 'datetime', allow_none=True) check(asset, 'last_licensed_scan_date', 'datetime', allow_none=True) check(asset, 'last_scan_id', 'scanner-uuid', allow_none=True) check(asset, 'last_scan_target', str, allow_none=True) check(asset, 'last_schedule_id', str, allow_none=True) check(asset, 'last_scan_time', 'datetime', allow_none=True) check(asset, 'last_seen', 'datetime', allow_none=True) check(asset, 'mac_address', list) check(asset, 'manufacturer_tpm_id', list) check(asset, 'mcafee_epo_agent_guid', list) check(asset, 'mcafee_epo_guid', list) check(asset, 'netbios_name', list) check(asset, 'network_id', list) check(asset, 'operating_system', list) check(asset, 'qualys_asset_id', list) check(asset, 'qualys_host_id', list) check(asset, 'servicenow_sysid', list) check(asset, 'sources', list) for source in asset['sources']: check(source, 'first_seen', 'datetime') check(source, 'last_seen', 'datetime') check(source, 'name', str) check(asset, 'ssh_fingerprint', list) check(asset, 'symantec_ep_hardware_key', list) check(asset, 'system_type', list) check(asset, 'tag_id', list) check(asset, 'tags', list) check(asset, 'tenable_uuid', list) check(asset, 'terminated_at', 'datetime', allow_none=True) check(asset, 'terminated_by', str, allow_none=True) check(asset, 'updated_at', 'datetime')