Beispiel #1
0
def test_webinspect_api_helper_get_scan_by_name_success(api_mock):
    # Given
    webinspect_api_helper_object = WebInspectAPIHelper(silent=True, webinspect_setting_overrides=MagicMock())
    webinspect_api_helper_object.api.get_scan_by_name = api_mock

    # When
    webinspect_api_helper_object.get_scan_by_name("test_name")

    # Expect
    assert api_mock.call_count == 1
Beispiel #2
0
    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)
Beispiel #3
0
    def download(server, scan_name, scan_id, extension, username, password):
        try:
            auth_config = WebInspectAuth()
            username, password = auth_config.authenticate(username, password)

            query_client = WebInspectAPIHelper(host=server, username=username, password=password)

            if not scan_id:
                results = query_client.get_scan_by_name(scan_name)
                if len(results) == 0:
                    webinspect_logexceptionhelper.log_error_no_scans_found(scan_name)
                elif len(results) == 1:
                    scan_id = results[0]['ID']
                    Logger.app.info("Scan matching the name {} found.".format(scan_name))
                    Logger.app.info("Downloading scan {}".format(scan_name))
                    query_client.export_scan_results(scan_id, extension, scan_name)
                else:
                    webinspect_logexceptionhelper.log_info_multiple_scans_found(scan_name)
                    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 result in results:
                        print("{0:80} {1:40} {2:10}".format(result['Name'], result['ID'], result['Status']))
            else:
                if query_client.get_scan_status(scan_id):
                    query_client.export_scan_results(scan_id, extension, scan_name)

                else:
                    if query_client.get_scan_status(scan_id):
                        query_client.export_scan_results(scan_id, extension, scan_name)
                    else:
                        Logger.console.error("Unable to find scan with ID matching {}".format(scan_id))

        except (UnboundLocalError, TypeError) as e:
            webinspect_logexceptionhelper.log_error_webinspect_download(e)

        # 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)