Skip to content

Commit 1c303ff

Browse files
committed
ci: add port-allowlist test for networking-py
Signed-off-by: danbugs <danilochiarlone@gmail.com>
1 parent 987faa1 commit 1c303ff

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

.github/workflows/test-examples.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ jobs:
237237
memory: "512Mi"
238238
args: "--net -- /urllib_get.py"
239239
expect: "SUCCESS: urllib GET worked!"
240+
- example: networking-py
241+
memory: "512Mi"
242+
args: "--port 8080 -- /echo_server_test.py"
243+
expect: "SUCCESS: bind\\+listen on port 8080 allowed"
240244
steps:
241245
- uses: actions/checkout@v4
242246

@@ -569,6 +573,10 @@ jobs:
569573
memory: "512Mi"
570574
args: "--net -- /urllib_get.py"
571575
expect: "SUCCESS: urllib GET worked!"
576+
- example: networking-py
577+
memory: "512Mi"
578+
args: "--port 8080 -- /echo_server_test.py"
579+
expect: "SUCCESS: bind\\+listen on port 8080 allowed"
572580
steps:
573581
- uses: actions/checkout@v4
574582

examples/networking-py/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ COPY http_get.py /http_get.py
99
COPY echo_server.py /echo_server.py
1010
COPY urllib_get.py /urllib_get.py
1111
COPY https_test.py /https_test.py
12+
COPY echo_server_test.py /echo_server_test.py
1213

1314
# --- CPIO rootfs builder ---
1415
FROM alpine:3.20 AS cpio
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""Test that --port allows bind+listen and no --port would reject it.
2+
3+
This is a run-to-completion test for CI: it binds, listens, then exits.
4+
The fact that bind+listen succeed (instead of raising OSError) proves
5+
the --port allowlist is working.
6+
"""
7+
import socket
8+
9+
HOST = "0.0.0.0"
10+
PORT = 8080
11+
12+
srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
13+
srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
14+
srv.bind((HOST, PORT))
15+
srv.listen(1)
16+
srv.close()
17+
print("SUCCESS: bind+listen on port 8080 allowed")

0 commit comments

Comments
 (0)