From 64e449c133929aa6a23a13d617c685a09fed3017 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 6 Jun 2022 20:26:26 +0100 Subject: [PATCH] fix [this code smell](https://sonarcloud.io/project/issues?pullRequest=1106&issues=AYE6byrIbM3H9G6ifn9K&open=AYE6byrIbM3H9G6ifn9K&id=pi-hole_docker-pi-hole) Signed-off-by: Adam Warner --- test/test_bash_functions.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/test_bash_functions.py b/test/test_bash_functions.py index 02d0bd8..9ab0b7e 100644 --- a/test/test_bash_functions.py +++ b/test/test_bash_functions.py @@ -178,9 +178,12 @@ def test_debian_setup_php_env(Docker, expected_lines, repeat_function): assert False, f'Found line {expected_line} times (more than once): {found_lines}' +WEBPASSWORD_TEST_FUNCTION_COMMAND='. /bash_functions.sh ; eval `grep setup_web_password /start.sh`' + + def test_webPassword_random_generation(Docker): ''' When a user sets webPassword env the admin password gets set to that ''' - function = Docker.run('. /bash_functions.sh ; eval `grep setup_web_password /start.sh`') + function = Docker.run(WEBPASSWORD_TEST_FUNCTION_COMMAND) assert 'assigning random password' in function.stdout.lower() @@ -191,7 +194,7 @@ def test_webPassword_random_generation(Docker): ]) def test_webPassword_env_assigns_password_to_file_or_removes_if_empty(Docker, args_env, secure, setupVarsHash): ''' When a user sets webPassword env the admin password gets set or removed if empty ''' - function = Docker.run('. /bash_functions.sh ; eval `grep setup_web_password /start.sh`') + function = Docker.run(WEBPASSWORD_TEST_FUNCTION_COMMAND) if secure: assert 'new password set' in function.stdout.lower() @@ -205,7 +208,7 @@ def test_webPassword_env_assigns_password_to_file_or_removes_if_empty(Docker, ar @pytest.mark.parametrize('test_args', ['-e WEBPASSWORD=login', '-e WEBPASSWORD=""']) def test_env_always_updates_password(Docker, args_env, test_args): '''When a user sets the WEBPASSWORD environment variable, ensure it always sets the password''' - function = Docker.run('. /bash_functions.sh ; eval `grep setup_web_password /start.sh`') + function = Docker.run(WEBPASSWORD_TEST_FUNCTION_COMMAND) assert '::: Assigning password defined by Environment Variable' in function.stdout @@ -214,7 +217,7 @@ def test_env_always_updates_password(Docker, args_env, test_args): def test_setupvars_trumps_random_password_if_set(Docker, args_env, test_args): '''If a password is already set in setupVars, and no password is set in the environment variable, do not generate a random password''' Docker.run('. /opt/pihole/utils.sh ; addOrEditKeyValPair /etc/pihole/setupVars.conf WEBPASSWORD volumepass') - function = Docker.run('. /bash_functions.sh ; eval `grep setup_web_password /start.sh`') + function = Docker.run(WEBPASSWORD_TEST_FUNCTION_COMMAND) assert 'Pre existing WEBPASSWORD found' in function.stdout assert Docker.run('grep -q \'{}\' {}'.format('WEBPASSWORD=volumepass', '/etc/pihole/setupVars.conf')).rc == 0