summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMike Milner <mike.milner@canonical.com>2012-01-12 18:51:48 +0100
committerMike Milner <mike.milner@canonical.com>2012-01-12 18:51:48 +0100
commitfb0ff769bdce25497949770d392f43b2888a732b (patch)
tree54f9bdb83d39e1871ea574160d9db4870c400dcb /tests
parent581be44da04ccfff8750b145efedf34f08ed02ac (diff)
downloadvyos-cloud-init-fb0ff769bdce25497949770d392f43b2888a732b.tar.gz
vyos-cloud-init-fb0ff769bdce25497949770d392f43b2888a732b.zip
Add tests for ca-certs handler.
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/test_handler_ca_certs.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/unittests/test_handler_ca_certs.py b/tests/unittests/test_handler_ca_certs.py
new file mode 100644
index 00000000..21eddf18
--- /dev/null
+++ b/tests/unittests/test_handler_ca_certs.py
@@ -0,0 +1,64 @@
+from unittest import TestCase
+from mocker import MockerTestCase
+
+from cloudinit.CloudConfig.cc_ca_certs import handle, write_file
+
+class TestAddCaCerts(MockerTestCase):
+ def setUp(self):
+ super(TestAddCaCerts, self).setUp()
+ self.name = "ca-certs"
+ self.cloud_init = None
+ self.log = None
+ self.args = []
+
+ def test_no_config(self):
+ """Test that no certificate are written if not provided."""
+ config = {"unknown-key": "value"}
+
+ mock = self.mocker.replace(write_file, passthrough=False)
+ self.mocker.replay()
+
+ handle(self.name, config, self.cloud_init, self.log, self.args)
+
+ def test_no_trusted_list(self):
+ """Test that no certificate are written if not provided."""
+ config = {"ca-certs": {}}
+
+ mock = self.mocker.replace(write_file, passthrough=False)
+ self.mocker.replay()
+
+ handle(self.name, config, self.cloud_init, self.log, self.args)
+
+ 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)
+
+ 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)
+
+ 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}}
+
+ mock = self.mocker.replace(write_file, passthrough=False)
+ mock("/usr/share/ca-certificates/cloud-init-provided.crt",
+ cert_file, "root", "root", "644")
+ self.mocker.replay()
+
+ handle(self.name, config, self.cloud_init, self.log, self.args)