-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathtest_cloudproxy.sh
executable file
·692 lines (561 loc) · 24.6 KB
/
test_cloudproxy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
#!/bin/bash
set -e
#########################################################################
# CloudProxy End-to-End Test Script
#########################################################################
# This script performs end-to-end testing of CloudProxy in a Docker container.
# It tests API endpoints, proxy creation, and optional connectivity testing.
#
# The script will:
# 1. Build a Docker container with CloudProxy
# 2. Test all API endpoints
# 3. Scale providers up to create proxies
# 4. Test connectivity through a random proxy (optional)
# 5. Test deletion and restart functionality
# 6. Clean up all resources (optional)
#
# Important: This script uses real cloud provider credentials from your
# environment variables or .env file to create actual proxy instances.
# Make sure you understand the potential costs before running.
#########################################################################
# Define colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Utility functions for formatting output
print_header() {
echo -e "\n${BLUE}========== $1 ==========${NC}\n"
}
print_info() {
echo -e "${YELLOW}[INFO] $1${NC}"
}
print_success() {
echo -e "${GREEN}[SUCCESS] $1${NC}"
}
print_error() {
echo -e "${RED}[ERROR] $1${NC}" >&2
}
print_warning() {
echo -e "${YELLOW}[WARNING] $1${NC}"
}
# Default configuration
AUTO_CLEANUP=${AUTO_CLEANUP:-true}
SKIP_CONNECTION_TEST=${SKIP_CONNECTION_TEST:-false}
PROXY_WAIT_TIME=${PROXY_WAIT_TIME:-30}
MAX_WAIT_TIME=${MAX_WAIT_TIME:-600} # 10 minutes maximum wait time
# Process command-line arguments
for arg in "$@"; do
case $arg in
--no-cleanup)
AUTO_CLEANUP=false
shift
;;
--skip-connection-test)
SKIP_CONNECTION_TEST=true
shift
;;
--proxy-wait=*)
PROXY_WAIT_TIME="${arg#*=}"
shift
;;
--help)
echo "Usage: $0 [OPTIONS]"
echo "Options:"
echo " --no-cleanup Don't automatically clean up resources"
echo " --skip-connection-test Skip testing proxy connectivity"
echo " --proxy-wait=SECONDS Wait time for proxy initialization (default: 30)"
echo " --help Show this help message"
exit 0
;;
esac
done
# Function to check required environment variables
check_required_env() {
local missing_vars=0
for var in "$@"; do
if [ -z "${!var}" ]; then
echo "ERROR: Required environment variable $var is not set."
missing_vars=$((missing_vars + 1))
fi
done
if [ $missing_vars -gt 0 ]; then
echo "Make sure to set these environment variables before running the script."
echo "You can create a .env file in the project root with these variables."
exit 1
fi
}
# Function to mask sensitive values in output
mask_value() {
local value=$1
if [ ${#value} -le 4 ]; then
echo "****"
else
local visible_start=${2:-4}
local visible_end=${3:-0}
local length=${#value}
local masked_length=$((length - visible_start - visible_end))
if [ $masked_length -le 0 ]; then
echo "****"
else
echo "${value:0:visible_start}$(printf '%*s' $masked_length | tr ' ' '*')${value:$((length - visible_end)):visible_end}"
fi
fi
}
# Check if .env file exists and load it
if [ -f .env ]; then
echo "Loading environment variables from .env file..."
export $(grep -v '^#' .env | xargs)
fi
# ANSI color codes for better output readability
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Function to print section headers
print_header() {
echo -e "\n${BLUE}===================================================${NC}"
echo -e "${BLUE} $1${NC}"
echo -e "${BLUE}===================================================${NC}\n"
}
# Function to print success messages
print_success() {
echo -e "${GREEN}✓ $1${NC}"
}
# Function to print info messages
print_info() {
echo -e "${YELLOW}ℹ $1${NC}"
}
# Function to print error messages
print_error() {
echo -e "${RED}✗ $1${NC}"
}
# Check for required environment variables
print_header "CHECKING ENVIRONMENT"
# Check auth settings
if [[ -z "$PROXY_USERNAME" || -z "$PROXY_PASSWORD" ]]; then
print_info "Proxy authentication not set. Authentication will be disabled."
else
print_info "Proxy authentication set with username: ${PROXY_USERNAME:0:2}****"
fi
# Check required variables for cloud providers
required_vars=()
# Check cloud provider credentials
if [ "${DIGITALOCEAN_ENABLED:-true}" = "true" ]; then
required_vars+=("DIGITALOCEAN_ACCESS_TOKEN")
fi
if [ "${AWS_ENABLED:-true}" = "true" ]; then
required_vars+=("AWS_ACCESS_KEY_ID" "AWS_SECRET_ACCESS_KEY")
fi
if [ "${GCP_ENABLED:-false}" = "true" ]; then
required_vars+=("GCP_SERVICE_ACCOUNT")
fi
if [ "${HETZNER_ENABLED:-false}" = "true" ]; then
required_vars+=("HETZNER_TOKEN")
fi
if [ "${AZURE_ENABLED:-false}" = "true" ]; then
required_vars+=("AZURE_CLIENT_ID" "AZURE_CLIENT_SECRET" "AZURE_TENANT_ID" "AZURE_SUBSCRIPTION_ID")
fi
# Check all the variables
for var in "${required_vars[@]}"; do
if [ -z "${!var}" ]; then
print_error "Required variable $var is not set or empty"
else
print_success "$var is set"
fi
done
# Function to make API calls and format the output with jq
call_api() {
local method=$1
local endpoint=$2
local data=$3
local description=$4
echo -e "${YELLOW}$description...${NC}"
if [ -z "$data" ]; then
# GET or DELETE request without body
response=$(curl -s -X $method "http://localhost:8000$endpoint" -H "accept: application/json")
else
# POST, PUT or PATCH request with JSON body
response=$(curl -s -X $method "http://localhost:8000$endpoint" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-d "$data")
fi
# Check if response is valid JSON
if echo "$response" | jq -e . >/dev/null 2>&1; then
echo "$response" | jq .
print_success "API call completed successfully"
else
print_error "Failed to parse response as JSON"
echo "$response"
return 1
fi
echo ""
}
# Function to test if a proxy is actually usable
test_proxy_connection() {
local proxy_ip=$1
local proxy_port=${2:-8899}
local description=${3:-"Testing proxy connection"}
local max_retries=${4:-5}
local retry_delay=${5:-10}
# Get auth configuration
local auth_config=$(curl -s -X GET "http://localhost:8000/auth" -H "accept: application/json")
local no_auth=$(echo "$auth_config" | jq -r '.no_auth')
local proxy_url
if [ "$no_auth" = "true" ]; then
proxy_url="http://${proxy_ip}:${proxy_port}"
else
local username=$(echo "$auth_config" | jq -r '.auth.username')
local password=$(echo "$auth_config" | jq -r '.auth.password')
proxy_url="http://${username}:${password}@${proxy_ip}:${proxy_port}"
fi
echo -e "${YELLOW}${description} (${proxy_url})...${NC}"
# Try multiple times with a delay, as proxies might take time to be fully operational
for ((i=1; i<=$max_retries; i++)); do
echo -e "${YELLOW}Attempt $i of $max_retries${NC}"
# Use curl to test proxy connectivity
echo -e "${YELLOW}Testing proxy connectivity...${NC}"
http_test=$(curl -s --connect-timeout 10 -m 20 -x "$proxy_url" http://httpbin.org/ip)
http_success=$?
# Check connectivity result
if [[ $http_success -eq 0 && -n "$http_test" ]]; then
echo -e "${GREEN}Connectivity test successful: $(echo $http_test | jq .)${NC}"
print_success "Proxy is operational"
return 0
else
echo -e "${RED}Connectivity test failed${NC}"
# If we haven't returned yet, we'll try again
if [[ $i -lt $max_retries ]]; then
echo -e "${YELLOW}Waiting ${retry_delay}s before next attempt...${NC}"
sleep $retry_delay
fi
fi
done
echo -e "${RED}Failed to establish proxy connectivity after $max_retries attempts${NC}"
return 1
}
# Function to wait for proxies to be created
wait_for_proxies() {
local expected_count=$1
local max_wait=${2:-$MAX_WAIT_TIME}
local wait_interval=${3:-10}
local elapsed=0
local count=0
print_info "Waiting for $expected_count proxies to be available (timeout: ${max_wait}s)..."
while [ $elapsed -lt $max_wait ]; do
local response=$(curl -s -X GET "http://localhost:8000/" -H "accept: application/json")
count=$(echo "$response" | jq -r '.total')
print_info "Current proxy count: $count / $expected_count (elapsed: ${elapsed}s)"
if [ "$count" -ge "$expected_count" ]; then
print_success "All expected proxies are now available!"
echo "$response" | jq '.proxies'
return 0
fi
sleep $wait_interval
elapsed=$((elapsed + wait_interval))
done
print_error "Timed out waiting for proxies to be created. Only $count of $expected_count available after ${elapsed}s."
return 1
}
# Function to wait for proxies to be destroyed
wait_for_proxies_destroyed() {
local max_wait=${1:-$MAX_WAIT_TIME}
local wait_interval=${2:-10}
local elapsed=0
print_info "Waiting for all proxies to be destroyed (timeout: ${max_wait}s)..."
while [ $elapsed -lt $max_wait ]; do
local response=$(curl -s -X GET "http://localhost:8000/" -H "accept: application/json")
local count=$(echo "$response" | jq -r '.total')
if [ "$count" -eq 0 ]; then
print_success "All proxies have been successfully destroyed!"
# Double-check with provider endpoints to confirm
print_info "Verifying with provider endpoints..."
local provider_counts=()
# Check each provider
for provider in digitalocean aws hetzner; do
local provider_info=$(curl -s -X GET "http://localhost:8000/providers/$provider" -H "accept: application/json")
local enabled=$(echo "$provider_info" | jq -r '.provider.enabled')
if [ "$enabled" = "true" ]; then
local running=$(echo "$provider_info" | jq -r '.provider.running')
provider_counts+=("$provider:$running")
if [ "$running" -gt 0 ]; then
print_warning "Provider $provider still reports $running running instances"
else
print_success "Provider $provider confirms 0 running instances"
fi
fi
done
# If any provider still shows instances, we need to wait longer
if [[ "${provider_counts[*]}" =~ ":0" ]]; then
return 0
else
print_info "Some providers still report instances, continuing to wait..."
fi
fi
print_info "Remaining proxies: $count (elapsed: ${elapsed}s)"
local proxies=$(echo "$response" | jq -r '.proxies[].ip')
if [ -n "$proxies" ]; then
print_info "Destroying remaining proxies..."
for ip in $proxies; do
call_api "DELETE" "/destroy?ip_address=$ip" "" "Destroying proxy $ip"
done
# If we've been waiting a while and still have proxies, try checking each provider directly
if [ $elapsed -gt 120 ]; then
print_info "Elapsed time > 120s, checking providers directly..."
# Force a provider check cycle
call_api "GET" "/providers/digitalocean" "" "Forcing DigitalOcean provider check"
call_api "GET" "/providers/aws" "" "Forcing AWS provider check"
call_api "GET" "/providers/hetzner" "" "Forcing Hetzner provider check"
# Wait for the provider checks to complete
sleep 15
fi
fi
sleep $wait_interval
elapsed=$((elapsed + wait_interval))
done
print_error "Timed out waiting for proxies to be destroyed. Still have $count proxies after ${elapsed}s."
return 1
}
# Function to ensure cloud provider deletion queues are processed
ensure_cloud_provider_cleanup() {
local verification_wait=${1:-60} # Wait time in seconds to allow cloud providers to process deletions
local providers_check_interval=${2:-15} # Interval to check providers
print_info "Ensuring cloud providers have processed all deletion requests..."
# First, check the destroy queue to see if there are pending operations
local destroy_queue=$(curl -s -X GET "http://localhost:8000/destroy" -H "accept: application/json")
local queue_count=$(echo "$destroy_queue" | jq -r '.total')
if [ "$queue_count" -gt 0 ]; then
print_info "Found $queue_count items in destroy queue. Waiting for processing..."
# Check destroy queue periodically
local elapsed=0
local wait_interval=10
while [ $elapsed -lt $MAX_WAIT_TIME ]; do
sleep $wait_interval
elapsed=$((elapsed + wait_interval))
destroy_queue=$(curl -s -X GET "http://localhost:8000/destroy" -H "accept: application/json")
queue_count=$(echo "$destroy_queue" | jq -r '.total')
print_info "Destroy queue items: $queue_count (elapsed: ${elapsed}s)"
if [ "$queue_count" -eq 0 ]; then
print_success "Destroy queue is empty!"
break
fi
done
else
print_success "Destroy queue is empty"
fi
# Now, give cloud providers time to process the deletion requests
print_info "Waiting ${verification_wait}s for cloud providers to process deletion requests..."
sleep $verification_wait
# Check providers to ensure no instances are running
print_info "Verifying no instances are running with providers..."
local providers=("digitalocean" "aws" "hetzner")
for provider in "${providers[@]}"; do
local provider_info=$(curl -s -X GET "http://localhost:8000/providers/$provider" -H "accept: application/json")
local enabled=$(echo "$provider_info" | jq -r '.provider.enabled')
if [ "$enabled" = "true" ]; then
local count=$(echo "$provider_info" | jq -r '.provider.running')
if [ "$count" -gt 0 ]; then
print_error "Provider $provider still reports $count running instances"
else
print_success "Provider $provider reports 0 running instances"
fi
fi
done
# Final verification by checking API again
local final_check=$(curl -s -X GET "http://localhost:8000/" -H "accept: application/json")
local final_count=$(echo "$final_check" | jq -r '.total')
if [ "$final_count" -eq 0 ]; then
print_success "Final verification: All proxies successfully destroyed!"
return 0
else
print_error "Final verification: Still found $final_count proxies!"
return 1
fi
}
# Step 1: Build the Docker container
print_header "BUILDING DOCKER CONTAINER"
docker build -t cloudproxy:test .
print_success "Docker image built successfully"
# Step 2: Check for and clean up any existing containers
print_header "CLEANING UP EXISTING CONTAINERS"
if docker ps -a | grep -q cloudproxy-test; then
print_info "Found existing cloudproxy-test container, removing..."
docker rm -f cloudproxy-test
print_success "Removed existing container"
else
print_info "No existing cloudproxy-test container found"
fi
# Step 3: Run the Docker container
print_header "STARTING CLOUDPROXY CONTAINER"
docker run -d --name cloudproxy-test -p 8000:8000 --env-file .env cloudproxy:test
print_success "Container started"
# Wait for the container to initialize
print_info "Waiting for container to initialize..."
sleep 5
# Check if container is still running
if ! docker ps | grep -q cloudproxy-test; then
print_error "Container failed to start or crashed. Showing logs:"
docker logs cloudproxy-test
exit 1
fi
# Step 4: Show container logs
print_header "CONTAINER LOGS"
docker logs cloudproxy-test
# Step 5: Begin API testing
print_header "TESTING CLOUDPROXY API"
# Test 1: List initial proxies
call_api "GET" "/" "" "Listing initial proxies"
# Test 2: Check providers
call_api "GET" "/providers" "" "Checking all providers"
# Test 3: Get auth configuration
call_api "GET" "/auth" "" "Checking authentication configuration"
# Test 4: Try to get a random proxy (may not have proxies yet)
call_api "GET" "/random" "" "Getting a random proxy"
# Test 5: Update DigitalOcean scaling
call_api "PATCH" "/providers/digitalocean" '{"min_scaling": 3, "max_scaling": 5}' "Updating DigitalOcean scaling"
# Test 6: Update AWS scaling
call_api "PATCH" "/providers/aws" '{"min_scaling": 3, "max_scaling": 4}' "Updating AWS scaling"
# Test 7: Update Hetzner scaling
call_api "PATCH" "/providers/hetzner" '{"min_scaling": 3, "max_scaling": 3}' "Updating Hetzner scaling"
# Wait for proxies to be created (dynamic wait with timeout)
# Calculate expected total proxies from scaling settings
expected_proxy_count=0
do_min_scaling=$(curl -s -X GET "http://localhost:8000/providers/digitalocean" -H "accept: application/json" | jq -r '.provider.scaling.min_scaling')
aws_min_scaling=$(curl -s -X GET "http://localhost:8000/providers/aws" -H "accept: application/json" | jq -r '.provider.scaling.min_scaling')
hetzner_min_scaling=$(curl -s -X GET "http://localhost:8000/providers/hetzner" -H "accept: application/json" | jq -r '.provider.scaling.min_scaling')
# Only count enabled providers
do_enabled=$(curl -s -X GET "http://localhost:8000/providers/digitalocean" -H "accept: application/json" | jq -r '.provider.enabled')
aws_enabled=$(curl -s -X GET "http://localhost:8000/providers/aws" -H "accept: application/json" | jq -r '.provider.enabled')
hetzner_enabled=$(curl -s -X GET "http://localhost:8000/providers/hetzner" -H "accept: application/json" | jq -r '.provider.enabled')
if [ "$do_enabled" = "true" ]; then
expected_proxy_count=$((expected_proxy_count + do_min_scaling))
fi
if [ "$aws_enabled" = "true" ]; then
expected_proxy_count=$((expected_proxy_count + aws_min_scaling))
fi
if [ "$hetzner_enabled" = "true" ]; then
expected_proxy_count=$((expected_proxy_count + hetzner_min_scaling))
fi
# Wait for the expected number of proxies
wait_for_proxies $expected_proxy_count
# Test 8: List proxies after scaling up
call_api "GET" "/" "" "Listing proxies after scaling up"
# Test 9: Check providers again
call_api "GET" "/providers" "" "Checking all providers after scaling"
# Test 10: Get a random proxy again
call_api "GET" "/random" "" "Getting a random proxy after scaling"
# Wait a bit longer for proxies to be fully operational (SSH setup, etc.)
print_info "Waiting for proxies to be fully operational..."
sleep $PROXY_WAIT_TIME
# Test 11: Actually test connecting through a proxy
if [ "$SKIP_CONNECTION_TEST" = "true" ]; then
print_header "SKIPPING PROXY CONNECTION TEST"
print_info "Connection testing has been disabled via the --skip-connection-test flag"
else
print_header "TESTING PROXY CONNECTION"
test_proxy_ip=$(curl -s -X GET "http://localhost:8000/random" -H "accept: application/json" | jq -r '.ip')
if [ -n "$test_proxy_ip" ] && [ "$test_proxy_ip" != "null" ]; then
if test_proxy_connection "$test_proxy_ip" 8899 "Testing connectivity through random proxy"; then
print_success "Successfully connected through proxy $test_proxy_ip"
else
print_error "Failed to connect through proxy $test_proxy_ip"
# Show the logs for this proxy for debugging
print_info "Showing logs for the proxy instance..."
docker logs cloudproxy-test 2>&1 | grep -i "$test_proxy_ip" | tail -n 50
# Test direct connectivity to the proxy port
print_info "Testing direct connectivity to proxy port..."
nc_result=$(nc -zv -w 5 $test_proxy_ip 8899 2>&1 || echo "Connection failed")
echo "$nc_result"
# Check logs inside the instance (would need SSH access)
print_info "To further debug, SSH into the proxy instance and check:"
echo " - System logs"
echo " - Proxy service status"
echo " - Network port configuration"
fi
else
print_error "No proxies available to test"
fi
fi
# Get the IP of a proxy to delete - using jq to extract the first proxy IP
first_proxy_ip=$(curl -s -X GET "http://localhost:8000/" -H "accept: application/json" |
jq -r '.proxies[0].ip')
if [ -n "$first_proxy_ip" ] && [ "$first_proxy_ip" != "null" ]; then
# Test 11: Delete a specific proxy
call_api "DELETE" "/destroy?ip_address=$first_proxy_ip" "" "Deleting proxy with IP $first_proxy_ip"
# Wait for the proxy to be deleted
print_info "Waiting for proxy to be deleted..."
sleep 5
# Test 12: Check if proxy is in destroy queue
call_api "GET" "/destroy" "" "Checking destroy queue"
# Test 13: List proxies after deletion
call_api "GET" "/" "" "Listing proxies after deletion"
else
print_error "No proxies available to delete"
fi
# Get another proxy IP for restart
second_proxy_ip=$(curl -s -X GET "http://localhost:8000/" -H "accept: application/json" |
jq -r '.proxies[0].ip')
if [ -n "$second_proxy_ip" ] && [ "$second_proxy_ip" != "null" ]; then
# Test 14: Restart a specific proxy
call_api "DELETE" "/restart?ip_address=$second_proxy_ip" "" "Restarting proxy with IP $second_proxy_ip"
else
print_error "No proxies available to restart"
fi
# Test 15: Scale down DigitalOcean
call_api "PATCH" "/providers/digitalocean" '{"min_scaling": 1, "max_scaling": 2}' "Scaling down DigitalOcean"
# Wait for scaling down to take effect
print_info "Waiting for scaling down to take effect..."
sleep 10
# Test 16: Check providers again after scale down
call_api "GET" "/providers" "" "Checking providers after scaling down"
# Test 17: Final list of proxies
call_api "GET" "/" "" "Final list of all proxies"
# Check if UI and docs are accessible
print_header "CHECKING WEB INTERFACES"
ui_status=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/ui/)
docs_status=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/docs)
if [ "$ui_status" -eq 200 ]; then
print_success "UI is accessible at http://localhost:8000/ui/"
else
print_error "UI is not accessible, status code: $ui_status"
fi
if [ "$docs_status" -eq 200 ]; then
print_success "API docs are accessible at http://localhost:8000/docs"
else
print_error "API docs are not accessible, status code: $docs_status"
fi
print_header "TEST SUMMARY"
print_success "All tests completed. CloudProxy container is working properly."
print_info "Proxy connectivity tests were performed."
print_info "You can access the UI at: http://localhost:8000/ui/"
print_info "You can access the API docs at: http://localhost:8000/docs"
print_info "To stop the container run: docker stop cloudproxy-test"
print_info "To remove the container run: docker rm cloudproxy-test"
# Clean up resources based on environment variable
if [ "${AUTO_CLEANUP:-true}" = "true" ]; then
print_header "CLEANING UP RESOURCES"
# Scale down all providers to 0 to avoid leaving cloud resources running
print_info "Scaling down all providers to 0..."
call_api "PATCH" "/providers/digitalocean" '{"min_scaling": 0, "max_scaling": 0}' "Scaling down DigitalOcean"
call_api "PATCH" "/providers/aws" '{"min_scaling": 0, "max_scaling": 0}' "Scaling down AWS"
call_api "PATCH" "/providers/hetzner" '{"min_scaling": 0, "max_scaling": 0}' "Scaling down Hetzner"
# Wait for all proxies to be destroyed
wait_for_proxies_destroyed
# Ensure all cloud provider deletion queues are processed
ensure_cloud_provider_cleanup
# Stop and remove the container
print_info "Stopping and removing the test container..."
docker stop cloudproxy-test && docker rm cloudproxy-test
print_success "Cleanup complete"
else
print_info "AUTO_CLEANUP is disabled. Remember to manually clean up resources:"
print_info "1. Scale down all providers to 0"
print_info "2. Destroy any remaining proxies"
print_info "3. Stop and remove the container"
fi
# Exit with success
print_header "TEST SCRIPT COMPLETE"
exit 0