def test_webinspect_api_helper_list_scans_success(api_mock): # Given webinspect_api_helper_object = WebInspectAPIHelper(silent=True, webinspect_setting_overrides=MagicMock()) webinspect_api_helper_object.api.list_scans = api_mock # When webinspect_api_helper_object.list_scans() # Expect assert api_mock.call_count == 1
def test_webinspect_api_helper_list_scans_failure_name_error(api_mock, log_error_mock): # Given webinspect_api_helper_object = WebInspectAPIHelper(silent=True, webinspect_setting_overrides=MagicMock()) webinspect_api_helper_object.api.list_scans = api_mock api_mock.side_effect = NameError # When webinspect_api_helper_object.list_scans() # Expect assert log_error_mock.call_count == 1 assert api_mock.call_count == 1
def list_scans(scan_name, server, username, password): if server: # if any cli servers were passed. servers = [] for s in server: servers.append(s) else: servers = [(e[0]) for e in WebInspectConfig().endpoints] auth_config = WebInspectAuth() username, password = auth_config.authenticate(username, password) for server in servers: query_client = WebInspectAPIHelper(host=server, username=username, password=password) if scan_name: results = query_client.get_scan_by_name(scan_name) if results and len(results): print("Scans matching the name {} found on {}".format( scan_name, server)) print("{0:80} {1:40} {2:10}".format( 'Scan Name', 'Scan ID', 'Scan Status')) print("{0:80} {1:40} {2:10}\n".format( '-' * 80, '-' * 40, '-' * 10)) for match in results: print("{0:80} {1:40} {2:10}".format( match['Name'], match['ID'], match['Status'])) else: Logger.app.error( "No scans matching the name {} were found on {}". format(scan_name, server)) else: results = query_client.list_scans() if results and len(results): print("Scans found on {}".format(server)) print("{0:80} {1:40} {2:10}".format( 'Scan Name', 'Scan ID', 'Scan Status')) print("{0:80} {1:40} {2:10}\n".format( '-' * 80, '-' * 40, '-' * 10)) for scan in results: print("{0:80} {1:40} {2:10}".format( scan['Name'], scan['ID'], scan['Status'])) else: print("No scans found on {}".format(server)) # If we've made it this far, our new credentials are valid and should be saved if username is not None and password is not None and not auth_config.has_auth_creds( ): auth_config.write_credentials(username, password)