From a08bc91f2b7dfaae03aa3fc3887d47779c16bba4 2020-05-29 15:22:50 From: Branko Majic Date: 2020-05-29 15:22:50 Subject: [PATCH] GC-37: Drop use of depth variable in a number of tests to make them simpler. --- diff --git a/tests/test_commands.py b/tests/test_commands.py index afcb8513e5fd70f67bb2d28319fa50338c2394f0..413f61f74686ceaae6acbf6dab91b2c6f95f3145 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -36,9 +36,8 @@ def test_init_sets_up_directory_structure(tmpdir): base_dir = tmpdir.join('.gimmecert') ca_dir = tmpdir.join('.gimmecert', 'ca') server_dir = tmpdir.join('.gimmecert', 'server') - depth = 1 - gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, depth) + gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, 1) assert os.path.exists(base_dir.strpath) assert os.path.exists(ca_dir.strpath) @@ -46,9 +45,7 @@ def test_init_sets_up_directory_structure(tmpdir): def test_init_generates_single_ca_artifact_for_depth_1(tmpdir): - depth = 1 - - gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, depth) + gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, 1) assert os.path.exists(tmpdir.join('.gimmecert', 'ca', 'level1.key.pem').strpath) assert os.path.exists(tmpdir.join('.gimmecert', 'ca', 'level1.cert.pem').strpath) @@ -56,9 +53,7 @@ def test_init_generates_single_ca_artifact_for_depth_1(tmpdir): def test_init_generates_three_ca_artifacts_for_depth_3(tmpdir): - depth = 3 - - gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, depth) + gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, 3) assert os.path.exists(tmpdir.join('.gimmecert', 'ca', 'level1.key.pem').strpath) assert os.path.exists(tmpdir.join('.gimmecert', 'ca', 'level1.cert.pem').strpath) @@ -70,9 +65,7 @@ def test_init_generates_three_ca_artifacts_for_depth_3(tmpdir): def test_init_outputs_full_chain_for_depth_1(tmpdir): - depth = 1 - - gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, depth) + gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, 1) level1_certificate = tmpdir.join('.gimmecert', 'ca', 'level1.cert.pem').read() full_chain = tmpdir.join('.gimmecert', 'ca', 'chain-full.cert.pem').read() @@ -81,9 +74,7 @@ def test_init_outputs_full_chain_for_depth_1(tmpdir): def test_init_outputs_full_chain_for_depth_3(tmpdir): - depth = 3 - - gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, depth) + gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, 3) level1_certificate = tmpdir.join('.gimmecert', 'ca', 'level1.cert.pem').read() level2_certificate = tmpdir.join('.gimmecert', 'ca', 'level2.cert.pem').read() @@ -96,32 +87,26 @@ def test_init_outputs_full_chain_for_depth_3(tmpdir): def test_init_returns_success_if_directory_has_not_been_previously_initialised(tmpdir): - depth = 1 - - status_code = gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, depth) + status_code = gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, 1) assert status_code == gimmecert.commands.ExitCode.SUCCESS def test_init_returns_error_code_if_directory_has_been_previously_initialised(tmpdir): - depth = 1 - - gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, depth) - status_code = gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, depth) + gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, 1) + status_code = gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, 1) assert status_code == gimmecert.commands.ExitCode.ERROR_ALREADY_INITIALISED def test_init_does_not_overwrite_artifcats_if_already_initialised(tmpdir): - depth = 1 - - gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, depth) + gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, 1) level1_private_key_before = tmpdir.join('.gimmecert', 'ca', 'level1.key.pem').read() level1_certificate_before = tmpdir.join('.gimmecert', 'ca', 'level1.cert.pem').read() full_chain_before = tmpdir.join('.gimmecert', 'ca', 'chain-full.cert.pem').read() - gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, depth) + gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, 1) level1_private_key_after = tmpdir.join('.gimmecert', 'ca', 'level1.key.pem').read() level1_certificate_after = tmpdir.join('.gimmecert', 'ca', 'level1.cert.pem').read() @@ -638,13 +623,11 @@ def test_status_reports_uninitialised_directory(tmpdir): def test_status_reports_ca_hierarchy_information(tmpdir): - depth = 3 - stdout_stream = io.StringIO() stderr_stream = io.StringIO() with freeze_time('2018-01-01 00:15:00'): - gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, depth) + gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, 3) with freeze_time('2018-06-01 00:15:00'): status_code = gimmecert.commands.status(stdout_stream, stderr_stream, tmpdir.strpath) @@ -684,8 +667,6 @@ def test_status_reports_ca_hierarchy_information(tmpdir): def test_status_reports_server_certificate_information(tmpdir): - depth = 3 - stdout_stream = io.StringIO() stderr_stream = io.StringIO() @@ -695,7 +676,7 @@ def test_status_reports_server_certificate_information(tmpdir): gimmecert.storage.write_csr(myserver3_csr, myserver3_csr_file.strpath) with freeze_time('2018-01-01 00:15:00'): - gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, depth) + gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, 3) with freeze_time('2018-02-01 00:15:00'): gimmecert.commands.server(io.StringIO(), io.StringIO(), tmpdir.strpath, 'myserver1', None, None) @@ -754,8 +735,6 @@ def test_status_reports_server_certificate_information(tmpdir): def test_status_reports_client_certificate_information(tmpdir): - depth = 3 - stdout_stream = io.StringIO() stderr_stream = io.StringIO() @@ -765,7 +744,7 @@ def test_status_reports_client_certificate_information(tmpdir): gimmecert.storage.write_csr(myclient3_csr, myclient3_csr_file.strpath) with freeze_time('2018-01-01 00:15:00'): - gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, depth) + gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, 3) with freeze_time('2018-02-01 00:15:00'): gimmecert.commands.client(io.StringIO(), io.StringIO(), tmpdir.strpath, 'myclient1', None) @@ -818,14 +797,12 @@ def test_status_reports_client_certificate_information(tmpdir): def test_status_reports_no_server_certificates_were_issued(tmpdir): - depth = 1 - stdout_stream = io.StringIO() stderr_stream = io.StringIO() # Just create some sample data, but no server certificates. with freeze_time('2018-01-01 00:15:00'): - gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, depth) + gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, 1) gimmecert.commands.client(io.StringIO(), io.StringIO(), tmpdir.strpath, 'myclient1', None) gimmecert.commands.client(io.StringIO(), io.StringIO(), tmpdir.strpath, 'myclient2', None) @@ -841,14 +818,12 @@ def test_status_reports_no_server_certificates_were_issued(tmpdir): def test_status_reports_no_client_certificates_were_issued(tmpdir): - depth = 1 - stdout_stream = io.StringIO() stderr_stream = io.StringIO() # Just create some sample data, but no client certificates. with freeze_time('2018-01-01 00:15:00'): - gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, depth) + gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, tmpdir.basename, 1) gimmecert.commands.server(io.StringIO(), io.StringIO(), tmpdir.strpath, 'myserver1', None, None) gimmecert.commands.server(io.StringIO(), io.StringIO(), tmpdir.strpath, 'myserver2', None, None) @@ -882,14 +857,12 @@ def test_certificate_marked_as_not_valid_or_expired_as_appropriate(tmpdir, subje between these. """ - depth = 1 - stdout_stream = io.StringIO() stderr_stream = io.StringIO() # Perform action on our fixed issuance date. with freeze_time(issuance_date): - gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, "My Project", depth) + gimmecert.commands.init(io.StringIO(), io.StringIO(), tmpdir.strpath, "My Project", 1) gimmecert.commands.server(io.StringIO(), io.StringIO(), tmpdir.strpath, 'myserver', None, None) gimmecert.commands.client(io.StringIO(), io.StringIO(), tmpdir.strpath, 'myclient', None)