diff options
author | Mike Milner <mike.milner@canonical.com> | 2012-01-14 10:49:09 +0000 |
---|---|---|
committer | Mike Milner <mike.milner@canonical.com> | 2012-01-14 10:49:09 +0000 |
commit | 094e915e91186401ebc7c97564917334faade150 (patch) | |
tree | 323bf15f4f49ca76dea569505ddf6293426a1204 /tests | |
parent | a717e4f8b9210374edcc9053ca6ff980cb0cefff (diff) | |
download | vyos-cloud-init-094e915e91186401ebc7c97564917334faade150.tar.gz vyos-cloud-init-094e915e91186401ebc7c97564917334faade150.zip |
Factor out writing of certificates.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unittests/test_handler_ca_certs.py | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/tests/unittests/test_handler_ca_certs.py b/tests/unittests/test_handler_ca_certs.py index 254c8727..7c0197ed 100644 --- a/tests/unittests/test_handler_ca_certs.py +++ b/tests/unittests/test_handler_ca_certs.py @@ -1,7 +1,7 @@ from unittest import TestCase from mocker import MockerTestCase -from cloudinit.CloudConfig.cc_ca_certs import handle, write_file, update_ca_certs +from cloudinit.CloudConfig.cc_ca_certs import handle, write_file, update_ca_certs, add_ca_certs class TestNoConfig(MockerTestCase): def setUp(self): @@ -24,9 +24,9 @@ class TestNoConfig(MockerTestCase): handle(self.name, config, self.cloud_init, self.log, self.args) -class TestAddCaCerts(MockerTestCase): +class TestConfig(MockerTestCase): def setUp(self): - super(TestAddCaCerts, self).setUp() + super(TestConfig, self).setUp() self.name = "ca-certs" self.cloud_init = None self.log = None @@ -46,39 +46,37 @@ class TestAddCaCerts(MockerTestCase): handle(self.name, config, self.cloud_init, self.log, self.args) + +class TestAddCaCerts(MockerTestCase): def test_no_certs_in_list(self): """Test that no certificate are written if not provided.""" - config = {"ca-certs": {"trusted": []}} - mock = self.mocker.replace(write_file, passthrough=False) self.mocker.replay() - handle(self.name, config, self.cloud_init, self.log, self.args) + add_ca_certs([]) def test_single_cert(self): """Test adding a single certificate to the trusted CAs""" cert = "CERT1\nLINE2\nLINE3" - config = {"ca-certs": {"trusted": cert}} mock = self.mocker.replace(write_file, passthrough=False) mock("/usr/share/ca-certificates/cloud-init-provided.crt", cert, "root", "root", "644") self.mocker.replay() - handle(self.name, config, self.cloud_init, self.log, self.args) + add_ca_certs([cert]) def test_multiple_certs(self): """Test adding multiple certificate to the trusted CAs""" certs = ["CERT1\nLINE2\nLINE3", "CERT2\nLINE2\nLINE3"] - cert_file = "\n".join(certs) - config = {"ca-certs": {"trusted": certs}} + expected_cert_file = "\n".join(certs) mock = self.mocker.replace(write_file, passthrough=False) mock("/usr/share/ca-certificates/cloud-init-provided.crt", - cert_file, "root", "root", "644") + expected_cert_file, "root", "root", "644") self.mocker.replay() - handle(self.name, config, self.cloud_init, self.log, self.args) + add_ca_certs(certs) class TestUpdateCaCerts(MockerTestCase): def test_commands(self): |