Skip to content

Commit

Permalink
Support empty new lines in the input file. (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyhau authored Nov 4, 2022
1 parent 2f5117c commit fb4bbab
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Change Log
All notable changes to this project will be documented in this file.

2.0.1 - 2022-11-04
==================

### Fixed
- Support empty new lines in the input file.


2.0.0 - 2022-09-03
==================

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import find_packages, setup

__title__ = "ssllabsscan"
__version__ = "2.0.0"
__version__ = "2.0.1"
__author__ = "Kay Hau"
__email__ = "[email protected]"
__uri__ = "https://github.com/kyhau/ssllabs-scan"
Expand Down
2 changes: 1 addition & 1 deletion ssllabsscan/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def process(
# read from input file
with open(server_list_file) as f:
content = f.readlines()
servers = [x.strip() for x in content]
servers = [x.strip() for x in content if x.strip()]

with open(SUMMARY_CSV, "w") as outfile:
# write column names to file
Expand Down
13 changes: 13 additions & 0 deletions ssllabsscan/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ def sample_server_list_file(unit_tests_tmp_output_dir):
return server_list_file


@pytest.fixture(scope="session")
def sample_server_list_file_2(unit_tests_tmp_output_dir):
"""
Create a sample server_list file in the tmp unit tests file.
Return the full path filename
"""
server_list_file = os.path.join(unit_tests_tmp_output_dir, "test_server_list_2.txt")
with open(server_list_file, "w") as outfile:
# File has emptry newlines
outfile.write("\nexample.com\n\n")
return server_list_file


@pytest.fixture(scope="session")
def output_summary_csv_file(unit_tests_tmp_output_dir):
return os.path.join(unit_tests_tmp_output_dir, "test_summary.csv")
Expand Down
49 changes: 45 additions & 4 deletions ssllabsscan/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import os

from mock import Mock

from ssllabsscan.main import process
from ssllabsscan.ssllabs_client import SSLLabsClient

from .conftest import MockHttpResponse


def test_main_process(
sample_server_list_file,
def common_tests(
sample_input_file,
sample_dns_response,
sample_in_progress_response,
sample_ready_response,
Expand All @@ -24,8 +25,8 @@ def test_main_process(

SSLLabsClient.requests_get = Mock(side_effect=mocked_request_ok_response_sequence)

assert 0==process(
sample_server_list_file,
assert 0 == process(
sample_input_file,
check_progress_interval_secs=1,
summary_csv=output_summary_csv_file,
summary_html=output_summary_html_file
Expand All @@ -34,3 +35,43 @@ def test_main_process(
assert os.path.exists(output_server_1_json_file)
assert os.path.exists(output_summary_csv_file)
assert os.path.exists(output_summary_html_file)


def test_main_process_1(
sample_server_list_file,
sample_dns_response,
sample_in_progress_response,
sample_ready_response,
output_summary_csv_file,
output_summary_html_file,
output_server_1_json_file
):
common_tests(
sample_server_list_file,
sample_dns_response,
sample_in_progress_response,
sample_ready_response,
output_summary_csv_file,
output_summary_html_file,
output_server_1_json_file
)


def test_main_process_2(
sample_server_list_file_2, # input file with empty newlines
sample_dns_response,
sample_in_progress_response,
sample_ready_response,
output_summary_csv_file,
output_summary_html_file,
output_server_1_json_file
):
common_tests(
sample_server_list_file_2,
sample_dns_response,
sample_in_progress_response,
sample_ready_response,
output_summary_csv_file,
output_summary_html_file,
output_server_1_json_file
)

0 comments on commit fb4bbab

Please sign in to comment.