示例#1
0
def test_ssl_labs_client_analyze(sample_ok_response, output_summary_csv_file, output_server_1_json_file):
    mocked_request_ok_response_sequence = [
        {"status": "DNS"},
        {"status": "IN_PROGRESS"},
        sample_ok_response,
    ]

    client = SSLLabsClient(check_progress_interval_secs=1)
    client.request_api = Mock(side_effect=mocked_request_ok_response_sequence)

    client.analyze(host=sample_ok_response["host"], summary_csv_file=output_summary_csv_file)

    assert os.path.exists(output_server_1_json_file)
    assert os.path.exists(output_summary_csv_file)
示例#2
0
def test_ssl_labs_client_start_new_scan(sample_ok_response):

    # Case 1: valid server url
    mocked_request_ok_response_sequence = [
        {"status": "DNS"},
        {"status": "IN_PROGRESS"},
        sample_ok_response,
    ]

    client1 = SSLLabsClient(check_progress_interval_secs=1)
    client1.request_api = Mock(side_effect=mocked_request_ok_response_sequence)

    ret = client1.start_new_scan(host=sample_ok_response["host"])
    assert ret["status"] == "READY"
    assert ret["host"] == sample_ok_response["host"]
    assert ret["endpoints"][0]["grade"]

    # Case 2: invalid server url
    mocked_request_err_response_sequence = [
        {"status": "DNS"},
        {"status": "ERROR"},
    ]

    client2 = SSLLabsClient(check_progress_interval_secs=1)
    client2.request_api = Mock(side_effect=mocked_request_err_response_sequence)

    ret = client2.start_new_scan(host="example2.com")
    assert ret["status"] == "ERROR"
示例#3
0
def process(
        server_list_file, check_progress_interval_secs=30,
        summary_csv=SUMMARY_CSV, summary_html=SUMMARY_HTML
):
    ret = 0
    # read from input file
    with open(server_list_file) as f:
        content = f.readlines()
    servers = [x.strip() for x in content]

    if not os.path.exists(os.path.dirname(SUMMARY_CSV)):
        try:
            os.makedirs(os.path.dirname(SUMMARY_CSV))
        except OSError as exc:
            if exc.errno != errno.EEXIST:
                raise

    with open(SUMMARY_CSV, "w") as outfile:
        # write column names to file
        outfile.write("#{}\n".format(",".join(str(s) for s in SUMMARY_COL_NAMES)))

    for server in servers:
        try:
            print("Start analyzing {} ...".format(server))
            SSLLabsClient(check_progress_interval_secs).analyze(server, summary_csv)
        except Exception as e:
            print(e)
            traceback.print_stack()
            ret = 1

    output_summary_html(summary_csv, summary_html)
    return ret
示例#4
0
def process(server_list_file,
            check_progress_interval_secs=30,
            summary_csv=SUMMARY_CSV,
            summary_html=SUMMARY_HTML):
    ret = 0
    # read from input file
    with open(server_list_file) as f:
        content = f.readlines()
    servers = [x.strip() for x in content]

    with open(SUMMARY_CSV, 'w') as outfile:
        # write column names to file
        outfile.write("#{}\n".format(",".join(
            str(s) for s in SUMMARY_COL_NAMES)))

    for server in servers:
        try:
            print("Start analyzing {} ...".format(server))
            SSLLabsClient(check_progress_interval_secs).analyze(
                server, summary_csv)
        except Exception as e:
            print(e)
            ret = 1

    output_summary_html(summary_csv, summary_html)
    return ret
示例#5
0
def test_prepare_datetime(time):
    """Test that SSLLabsClient.prepare_datetime works as expected."""
    assert SSLLabsClient().prepare_datetime(time) == "2018-03-17"