From 7570874dc3338023062d8c213d61d9de654fcbe4 Mon Sep 17 00:00:00 2001 From: Giorgos Drosos Date: Fri, 25 Jul 2025 13:28:58 +0300 Subject: [PATCH] Reject apk with update cache for empty package names --- plugins/modules/apk.py | 6 +++--- tests/integration/targets/apk/tasks/main.yml | 19 ++++++++++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/plugins/modules/apk.py b/plugins/modules/apk.py index 499fc78ff6..7ad5d5908e 100644 --- a/plugins/modules/apk.py +++ b/plugins/modules/apk.py @@ -351,6 +351,9 @@ def main(): p = module.params + if all(not name.strip() for name in p['name']): + module.fail_json(msg="Package name(s) cannot be empty or whitespace-only") + if p['no_cache']: APK_PATH = "%s --no-cache" % (APK_PATH, ) @@ -371,9 +374,6 @@ def main(): if p['upgrade']: upgrade_packages(module, p['available']) - if all(not name.strip() for name in p['name']): - module.fail_json(msg="Package name(s) cannot be empty or whitespace-only") - if p['state'] in ['present', 'latest']: install_packages(module, p['name'], p['state'], p['world']) elif p['state'] == 'absent': diff --git a/tests/integration/targets/apk/tasks/main.yml b/tests/integration/targets/apk/tasks/main.yml index ada3b13ee9..c800b1fa1c 100644 --- a/tests/integration/targets/apk/tasks/main.yml +++ b/tests/integration/targets/apk/tasks/main.yml @@ -169,7 +169,7 @@ ansible.builtin.assert: that: - result_empty is failed - - "'Package name(s) cannot be empty' in result_empty.msg" + - "'Package name(s) cannot be empty or whitespace-only' == result_empty.msg" - name: Install package name with only spaces community.general.apk: @@ -181,7 +181,7 @@ ansible.builtin.assert: that: - result_spaces is failed - - "'Package name(s) cannot be empty' in result_spaces.msg" + - "'Package name(s) cannot be empty or whitespace-only' == result_spaces.msg" - name: Accept list with valid and empty string community.general.apk: @@ -204,4 +204,17 @@ ansible.builtin.assert: that: - result_multiple_empty is failed - - "'Package name(s) cannot be empty' in result_multiple_empty.msg" + - "'Package name(s) cannot be empty or whitespace-only' == result_multiple_empty.msg" + + - name: Reject empty package name with update_cache parameter + community.general.apk: + name: "" + update_cache: true + register: result_empty_package_with_update_cache + ignore_errors: true + + - name: Assert failure due to all package names being empty or whitespace + ansible.builtin.assert: + that: + - result_empty_package_with_update_cache is failed + - "'Package name(s) cannot be empty or whitespace-only' == result_empty_package_with_update_cache.msg"