From e41371802f469e7aa701792a157a3860fe875ef6 Mon Sep 17 00:00:00 2001 From: Chris MacNaughton Date: Fri, 26 Oct 2018 12:39:02 +0200 Subject: [PATCH] Use bytes instead of str for writing SSL files Change-Id: I74930cf363fe652a34d7ad86cdc493b15557ed40 Closes-Bug: #1799877 --- hooks/horizon_contexts.py | 4 ++-- unit_tests/test_horizon_contexts.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hooks/horizon_contexts.py b/hooks/horizon_contexts.py index 4577729f..8b20c910 100644 --- a/hooks/horizon_contexts.py +++ b/hooks/horizon_contexts.py @@ -248,9 +248,9 @@ class ApacheSSLContext(OSContextGenerator): ssl_cert, ssl_key = get_cert() if all([ssl_cert, ssl_key]): - with open('/etc/ssl/certs/dashboard.cert', 'w') as cert_out: + with open('/etc/ssl/certs/dashboard.cert', 'wb') as cert_out: cert_out.write(b64decode(ssl_cert)) - with open('/etc/ssl/private/dashboard.key', 'w') as key_out: + with open('/etc/ssl/private/dashboard.key', 'wb') as key_out: key_out.write(b64decode(ssl_key)) os.chmod('/etc/ssl/private/dashboard.key', 0o600) ctxt = { diff --git a/unit_tests/test_horizon_contexts.py b/unit_tests/test_horizon_contexts.py index b366e60e..84deafaf 100644 --- a/unit_tests/test_horizon_contexts.py +++ b/unit_tests/test_horizon_contexts.py @@ -108,8 +108,8 @@ class TestHorizonContexts(CharmTestCase): 'ssl_cert': '/etc/ssl/certs/dashboard.cert', 'ssl_key': '/etc/ssl/private/dashboard.key'}) _open.assert_has_calls([ - call('/etc/ssl/certs/dashboard.cert', 'w'), - call('/etc/ssl/private/dashboard.key', 'w') + call('/etc/ssl/certs/dashboard.cert', 'wb'), + call('/etc/ssl/private/dashboard.key', 'wb') ]) _file.write.assert_has_calls([ call('cert'),