Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test fixes for IPv6 #223

Merged
merged 5 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/files/nginx.default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ ssl_certificate_key /root/certs/foobar.key;

server {
listen 80;
listen [::]:80;
server_name localhost;

location / {
Expand Down
5 changes: 3 additions & 2 deletions tests/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
WEB_SERVER = DerivedContainer(
base=LEAP,
containerfile="""
RUN zypper -n in python3 curl && echo "Hello Green World!" > index.html
ENTRYPOINT ["/usr/bin/python3", "-m", "http.server"]
RUN zypper -n in python311 curl && echo "Hello Green World!" > index.html
ENTRYPOINT ["/usr/bin/python3.11", "-m", "http.server", "--bind", "::"]
HEALTHCHECK --interval=5s --timeout=1s CMD curl --fail http://0.0.0.0:8000
EXPOSE 8000
""",
image_format=ImageFormat.DOCKER,
forwarded_ports=[PortForwarding(container_port=8000)],
)

Expand Down
38 changes: 13 additions & 25 deletions tests/test_port_forwarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,9 @@ def test_port_forward_set_up(auto_container: ContainerData, host):
), "host port must be set"

assert (
host.run_expect(
[0],
host.check_output(
f"{_CURL} localhost:{auto_container.forwarded_ports[0].host_port}",
).stdout.strip()
).strip()
== "Hello Green World!"
)

Expand Down Expand Up @@ -161,23 +160,16 @@ def test_multiple_open_ports(container: ContainerData, number: int, host):
container.forwarded_ports[0].protocol == NetworkProtocol.TCP
and container.forwarded_ports[0].container_port == 80
)
assert (
f"Test page {number}"
in host.run_expect(
[0], f"{_CURL} localhost:{container.forwarded_ports[0].host_port}"
).stdout
assert f"Test page {number}" in host.check_output(
f"{_CURL} localhost:{container.forwarded_ports[0].host_port}"
)

assert (
container.forwarded_ports[1].protocol == NetworkProtocol.TCP
and container.forwarded_ports[1].container_port == 443
)
assert (
f"Test page {number}"
in host.run_expect(
[0],
f"curl --insecure https://localhost:{container.forwarded_ports[1].host_port}",
).stdout
assert f"Test page {number}" in host.check_output(
f"curl --insecure https://localhost:{container.forwarded_ports[1].host_port}",
)


Expand Down Expand Up @@ -214,12 +206,12 @@ def test_multiple_open_ports(container: ContainerData, number: int, host):
def test_bind_to_address(addr: str, container: ContainerData, host) -> None:
"""address"""
for host_addr in _ADDRESSES:
cmd = f"{_CURL} http://{host_addr}:{container.forwarded_ports[0].host_port}"
# need to surround a ipv6 address in [] so that it can be distinguished
# from a port
formated_ip = f"[{host_addr}]" if ":" in host_addr else host_addr
cmd = f"{_CURL} http://{formated_ip}:{container.forwarded_ports[0].host_port}"
if addr == host_addr:
assert (
host.run_expect([0], cmd).stdout.strip()
== "Hello Green World!"
)
assert host.check_output(cmd).strip() == "Hello Green World!"
else:
assert host.run_expect([7], cmd)

Expand Down Expand Up @@ -249,9 +241,7 @@ def test_container_bind_to_host_port(

assert launcher.container_data.forwarded_ports[0].host_port == PORT
assert (
host.run_expect(
[0], f"{_CURL} http://localhost:{PORT}"
).stdout.strip()
host.check_output(f"{_CURL} http://localhost:{PORT}").strip()
== "Hello Green World!"
)

Expand Down Expand Up @@ -281,8 +271,6 @@ def test_pod_bind_to_host_port(

assert launcher.pod_data.forwarded_ports[0].host_port == PORT
assert (
host.run_expect(
[0], f"{_CURL} http://localhost:{PORT}"
).stdout.strip()
host.check_output(f"{_CURL} http://localhost:{PORT}").strip()
== "Hello Green World!"
)