File tree Expand file tree Collapse file tree
custom-domain/dstack-ingress/scripts Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -71,6 +71,28 @@ sanitize_dns_label() {
7171 fi
7272}
7373
74+ sanitize_positive_integer () {
75+ local candidate=" $1 "
76+ local name=" ${2:- value} "
77+ if [[ " $candidate " =~ ^[0-9]+$ ]] && (( candidate >= 1 )) ; then
78+ echo " $candidate "
79+ else
80+ echo " Error: Invalid ${name} : $candidate (must be a positive integer)" >&2
81+ return 1
82+ fi
83+ }
84+
85+ sanitize_haproxy_timeout () {
86+ local candidate=" $1 "
87+ local name=" ${2:- timeout} "
88+ if [[ " $candidate " =~ ^[0-9]+ (us| ms| s| m| h| d)? $ ]]; then
89+ echo " $candidate "
90+ else
91+ echo " Error: Invalid ${name} : $candidate (e.g. 10s, 5m, 86400s)" >&2
92+ return 1
93+ fi
94+ }
95+
7496sanitize_proxy_timeout () {
7597 local candidate=" $1 "
7698 if [ -z " $candidate " ]; then
Original file line number Diff line number Diff line change @@ -25,8 +25,11 @@ while true; do
2525 build-combined-pems.sh || echo " Combined PEM build failed"
2626
2727 # Graceful reload: send SIGUSR2 to haproxy master process
28- if ! kill -USR2 " $( cat /var/run/haproxy/haproxy.pid 2> /dev/null) " 2> /dev/null; then
29- echo " HAProxy reload failed" >&2
28+ local pidfile=" /var/run/haproxy/haproxy.pid"
29+ if [ ! -f " $pidfile " ]; then
30+ echo " HAProxy reload failed: PID file $pidfile not found" >&2
31+ elif ! kill -USR2 " $( cat " $pidfile " ) " ; then
32+ echo " HAProxy reload failed: SIGUSR2 to PID $( cat " $pidfile " ) failed" >&2
3033 else
3134 echo " Certificate renewed and HAProxy reloaded successfully"
3235 fi
Original file line number Diff line number Diff line change @@ -36,6 +36,10 @@ BOOT_TIMEOUT="${BOOT_TIMEOUT:-300}"
3636READY_TIMEOUT=" ${READY_TIMEOUT:- 600} "
3737
3838# Derived domains for multi-protocol testing
39+ if [[ " $DOMAIN " == \* * ]]; then
40+ echo " Error: DOMAIN must not be a wildcard for e2e testing (got $DOMAIN )" >&2
41+ exit 1
42+ fi
3943GRPC_DOMAIN=" grpc-${DOMAIN} "
4044
4145CVM_NAME=" ingress-e2e-$( date +%s) "
@@ -147,7 +151,7 @@ DOMAINS_VAL="${DOMAIN},${GRPC_DOMAIN}"
147151ROUTING_MAP_VAL=" ${DOMAIN} =whoami:80,${GRPC_DOMAIN} =grpcbin:9000"
148152
149153log " Deploying CVM: $CVM_NAME "
150- phala deploy \
154+ if ! phala deploy \
151155 -c " $COMPOSE_FILE " \
152156 -n " $CVM_NAME " \
153157 -t " $INSTANCE_TYPE " \
@@ -157,7 +161,10 @@ phala deploy \
157161 -e " GATEWAY_DOMAIN=${GATEWAY_DOMAIN} " \
158162 -e " DOMAINS=${DOMAINS_VAL} " \
159163 -e " ROUTING_MAP=${ROUTING_MAP_VAL} " \
160- --wait
164+ --wait; then
165+ fail " CVM deployment failed"
166+ exit 1
167+ fi
161168
162169log " CVM deployed, waiting for boot..."
163170
Original file line number Diff line number Diff line change @@ -55,6 +55,14 @@ assert_equal "$(sanitize_proxy_timeout 30s)" "30s" "sanitize_proxy_timeout accep
5555assert_equal " $( sanitize_proxy_timeout 5m) " " 5m" " sanitize_proxy_timeout accepts minutes suffix"
5656assert_equal " $( sanitize_proxy_timeout 1h) " " 1h" " sanitize_proxy_timeout accepts hours suffix"
5757assert_equal " $( sanitize_proxy_timeout ' ' ) " " " " sanitize_proxy_timeout accepts empty value"
58+ assert_equal " $( sanitize_positive_integer 4096 MAXCONN) " " 4096" " sanitize_positive_integer accepts 4096"
59+ assert_equal " $( sanitize_positive_integer 1 MAXCONN) " " 1" " sanitize_positive_integer accepts 1"
60+ assert_equal " $( sanitize_haproxy_timeout 10s TIMEOUT_CONNECT) " " 10s" " sanitize_haproxy_timeout accepts 10s"
61+ assert_equal " $( sanitize_haproxy_timeout 86400s TIMEOUT_CLIENT) " " 86400s" " sanitize_haproxy_timeout accepts 86400s"
62+ assert_equal " $( sanitize_haproxy_timeout 5m TIMEOUT) " " 5m" " sanitize_haproxy_timeout accepts 5m"
63+ assert_equal " $( sanitize_haproxy_timeout 500ms TIMEOUT) " " 500ms" " sanitize_haproxy_timeout accepts 500ms"
64+ assert_equal " $( sanitize_haproxy_timeout 100us TIMEOUT) " " 100us" " sanitize_haproxy_timeout accepts 100us"
65+ assert_equal " $( sanitize_haproxy_timeout 1d TIMEOUT) " " 1d" " sanitize_haproxy_timeout accepts 1d"
5866
5967# Failing cases
6068assert_fails " sanitize_port rejects non-numeric" sanitize_port abc
8997fi
9098
9199assert_fails " sanitize_dns_label rejects invalid characters" sanitize_dns_label " bad*label"
100+ assert_fails " sanitize_positive_integer rejects zero" sanitize_positive_integer 0 MAXCONN
101+ assert_fails " sanitize_positive_integer rejects non-numeric" sanitize_positive_integer abc MAXCONN
102+ assert_fails " sanitize_haproxy_timeout rejects bare text" sanitize_haproxy_timeout abc TIMEOUT
92103
93104if [[ $failures -eq 0 ]]; then
94105 echo " All sanitizer tests passed"
You can’t perform that action at this time.
0 commit comments