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() cc_ca_certs.handle(self.name, config, self.cloud, self.log, self.args)
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() cc_ca_certs.handle(self.name, config, self.cloud, 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"]}} cc_ca_certs.handle(self.name, config, self.cloud, self.log, self.args) self.mock_add.assert_called_once_with(['CERT1']) self.assertEqual(self.mock_update.call_count, 1) self.assertEqual(self.mock_remove.call_count, 1)
def test_single_trusted(self): """Test that a single cert gets passed to add_ca_certs.""" config = {"ca-certs": {"trusted": ["CERT1"]}} cc_ca_certs.handle(self.name, config, self.cloud, self.log, self.args) self.mock_add.assert_called_once_with(['CERT1']) self.assertEqual(self.mock_update.call_count, 1) self.assertEqual(self.mock_remove.call_count, 0)
def test_empty_trusted_list(self): """Test that no certificate are written if 'trusted' list is empty.""" config = {"ca-certs": {"trusted": []}} cc_ca_certs.handle(self.name, config, self.cloud, self.log, self.args) self.assertEqual(self.mock_add.call_count, 0) self.assertEqual(self.mock_update.call_count, 1) self.assertEqual(self.mock_remove.call_count, 0)
def test_empty_trusted_list(self): """Test that no certificate are written if 'trusted' list is empty.""" config = {"ca-certs": {"trusted": []}} cc_ca_certs.handle(self.name, config, self.cloud, self.log, self.args) self.assertEqual(self.mock_add.call_count, 0) self.assertEqual(self.mock_update.call_count, 1) self.assertEqual(self.mock_remove.call_count, 0)
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"]}} cc_ca_certs.handle(self.name, config, self.cloud, self.log, self.args) self.mock_add.assert_called_once_with(['CERT1']) self.assertEqual(self.mock_update.call_count, 1) self.assertEqual(self.mock_remove.call_count, 1)
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}} cc_ca_certs.handle(self.name, config, self.cloud, self.log, self.args) self.assertEqual(self.mock_add.call_count, 0) self.assertEqual(self.mock_update.call_count, 1) self.assertEqual(self.mock_remove.call_count, 0)
def test_remove_default_ca_certs(self): """Test remove_defaults works as expected.""" config = {"ca-certs": {"remove-defaults": True}} cc_ca_certs.handle(self.name, config, self.cloud, self.log, self.args) self.assertEqual(self.mock_add.call_count, 0) self.assertEqual(self.mock_update.call_count, 1) self.assertEqual(self.mock_remove.call_count, 1)
def test_remove_default_ca_certs(self): """Test remove_defaults works as expected.""" config = {"ca-certs": {"remove-defaults": True}} cc_ca_certs.handle(self.name, config, self.cloud, self.log, self.args) self.assertEqual(self.mock_add.call_count, 0) self.assertEqual(self.mock_update.call_count, 1) self.assertEqual(self.mock_remove.call_count, 1)
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() cc_ca_certs.handle(self.name, config, self.cloud, 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"]}} cc_ca_certs.handle(self.name, config, self.cloud, self.log, self.args) self.mock_add.assert_called_once_with(['CERT1', 'CERT2']) self.assertEqual(self.mock_update.call_count, 1) self.assertEqual(self.mock_remove.call_count, 0)
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() cc_ca_certs.handle(self.name, config, self.cloud, 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() cc_ca_certs.handle(self.name, config, self.cloud, 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() cc_ca_certs.handle(self.name, config, self.cloud, 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() cc_ca_certs.handle(self.name, config, self.cloud, 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() cc_ca_certs.handle(self.name, config, self.cloud, self.log, self.args)
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}} cc_ca_certs.handle(self.name, config, self.cloud, self.log, self.args) self.assertEqual(self.mock_add.call_count, 0) self.assertEqual(self.mock_update.call_count, 1) self.assertEqual(self.mock_remove.call_count, 0)
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() cc_ca_certs.handle(self.name, config, self.cloud, 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() cc_ca_certs.handle(self.name, config, self.cloud, self.log, self.args)
def test_no_config(self): """ Test that nothing is done if no ca-certs configuration is provided. """ config = util.get_builtin_cfg() self.mocker.replace(util.write_file, passthrough=False) self.mocker.replace(cc_ca_certs.update_ca_certs, passthrough=False) self.mocker.replay() cc_ca_certs.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 = util.get_builtin_cfg() self.mocker.replace(util.write_file, passthrough=False) self.mocker.replace(cc_ca_certs.update_ca_certs, passthrough=False) self.mocker.replay() cc_ca_certs.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() cc_ca_certs.handle(self.name, config, self.cloud, 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": {}} cc_ca_certs.handle(self.name, config, self.cloud, self.log, self.args) self.assertEqual(self.mock_add.call_count, 0) self.assertEqual(self.mock_update.call_count, 1) self.assertEqual(self.mock_remove.call_count, 0)
def test_remove_default_ca_certs(self): """Test remove_defaults works as expected.""" config = {"ca-certs": {"remove-defaults": True}} for distro_name in cc_ca_certs.distros: self._mock_init() cloud = self._get_cloud(distro_name) cc_ca_certs.handle(self.name, config, cloud, self.log, self.args) self.assertEqual(self.mock_add.call_count, 0) self.assertEqual(self.mock_update.call_count, 1) self.assertEqual(self.mock_remove.call_count, 1)
def test_empty_trusted_list(self): """Test that no certificate are written if 'trusted' list is empty.""" config = {"ca-certs": {"trusted": []}} for distro_name in cc_ca_certs.distros: self._mock_init() cloud = self._get_cloud(distro_name) cc_ca_certs.handle(self.name, config, cloud, self.log, self.args) self.assertEqual(self.mock_add.call_count, 0) self.assertEqual(self.mock_update.call_count, 1) self.assertEqual(self.mock_remove.call_count, 0)
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}} for distro_name in cc_ca_certs.distros: self._mock_init() cloud = self._get_cloud(distro_name) cc_ca_certs.handle(self.name, config, cloud, self.log, self.args) self.assertEqual(self.mock_add.call_count, 0) self.assertEqual(self.mock_update.call_count, 1) self.assertEqual(self.mock_remove.call_count, 0)
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() cc_ca_certs.handle(self.name, config, self.cloud, 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": {}} cc_ca_certs.handle(self.name, config, self.cloud, self.log, self.args) self.assertEqual(self.mock_add.call_count, 0) self.assertEqual(self.mock_update.call_count, 1) self.assertEqual(self.mock_remove.call_count, 0)
def test_multiple_trusted(self): """Test that multiple certs get passed to add_ca_certs.""" config = {"ca-certs": {"trusted": ["CERT1", "CERT2"]}} for distro_name in cc_ca_certs.distros: self._mock_init() cloud = self._get_cloud(distro_name) conf = cc_ca_certs._distro_ca_certs_configs(distro_name) cc_ca_certs.handle(self.name, config, cloud, self.log, self.args) self.mock_add.assert_called_once_with(conf, ['CERT1', 'CERT2']) self.assertEqual(self.mock_update.call_count, 1) self.assertEqual(self.mock_remove.call_count, 0)
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"]}} for distro_name in cc_ca_certs.distros: self._mock_init() cloud = self._get_cloud(distro_name) conf = cc_ca_certs._distro_ca_certs_configs(distro_name) cc_ca_certs.handle(self.name, config, cloud, self.log, self.args) self.mock_add.assert_called_once_with(conf, ['CERT1']) self.assertEqual(self.mock_update.call_count, 1) self.assertEqual(self.mock_remove.call_count, 1)
def test_no_trusted_list(self): """ Test that no certificates are written if the 'trusted' key is not present. """ config = {"ca-certs": {}} for distro_name in cc_ca_certs.distros: self._mock_init() cloud = self._get_cloud(distro_name) cc_ca_certs.handle(self.name, config, cloud, self.log, self.args) self.assertEqual(self.mock_add.call_count, 0) self.assertEqual(self.mock_update.call_count, 1) self.assertEqual(self.mock_remove.call_count, 0)
def test_deprecate_key_warnings(self, update_ca_certs, caplog): """Assert warnings are logged for deprecated keys.""" log = logging.getLogger("CALogTest") cloud = get_cloud("ubuntu") cc_ca_certs.handle("IGNORE", {"ca-certs": { "remove-defaults": False }}, cloud, log, []) expected_warnings = [ "DEPRECATION: key 'ca-certs' is now deprecated. Use 'ca_certs'" " instead.", "DEPRECATION: key 'ca-certs.remove-defaults' is now deprecated." " Use 'ca_certs.remove_defaults' instead.", ] for warning in expected_warnings: assert warning in caplog.text assert 1 == update_ca_certs.call_count
def test_no_config(self): """ Test that nothing is done if no ca-certs configuration is provided. """ config = util.get_builtin_cfg() with ExitStack() as mocks: util_mock = mocks.enter_context( mock.patch.object(util, 'write_file')) certs_mock = mocks.enter_context( mock.patch.object(cc_ca_certs, 'update_ca_certs')) cc_ca_certs.handle(self.name, config, self.cloud_init, self.log, self.args) self.assertEqual(util_mock.call_count, 0) self.assertEqual(certs_mock.call_count, 0)
def test_no_config(self): """ Test that nothing is done if no ca-certs configuration is provided. """ config = util.get_builtin_cfg() with ExitStack() as mocks: util_mock = mocks.enter_context( mock.patch.object(util, 'write_file')) certs_mock = mocks.enter_context( mock.patch.object(cc_ca_certs, 'update_ca_certs')) cc_ca_certs.handle(self.name, config, self.cloud_init, self.log, self.args) self.assertEqual(util_mock.call_count, 0) self.assertEqual(certs_mock.call_count, 0)
def test_duplicate_keys(self, update_ca_certs, caplog): """Assert warnings are logged for deprecated keys.""" log = logging.getLogger("CALogTest") cloud = get_cloud("ubuntu") cc_ca_certs.handle( "IGNORE", { "ca-certs": { "remove-defaults": True }, "ca_certs": { "remove_defaults": False }, }, cloud, log, [], ) expected_warning = ( "Found both ca-certs (deprecated) and ca_certs config keys." " Ignoring ca-certs.") assert expected_warning in caplog.text assert 1 == update_ca_certs.call_count