def test_no_remove_defaults_if_false(self): """Test remove_defaults is not called when config value is False""" config = {"ca-certs": {"remove-defaults": False}} self.mock_update() self.mocker.replay() handle(self.name, config, self.cloud_init, self.log, self.args)
def test_remove_default_ca_certs(self): """Test remove_defaults works as expected""" config = {"ca-certs": {"remove-defaults": True}} self.mock_remove() self.mock_update() self.mocker.replay() handle(self.name, config, self.cloud_init, self.log, self.args)
def test_multiple_trusted(self): """Test that multiple certs get passed to add_ca_certs""" config = {"ca-certs": {"trusted": ["CERT1", "CERT2"]}} self.mock_add(["CERT1", "CERT2"]) self.mock_update() self.mocker.replay() handle(self.name, config, self.cloud_init, self.log, self.args)
def test_empty_trusted_list(self): """Test that no certificate are written if 'trusted' list is empty""" config = {"ca-certs": {"trusted": []}} # No functions should be called self.mock_update() self.mocker.replay() handle(self.name, config, self.cloud_init, self.log, self.args)
def test_correct_order_for_remove_then_add(self): """Test remove_defaults is not called when config value is False""" config = {"ca-certs": {"remove-defaults": True, "trusted": ["CERT1"]}} self.mock_remove() self.mock_add(["CERT1"]) self.mock_update() self.mocker.replay() handle(self.name, config, self.cloud_init, self.log, self.args)
def test_no_config(self): """ Test that nothing is done if no ca-certs configuration is provided. """ config = {"unknown-key": "value"} self.mocker.replace(write_file, passthrough=False) self.mocker.replace(update_ca_certs, 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 certificates are written if the 'trusted' key is not present. """ config = {"ca-certs": {}} # No functions should be called self.mock_update() self.mocker.replay() handle(self.name, config, self.cloud_init, self.log, self.args)