diff --git a/functional_tests/base.py b/functional_tests/base.py index c4d837e23f452cca412afa5b582e21f254cc7380..dffee6eb6aedccbea87730605e5020b77f88b3a8 100644 --- a/functional_tests/base.py +++ b/functional_tests/base.py @@ -89,7 +89,7 @@ def run_interactive_command(prompt_answers, command, *args): # stdout/stderr. output_stream = io.StringIO() send_stream = io.StringIO() - process = pexpect.spawnu(command, [*args], timeout=2) + process = pexpect.spawnu(command, list(args), timeout=2) process.logfile_read = output_stream process.logfile_send = send_stream diff --git a/gimmecert/storage.py b/gimmecert/storage.py index 9dc268315a297a8ce7c8b1dd342030927cc1044b..2475ec65d8541a77db5e1d6442628a982aeabea6 100644 --- a/gimmecert/storage.py +++ b/gimmecert/storage.py @@ -103,11 +103,11 @@ def write_certificate_chain(certificate_chain, path): :type path: str """ - chain_pem = b"\n".join( + chain_pem = "\n".join( [gimmecert.utils.certificate_to_pem(certificate) for certificate in certificate_chain] ) - with open(path, 'wb') as certificate_chain_file: + with open(path, 'w') as certificate_chain_file: certificate_chain_file.write(chain_pem) diff --git a/gimmecert/utils.py b/gimmecert/utils.py index 1dabbc3873b59e89b4a2fe78143f68b070346ac3..8ae4d48c7ea16bbeb1e4e0a70827997e0190cb7d 100644 --- a/gimmecert/utils.py +++ b/gimmecert/utils.py @@ -38,12 +38,12 @@ def certificate_to_pem(certificate): :type certificate: cryptography.x509.Certificate :returns: Certificate in OpenSSL-style PEM format. - :rtype: bytes + :rtype: str """ certificate_pem = certificate.public_bytes(encoding=cryptography.hazmat.primitives.serialization.Encoding.PEM) - return certificate_pem + return certificate_pem.decode() def dn_to_str(dn): diff --git a/tests/test_cli.py b/tests/test_cli.py index a549e2352d47052fba327fe4f8f41eb28c0fd5a2..3bd3edca2fce6fb107e93fb4c0fef93bc089d3de 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -211,7 +211,7 @@ def test_setup_subcommand_parser_registered(setup_subcommand_parser): # command from CLI. See test documentation for more details. VALID_CLI_INVOCATIONS = [ # help, no options - ("gimmecert.cli.help", ["gimmecert", "help"]), + ("gimmecert.cli.help_", ["gimmecert", "help"]), # init, no options ("gimmecert.cli.init", ["gimmecert", "init"]), diff --git a/tests/test_storage.py b/tests/test_storage.py index 6c0ede6eac169e614a1253b2236ed7a0964ad84b..23cf3de5394cd04d09b7efdb5a397cc8e30fdc14 100644 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -84,8 +84,8 @@ def test_write_certificate_chain(tmpdir): level1_pem, level2_pem, level3_pem = [gimmecert.utils.certificate_to_pem(certificate) for certificate in certificate_chain] gimmecert.storage.write_certificate_chain(certificate_chain, output_file.strpath) - content = output_file.read(mode='rb') - expected_content = b"%s\n%s\n%s" % (level1_pem, level2_pem, level3_pem) + content = output_file.read(mode='r') + expected_content = "%s\n%s\n%s" % (level1_pem, level2_pem, level3_pem) assert content == expected_content diff --git a/tests/test_utils.py b/tests/test_utils.py index d5d13ebbe5a8a2dca9eba791b7616a1542229b20..1fc1f0d4b4d7cebb00291cc87a7930e13a46b98b 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -39,8 +39,9 @@ def test_certificate_to_pem_returns_valid_pem(): certificate_pem = gimmecert.utils.certificate_to_pem(certificate) - assert isinstance(certificate_pem, bytes) - certificate_from_pem = cryptography.x509.load_pem_x509_certificate(certificate_pem, cryptography.hazmat.backends.default_backend()) # Should not throw + assert isinstance(certificate_pem, str) + certificate_from_pem = cryptography.x509.load_pem_x509_certificate(bytes(certificate_pem, encoding='UTF-8'), + cryptography.hazmat.backends.default_backend()) # Should not throw assert certificate_from_pem.subject == certificate.subject assert certificate_from_pem.issuer == certificate.issuer