From dacc7372bf837ebd5d512b0e9de5e314b5f7e586 Mon Sep 17 00:00:00 2001 From: Nikita Stupin <18281368+nikitastupin@users.noreply.github.com> Date: Thu, 8 Jul 2021 13:00:21 +0300 Subject: [PATCH] Implement listing of open ports --- tests/5_container_runtime.sh | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/tests/5_container_runtime.sh b/tests/5_container_runtime.sh index 4b3b09a..e68e8a5 100644 --- a/tests/5_container_runtime.sh +++ b/tests/5_container_runtime.sh @@ -345,8 +345,34 @@ check_5_8() { local check="$id - $desc" starttestjson "$id" "$desc" - note -c "$check" - logcheckresult "NOTE" + fail=0 + open_port_containers="" + for c in $containers; do + ports=$(docker port "$c" | awk '{print $0}' | cut -d ':' -f2) + + for port in $ports; do + if [ -n "$port" ]; then + # If it's the first container, fail the test + if [ $fail -eq 0 ]; then + warn -s "$check" + warn " * Port in use: $port in $c" + open_port_containers="$open_port_containers $c:$port" + fail=1 + continue + fi + warn " * Port in use: $port in $c" + open_port_containers="$open_port_containers $c:$port" + fi + done + done + + # We went through all the containers and found none with open ports + if [ $fail -eq 0 ]; then + pass -s "$check" + logcheckresult "PASS" + return + fi + logcheckresult "WARN" "Containers with open ports" "$open_port_containers" } check_5_9() {