Changeset - 97b43a00271d
[Not reviewed]
0 1 0
Branko Majic (branko) - 4 years ago 2020-07-13 16:45:47
branko@majic.rs
GC-37: Parametrise tests for init command stdout/stderr to cover ECDSA as well.
1 file changed with 14 insertions and 6 deletions:
0 comments (0 inline, 0 general)
tests/test_commands.py
Show inline comments
 
@@ -244,39 +244,47 @@ def test_server_errors_out_if_certificate_already_issued(gctmpdir):
 
    assert "server myserver" in stderr
 
    assert stdout == ""
 
    assert gctmpdir.join('.gimmecert', 'server', 'myserver.key.pem').read() == existing_private_key
 
    assert gctmpdir.join('.gimmecert', 'server', 'myserver.cert.pem').read() == certificate
 

	
 

	
 
def test_init_command_stdout_and_stderr_for_single_ca(tmpdir):
 
@pytest.mark.parametrize("key_specification, key_specification_representation", [
 
    [("rsa", 2048), "2048-bit RSA"],
 
    [("ecdsa", ec.SECP192R1), "secp192r1 ECDSA"],
 
])
 
def test_init_command_stdout_and_stderr_for_single_ca(tmpdir, key_specification, key_specification_representation):
 
    stdout_stream = io.StringIO()
 
    stderr_stream = io.StringIO()
 

	
 
    gimmecert.commands.init(stdout_stream, stderr_stream, tmpdir.strpath, "myproject", 1, ("rsa", 2048))
 
    gimmecert.commands.init(stdout_stream, stderr_stream, tmpdir.strpath, "myproject", 1, key_specification)
 

	
 
    stdout = stdout_stream.getvalue()
 
    stderr = stderr_stream.getvalue()
 

	
 
    assert stderr == ""
 
    assert "CA hierarchy initialised using 2048-bit RSA keys" in stdout
 
    assert "CA hierarchy initialised using %s keys" % key_specification_representation in stdout
 
    assert ".gimmecert/ca/level1.cert.pem" in stdout
 
    assert ".gimmecert/ca/level1.key.pem" in stdout
 
    assert ".gimmecert/ca/chain-full.cert.pem" in stdout
 

	
 

	
 
def test_init_command_stdout_and_stderr_for_multiple_cas_with_rsa_1024(tmpdir):
 
@pytest.mark.parametrize("key_specification, key_specification_representation", [
 
    [("rsa", 1024), "1024-bit RSA"],
 
    [("ecdsa", ec.SECP192R1), "secp192r1 ECDSA"],
 
])
 
def test_init_command_stdout_and_stderr_for_multiple_cas_with_key_specification(tmpdir, key_specification, key_specification_representation):
 
    stdout_stream = io.StringIO()
 
    stderr_stream = io.StringIO()
 

	
 
    gimmecert.commands.init(stdout_stream, stderr_stream, tmpdir.strpath, "myproject", 3, ("rsa", 1024))
 
    gimmecert.commands.init(stdout_stream, stderr_stream, tmpdir.strpath, "myproject", 3, key_specification)
 

	
 
    stdout = stdout_stream.getvalue()
 
    stderr = stderr_stream.getvalue()
 

	
 
    assert stderr == ""
 
    assert "CA hierarchy initialised using 1024-bit RSA keys" in stdout
 
    assert "CA hierarchy initialised using %s keys" % key_specification_representation in stdout
 
    assert ".gimmecert/ca/level1.cert.pem" in stdout
 
    assert ".gimmecert/ca/level1.key.pem" in stdout
 
    assert ".gimmecert/ca/level2.cert.pem" in stdout
 
    assert ".gimmecert/ca/level2.key.pem" in stdout
 
    assert ".gimmecert/ca/level3.cert.pem" in stdout
 
    assert ".gimmecert/ca/level3.key.pem" in stdout
0 comments (0 inline, 0 general)