mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-03 12:44:22 -07:00
Ensure apk handles empty name strings
This commit is contained in:
parent
01f3248a12
commit
863c11b536
2 changed files with 55 additions and 0 deletions
|
@ -371,6 +371,12 @@ def main():
|
|||
if p['upgrade']:
|
||||
upgrade_packages(module, p['available'])
|
||||
|
||||
if all(not name.strip() for name in p['name']):
|
||||
if len(p['name']) == 1:
|
||||
module.fail_json(msg="Package name cannot be empty or whitespace-only")
|
||||
else:
|
||||
module.fail_json(msg="Package names 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':
|
||||
|
|
|
@ -158,3 +158,52 @@
|
|||
that:
|
||||
- results is not changed
|
||||
- (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 cannot be empty' in 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 cannot be empty' in 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
|
||||
- "'All package names are empty or whitespace' in result_multiple_empty.msg"
|
||||
ignore_errors: true
|
Loading…
Add table
Add a link
Reference in a new issue