def test_single_cert(self): """Test adding a single certificate to the trusted CAs""" cert = "CERT1\nLINE2\nLINE3" mock_write = self.mocker.replace(write_file, passthrough=False) mock_write("/usr/share/ca-certificates/cloud-init-ca-certs.crt", cert, mode=0644) mock_write("/etc/ca-certificates.conf", "\ncloud-init-ca-certs.crt", omode="a") self.mocker.replay() add_ca_certs([cert])
def test_multiple_certs(self): """Test adding multiple certificates to the trusted CAs""" certs = ["CERT1\nLINE2\nLINE3", "CERT2\nLINE2\nLINE3"] expected_cert_file = "\n".join(certs) mock_write = self.mocker.replace(write_file, passthrough=False) mock_write("/usr/share/ca-certificates/cloud-init-ca-certs.crt", expected_cert_file, mode=0644) mock_write("/etc/ca-certificates.conf", "\ncloud-init-ca-certs.crt", omode="a") self.mocker.replay() add_ca_certs(certs)
def test_no_certs_in_list(self): """Test that no certificate are written if not provided.""" self.mocker.replace(write_file, passthrough=False) self.mocker.replay() add_ca_certs([])