diff options
| author | Michal Nasiadka <mnasiadka@gmail.com> | 2026-01-19 10:14:49 +0100 |
|---|---|---|
| committer | Michal Nasiadka <mnasiadka@gmail.com> | 2026-01-19 10:53:36 +0100 |
| commit | 2ba4a6efdca7f9a1ed00cebc78dba8bb6a510923 (patch) | |
| tree | bb95c951933c5e6f8e0392f008762244b65397a5 | |
| parent | e80dc8332dfe3b2cdfe508c804b894af4952dd62 (diff) | |
| download | kolla-ansible-2ba4a6efdca7f9a1ed00cebc78dba8bb6a510923.tar.gz kolla-ansible-2ba4a6efdca7f9a1ed00cebc78dba8bb6a510923.zip | |
CI: Fix hardcoded passwords check introduced by bandit
Tests had to be a bit refactored due to pep8 E501 (line too long)
See [1].
[1]: https://github.com/PyCQA/bandit/commit/649b9bdf87f4f9d850b29819b14b847bd3b8f970
Change-Id: I99407525546f50c4ff1c0101316485604c83b07f
Signed-off-by: Michal Nasiadka <mnasiadka@gmail.com>
| -rw-r--r-- | ansible/library/kolla_container.py | 2 | ||||
| -rw-r--r-- | tests/kolla_container_tests/test_docker_worker.py | 73 | ||||
| -rw-r--r-- | tests/kolla_container_tests/test_podman_worker.py | 75 |
3 files changed, 90 insertions, 60 deletions
diff --git a/ansible/library/kolla_container.py b/ansible/library/kolla_container.py index c6a0ea5d1..6427ea19a 100644 --- a/ansible/library/kolla_container.py +++ b/ansible/library/kolla_container.py @@ -356,7 +356,7 @@ def generate_module(): common_options_defaults = { 'auth_email': None, - 'auth_password': None, + 'auth_password': None, # nosec B105 'auth_registry': None, 'auth_username': None, 'environment': None, diff --git a/tests/kolla_container_tests/test_docker_worker.py b/tests/kolla_container_tests/test_docker_worker.py index c79022462..26fe020f2 100644 --- a/tests/kolla_container_tests/test_docker_worker.py +++ b/tests/kolla_container_tests/test_docker_worker.py @@ -42,7 +42,7 @@ FAKE_DATA = { 'container_engine': 'docker', 'api_version': None, 'auth_username': None, - 'auth_password': None, + 'auth_password': None, # nosec B105 'auth_registry': None, 'restart_policy': None, 'auth_email': None, @@ -125,7 +125,7 @@ FAKE_DATA = { FAKE_DATA_COMMON_OPTS = { 'auth_username': 'kevko', - 'auth_password': 'SECRET', + 'auth_password': 'SECRET', # nosec B105 'auth_registry': 'Quay.io/kolla', 'restart_policy': 'unless-stopped', 'auth_email': 'kevko@kevko.org', @@ -144,7 +144,7 @@ def get_DockerWorker(mod_param, docker_api_version='1.40'): common_options_defaults = { 'auth_email': None, - 'auth_password': None, + 'auth_password': None, # nosec B105 'auth_registry': None, 'auth_username': None, 'environment': None, @@ -405,10 +405,13 @@ class TestContainer(base.BaseTestCase): self.assertEqual(self.dw.create_volume.call_count, 2) def test_start_container_without_pull(self): - self.fake_data['params'].update({'auth_username': 'fake_user', - 'auth_password': 'fake_psw', - 'auth_registry': 'myrepo/myapp', - 'auth_email': 'fake_mail@foogle.com'}) + params = { + 'auth_username': 'fake_user', + 'auth_password': 'fake_psw', # nosec B105 + 'auth_registry': 'myrepo/myapp', + 'auth_email': 'fake_mail@foogle.com' + } + self.fake_data['params'].update(params) self.dw = get_DockerWorker(self.fake_data['params']) self.dw.dc.images = mock.MagicMock( return_value=self.fake_data['images']) @@ -425,11 +428,14 @@ class TestContainer(base.BaseTestCase): self.dw.create_container.assert_called_once_with() def test_start_container_with_duplicate_name(self): - self.fake_data['params'].update({'name': 'my_container', - 'auth_username': 'fake_user', - 'auth_password': 'fake_psw', - 'auth_registry': 'myrepo/myapp', - 'auth_email': 'fake_mail@foogle.com'}) + params = { + 'name': 'my_container', + 'auth_username': 'fake_user', + 'auth_password': 'fake_psw', # nosec B105 + 'auth_registry': 'myrepo/myapp', + 'auth_email': 'fake_mail@foogle.com' + } + self.fake_data['params'].update(params) self.dw = get_DockerWorker(self.fake_data['params']) self.dw.dc.images = mock.MagicMock( return_value=self.fake_data['images']) @@ -453,11 +459,14 @@ class TestContainer(base.BaseTestCase): self.dw.create_container.assert_called_once_with() def test_start_container(self): - self.fake_data['params'].update({'name': 'my_container', - 'auth_username': 'fake_user', - 'auth_password': 'fake_psw', - 'auth_registry': 'myrepo/myapp', - 'auth_email': 'fake_mail@foogle.com'}) + params = { + 'name': 'my_container', + 'auth_username': 'fake_user', + 'auth_password': 'fake_psw', # nosec B105 + 'auth_registry': 'myrepo/myapp', + 'auth_email': 'fake_mail@foogle.com' + } + self.fake_data['params'].update(params) self.dw = get_DockerWorker(self.fake_data['params']) self.dw.dc.images = mock.MagicMock( return_value=self.fake_data['images']) @@ -497,12 +506,15 @@ class TestContainer(base.BaseTestCase): self.assertEqual(expected, self.dw.result) def test_start_container_no_systemd(self): - self.fake_data['params'].update({'name': 'my_container', - 'restart_policy': 'oneshot', - 'auth_username': 'fake_user', - 'auth_password': 'fake_psw', - 'auth_registry': 'myrepo/myapp', - 'auth_email': 'fake_mail@foogle.com'}) + params = { + 'name': 'my_container', + 'restart_policy': 'oneshot', + 'auth_username': 'fake_user', + 'auth_password': 'fake_psw', # nosec B105 + 'auth_registry': 'myrepo/myapp', + 'auth_email': 'fake_mail@foogle.com' + } + self.fake_data['params'].update(params) self.dw = get_DockerWorker(self.fake_data['params']) self.dw.dc.images = mock.MagicMock( return_value=self.fake_data['images']) @@ -520,11 +532,14 @@ class TestContainer(base.BaseTestCase): self.dw.systemd.start.assert_not_called() def test_start_container_systemd_start_fail(self): - self.fake_data['params'].update({'name': 'my_container', - 'auth_username': 'fake_user', - 'auth_password': 'fake_psw', - 'auth_registry': 'myrepo/myapp', - 'auth_email': 'fake_mail@foogle.com'}) + params = { + 'name': 'my_container', + 'auth_username': 'fake_user', + 'auth_password': 'fake_psw', # nosec B105 + 'auth_registry': 'myrepo/myapp', + 'auth_email': 'fake_mail@foogle.com' + } + self.fake_data['params'].update(params) self.dw = get_DockerWorker(self.fake_data['params']) self.dw.dc.images = mock.MagicMock( return_value=self.fake_data['images']) @@ -944,7 +959,7 @@ class TestImage(base.BaseTestCase): self.dw = get_DockerWorker( {'image': 'myregistrydomain.com:5000/ubuntu:16.04', 'auth_username': 'fake_user', - 'auth_password': 'fake_psw', + 'auth_password': 'fake_psw', # nosec B105 'auth_registry': 'myrepo/myapp', 'auth_email': 'fake_mail@foogle.com' }) diff --git a/tests/kolla_container_tests/test_podman_worker.py b/tests/kolla_container_tests/test_podman_worker.py index b3bfcdce2..55ab5c165 100644 --- a/tests/kolla_container_tests/test_podman_worker.py +++ b/tests/kolla_container_tests/test_podman_worker.py @@ -299,10 +299,13 @@ class TestContainer(base.BaseTestCase): self.assertEqual(self.pw.create_volume.call_count, 2) def test_start_container_without_pull(self): - self.fake_data['params'].update({'auth_username': 'fake_user', - 'auth_password': 'fake_psw', - 'auth_registry': 'myrepo/myapp', - 'auth_email': 'fake_mail@foogle.com'}) + auth_params = { + 'auth_username': 'fake_user', + 'auth_password': 'fake_psw', # nosec B105 + 'auth_registry': 'myrepo/myapp', + 'auth_email': 'fake_mail@foogle.com' + } + self.fake_data['params'].update(auth_params) self.pw = get_PodmanWorker(self.fake_data['params'].copy()) self.pw.pc.images = mock.MagicMock( return_value=self.fake_data['images']) @@ -322,11 +325,14 @@ class TestContainer(base.BaseTestCase): self.pw.create_container.assert_called_once_with() def test_start_container_with_duplicate_name(self): - self.fake_data['params'].update({'name': 'my_container', - 'auth_username': 'fake_user', - 'auth_password': 'fake_psw', - 'auth_registry': 'myrepo/myapp', - 'auth_email': 'fake_mail@foogle.com'}) + auth_params = { + 'name': 'my_container', + 'auth_username': 'fake_user', + 'auth_password': 'fake_psw', # nosec B105 + 'auth_registry': 'myrepo/myapp', + 'auth_email': 'fake_mail@foogle.com' + } + self.fake_data['params'].update(auth_params) self.pw = get_PodmanWorker(self.fake_data['params']) self.pw.pc.images = mock.MagicMock( return_value=self.fake_data['images']) @@ -348,11 +354,13 @@ class TestContainer(base.BaseTestCase): self.pw.create_container.assert_called_once_with() def test_start_container(self): - self.fake_data['params'].update({'name': 'my_container', - 'auth_username': 'fake_user', - 'auth_password': 'fake_psw', - 'auth_registry': 'myrepo/myapp', - 'auth_email': 'fake_mail@foogle.com'}) + auth_params = { + 'auth_username': 'fake_user', + 'auth_password': 'fake_psw', # nosec B105 + 'auth_registry': 'myrepo/myapp', + 'auth_email': 'fake_mail@foogle.com' + } + self.fake_data['params'].update(auth_params) self.pw = get_PodmanWorker(self.fake_data['params']) self.pw.pc.images = mock.MagicMock( return_value=self.fake_data['images']) @@ -403,12 +411,15 @@ class TestContainer(base.BaseTestCase): self.assertEqual(expected, self.pw.result) def test_start_container_no_systemd(self): - self.fake_data['params'].update({'name': 'my_container', - 'restart_policy': 'oneshot', - 'auth_username': 'fake_user', - 'auth_password': 'fake_psw', - 'auth_registry': 'myrepo/myapp', - 'auth_email': 'fake_mail@foogle.com'}) + auth_params = { + 'name': 'my_container', + 'restart_policy': 'oneshot', + 'auth_username': 'fake_user', + 'auth_password': 'fake_psw', # nosec B105 + 'auth_registry': 'myrepo/myapp', + 'auth_email': 'fake_mail@foogle.com' + } + self.fake_data['params'].update(auth_params) self.pw = get_PodmanWorker(self.fake_data['params']) self.pw.pc.images = mock.MagicMock( return_value=self.fake_data['images']) @@ -426,12 +437,14 @@ class TestContainer(base.BaseTestCase): self.pw.systemd.start.assert_not_called() def test_start_container_systemd_start_fail(self): - self.fake_data['params'].update({'name': 'my_container', - 'auth_username': 'fake_user', - 'auth_password': 'fake_psw', - 'auth_registry': 'myrepo/myapp', - 'auth_email': 'fake_mail@foogle.com'} - ) + params = { + 'name': 'my_container', + 'auth_username': 'fake_user', + 'auth_password': 'fake_psw', # nosec B105 + 'auth_registry': 'myrepo/myapp', + 'auth_email': 'fake_mail@foogle.com' + } + self.fake_data['params'].update(params) self.pw = get_PodmanWorker(self.fake_data['params']) self.pw.pc.images = mock.MagicMock( return_value=self.fake_data['images']) @@ -818,7 +831,7 @@ class TestImage(base.BaseTestCase): self.pw = get_PodmanWorker( {'image': 'myregistrydomain.com:5000/ubuntu:16.04', 'auth_username': 'fake_user', - 'auth_password': 'fake_psw', + 'auth_password': 'fake_psw', # nosec B105 'auth_registry': 'myrepo/myapp', 'auth_email': 'fake_mail@foogle.com' }) @@ -832,7 +845,8 @@ class TestImage(base.BaseTestCase): tag='16.04', tls_verify=False, stream=False, - auth_config={'username': 'fake_user', 'password': 'fake_psw'} + auth_config={'username': 'fake_user', + 'password': 'fake_psw'} # nosec B105 ) self.assertTrue(self.pw.changed) @@ -840,7 +854,7 @@ class TestImage(base.BaseTestCase): self.pw = get_PodmanWorker( {'image': 'myregistrydomain.com:5000/ubuntu:16.04', 'auth_username': 'fake_user', - 'auth_password': 'fake_psw', + 'auth_password': 'fake_psw', # nosec B105 'auth_registry': 'myrepo/myapp', 'auth_email': 'fake_mail@foogle.com' }) @@ -854,7 +868,8 @@ class TestImage(base.BaseTestCase): tag='16.04', tls_verify=False, stream=False, - auth_config={'username': 'fake_user', 'password': 'fake_psw'} + auth_config={'username': 'fake_user', + 'password': 'fake_psw'} # nosec B105 ) self.assertFalse(self.pw.changed) |
