docker_container: fail if there are too many parts in a parsed port (#367)

* Fail if there are too many parts in a parsed port.

* Add tests.

* Prevent bad parsing.
This commit is contained in:
Felix Fontein
2022-05-22 17:20:05 +02:00
committed by GitHub
parent ab2d33aa99
commit 401a76ff00
3 changed files with 51 additions and 0 deletions
@@ -7,6 +7,52 @@
set_fact:
cnames: "{{ cnames + [cname, cname2] }}"
####################################################################
## published_ports: error handling #################################
####################################################################
- name: published_ports -- non-closing square bracket
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
published_ports:
- "[::1:2000:3000"
register: published_ports_1
ignore_errors: true
- name: published_ports -- forgot square brackets for IPv6
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
published_ports:
- "::1:2000:3000"
register: published_ports_2
ignore_errors: true
- name: published_ports -- disallow hostnames
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
published_ports:
- "foo:2000:3000"
register: published_ports_3
ignore_errors: true
- assert:
that:
- published_ports_1 is failed
- published_ports_1.msg == 'Cannot find closing "]" in input "[::1:2000:3000" for opening "[" at index 1!'
- published_ports_2 is failed
- published_ports_2.msg == 'Invalid port description "::1:2000:3000" - expected 1 to 3 colon-separated parts, but got 5. Maybe you forgot to use square brackets ([...]) around an IPv6 address?'
- published_ports_3 is failed
- "published_ports_3.msg == 'Bind addresses for published ports must be IPv4 or IPv6 addresses, not hostnames. Use the dig lookup to resolve hostnames. (Found hostname: foo)'"
####################################################################
## published_ports: all ############################################
####################################################################