Skip to content

Commit fb4bbab

Browse files
authored
Support empty new lines in the input file. (#126)
1 parent 2f5117c commit fb4bbab

File tree

5 files changed

+67
-6
lines changed

5 files changed

+67
-6
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
2.0.1 - 2022-11-04
5+
==================
6+
7+
### Fixed
8+
- Support empty new lines in the input file.
9+
10+
411
2.0.0 - 2022-09-03
512
==================
613

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools import find_packages, setup
22

33
__title__ = "ssllabsscan"
4-
__version__ = "2.0.0"
4+
__version__ = "2.0.1"
55
__author__ = "Kay Hau"
66
__email__ = "virtualda@gmail.com"
77
__uri__ = "https://github.com/kyhau/ssllabs-scan"

ssllabsscan/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def process(
5555
# read from input file
5656
with open(server_list_file) as f:
5757
content = f.readlines()
58-
servers = [x.strip() for x in content]
58+
servers = [x.strip() for x in content if x.strip()]
5959

6060
with open(SUMMARY_CSV, "w") as outfile:
6161
# write column names to file

ssllabsscan/tests/conftest.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,19 @@ def sample_server_list_file(unit_tests_tmp_output_dir):
114114
return server_list_file
115115

116116

117+
@pytest.fixture(scope="session")
118+
def sample_server_list_file_2(unit_tests_tmp_output_dir):
119+
"""
120+
Create a sample server_list file in the tmp unit tests file.
121+
Return the full path filename
122+
"""
123+
server_list_file = os.path.join(unit_tests_tmp_output_dir, "test_server_list_2.txt")
124+
with open(server_list_file, "w") as outfile:
125+
# File has emptry newlines
126+
outfile.write("\nexample.com\n\n")
127+
return server_list_file
128+
129+
117130
@pytest.fixture(scope="session")
118131
def output_summary_csv_file(unit_tests_tmp_output_dir):
119132
return os.path.join(unit_tests_tmp_output_dir, "test_summary.csv")

ssllabsscan/tests/test_main.py

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import os
22

33
from mock import Mock
4+
45
from ssllabsscan.main import process
56
from ssllabsscan.ssllabs_client import SSLLabsClient
67

78
from .conftest import MockHttpResponse
89

910

10-
def test_main_process(
11-
sample_server_list_file,
11+
def common_tests(
12+
sample_input_file,
1213
sample_dns_response,
1314
sample_in_progress_response,
1415
sample_ready_response,
@@ -24,8 +25,8 @@ def test_main_process(
2425

2526
SSLLabsClient.requests_get = Mock(side_effect=mocked_request_ok_response_sequence)
2627

27-
assert 0==process(
28-
sample_server_list_file,
28+
assert 0 == process(
29+
sample_input_file,
2930
check_progress_interval_secs=1,
3031
summary_csv=output_summary_csv_file,
3132
summary_html=output_summary_html_file
@@ -34,3 +35,43 @@ def test_main_process(
3435
assert os.path.exists(output_server_1_json_file)
3536
assert os.path.exists(output_summary_csv_file)
3637
assert os.path.exists(output_summary_html_file)
38+
39+
40+
def test_main_process_1(
41+
sample_server_list_file,
42+
sample_dns_response,
43+
sample_in_progress_response,
44+
sample_ready_response,
45+
output_summary_csv_file,
46+
output_summary_html_file,
47+
output_server_1_json_file
48+
):
49+
common_tests(
50+
sample_server_list_file,
51+
sample_dns_response,
52+
sample_in_progress_response,
53+
sample_ready_response,
54+
output_summary_csv_file,
55+
output_summary_html_file,
56+
output_server_1_json_file
57+
)
58+
59+
60+
def test_main_process_2(
61+
sample_server_list_file_2, # input file with empty newlines
62+
sample_dns_response,
63+
sample_in_progress_response,
64+
sample_ready_response,
65+
output_summary_csv_file,
66+
output_summary_html_file,
67+
output_server_1_json_file
68+
):
69+
common_tests(
70+
sample_server_list_file_2,
71+
sample_dns_response,
72+
sample_in_progress_response,
73+
sample_ready_response,
74+
output_summary_csv_file,
75+
output_summary_html_file,
76+
output_server_1_json_file
77+
)

0 commit comments

Comments
 (0)