mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-29 08:01:24 -07:00
Ensure apk handles empty name strings properly (#10442)
* Ensure apk handles empty name strings * Update changelog * Update tests/integration/targets/apk/tasks/main.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Update changelogs/fragments/10442-apk-fix-empty-names.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Remove redundant conditional * Remove redundant ignore errors * Reject apk with update cache for empty package names --------- Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
fe59c6d29e
commit
3ad57ffa67
3 changed files with 66 additions and 0 deletions
3
changelogs/fragments/10442-apk-fix-empty-names.yml
Normal file
3
changelogs/fragments/10442-apk-fix-empty-names.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
bugfixes:
|
||||||
|
- apk - handle empty name strings properly
|
||||||
|
(https://github.com/ansible-collections/community.general/issues/10441, https://github.com/ansible-collections/community.general/pull/10442).
|
|
@ -351,6 +351,9 @@ def main():
|
||||||
|
|
||||||
p = module.params
|
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']:
|
if p['no_cache']:
|
||||||
APK_PATH = "%s --no-cache" % (APK_PATH, )
|
APK_PATH = "%s --no-cache" % (APK_PATH, )
|
||||||
|
|
||||||
|
|
|
@ -158,3 +158,63 @@
|
||||||
that:
|
that:
|
||||||
- results is not changed
|
- results is not changed
|
||||||
- (results.packages | default([]) | length) == 0
|
- (results.packages | default([]) | length) == 0
|
||||||
|
|
||||||
|
- name: Install package with empty name
|
||||||
|
community.general.apk:
|
||||||
|
name: ""
|
||||||
|
register: result_empty
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: Assert failure due to empty package name
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- result_empty is failed
|
||||||
|
- "'Package name(s) cannot be empty or whitespace-only' == result_empty.msg"
|
||||||
|
|
||||||
|
- name: Install package name with only spaces
|
||||||
|
community.general.apk:
|
||||||
|
name: [" "]
|
||||||
|
register: result_spaces
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: Assert failure due to whitespace-only package name
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- result_spaces is failed
|
||||||
|
- "'Package name(s) cannot be empty or whitespace-only' == result_spaces.msg"
|
||||||
|
|
||||||
|
- name: Accept list with valid and empty string
|
||||||
|
community.general.apk:
|
||||||
|
name: ["busybox", ""]
|
||||||
|
register: result_valid_mixed
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: Assert success with mixed package list
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- result_valid_mixed is not failed
|
||||||
|
|
||||||
|
- name: Reject package name list with multiple empty/whitespace-only strings
|
||||||
|
community.general.apk:
|
||||||
|
name: ["", " "]
|
||||||
|
register: result_multiple_empty
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: Assert failure due to all package names being empty or whitespace
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- result_multiple_empty is failed
|
||||||
|
- "'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"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue