|
234 | 234 |
|
235 | 235 | echo "passed: reject port 65536" |
236 | 236 |
|
| 237 | +# Invalid: float port (80.5 as YAML number — rejected by schema) |
| 238 | +echo ' |
| 239 | +apisix: |
| 240 | + stream_proxy: |
| 241 | + tcp: |
| 242 | + - 80.5 |
| 243 | +' > conf/config.yaml |
| 244 | + |
| 245 | +out=$(make init 2>&1 || true) |
| 246 | +if ! echo "$out" | grep "failed to validate"; then |
| 247 | + echo "failed: float port 80.5 should be rejected" |
| 248 | + exit 1 |
| 249 | +fi |
| 250 | + |
| 251 | +echo "passed: reject float port 80.5" |
| 252 | + |
237 | 253 | # Invalid: reversed range |
238 | 254 | echo ' |
239 | 255 | apisix: |
|
370 | 386 |
|
371 | 387 | echo "passed: reject missing port" |
372 | 388 |
|
| 389 | +# Integration test: stream_route with port range (end-to-end traffic verification) |
| 390 | +# Use nginx stream_configuration_snippet to create an inline upstream server |
| 391 | +cat > conf/config.yaml << 'EOF' |
| 392 | +apisix: |
| 393 | + proxy_mode: "http&stream" |
| 394 | + stream_proxy: |
| 395 | + only: false |
| 396 | + tcp: |
| 397 | + - "9100-9102" |
| 398 | +deployment: |
| 399 | + admin: |
| 400 | + admin_key: |
| 401 | + - name: admin |
| 402 | + key: test-port-range-key |
| 403 | + role: admin |
| 404 | +nginx_config: |
| 405 | + stream_configuration_snippet: | |
| 406 | + server { |
| 407 | + listen 9201; |
| 408 | + return "STREAM PORT RANGE OK\n"; |
| 409 | + } |
| 410 | +EOF |
| 411 | + |
| 412 | +make run |
| 413 | +sleep 1 |
| 414 | + |
| 415 | +# Create a stream route targeting the inline upstream |
| 416 | +curl -k -i http://127.0.0.1:9180/apisix/admin/stream_routes/1 \ |
| 417 | + -H 'X-API-KEY: test-port-range-key' -X PUT -d \ |
| 418 | + '{"upstream":{"nodes":{"127.0.0.1:9201":1},"type":"roundrobin"}}' |
| 419 | + |
| 420 | +sleep 1 |
| 421 | + |
| 422 | +# Verify traffic works on ports within the range |
| 423 | +for port in 9100 9101; do |
| 424 | + if ! echo -e "" | nc -w 3 127.0.0.1 $port | grep "STREAM PORT RANGE OK"; then |
| 425 | + echo "failed: stream_route with port range - no response on port $port" |
| 426 | + check_failure |
| 427 | + exit 1 |
| 428 | + fi |
| 429 | +done |
| 430 | + |
| 431 | +make stop |
| 432 | + |
| 433 | +echo "passed: stream_route with port range (end-to-end)" |
| 434 | + |
373 | 435 | echo "All stream port range tests passed." |
0 commit comments