-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathintegration_test.sh
More file actions
executable file
·215 lines (185 loc) · 6.63 KB
/
integration_test.sh
File metadata and controls
executable file
·215 lines (185 loc) · 6.63 KB
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
#!/bin/bash
# Integration test script for CaddyManager
# This script tests the integration between different components
# Colors for better readability
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
echo -e "${YELLOW}Running integration tests for CaddyManager...${NC}"
# Create a test directory
TEST_DIR="integration_test_$(date +%s)"
mkdir -p $TEST_DIR
cd $TEST_DIR
# Get authentication token
echo -e "Authenticating..."
LOGIN_RESULT=$(curl -s -X POST http://localhost:3000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"admin@caddymanager.local","password":"changeme123"}')
if echo "$LOGIN_RESULT" | grep -q "token"; then
echo -e "${GREEN}✓ Authentication successful${NC}"
TOKEN=$(echo "$LOGIN_RESULT" | grep -o '"token":"[^"]*' | sed 's/"token":"//')
else
echo -e "${RED}✗ Authentication failed${NC}"
cd ..
rm -rf $TEST_DIR
exit 1
fi
# Test 1: Create a proxy with template
echo -e "\nTest 1: Creating a proxy with template application"
# Get available templates
echo -e "Getting templates..."
TEMPLATES=$(curl -s -X GET http://localhost:3000/api/templates \
-H "Authorization: Bearer $TOKEN")
if echo "$TEMPLATES" | grep -q "templates"; then
echo -e "${GREEN}✓ Templates retrieved successfully${NC}"
TEMPLATE_ID=$(echo "$TEMPLATES" | grep -o '"id":"[^"]*' | head -1 | sed 's/"id":"//')
TEMPLATE_NAME=$(echo "$TEMPLATES" | grep -o '"name":"[^"]*' | head -1 | sed 's/"name":"//')
echo -e "Selected template: $TEMPLATE_NAME"
else
echo -e "${RED}✗ Failed to retrieve templates${NC}"
cd ..
rm -rf $TEST_DIR
exit 1
fi
# Create a proxy
echo -e "Creating proxy..."
PROXY_RESULT=$(curl -s -X POST http://localhost:3000/api/proxies \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "{
\"name\":\"Integration Test Proxy\",
\"domains\":[\"integration-test.local\"],
\"upstream_url\":\"http://localhost:8000\",
\"ssl_type\":\"none\",
\"compression_enabled\":true
}")
if echo "$PROXY_RESULT" | grep -q "success"; then
echo -e "${GREEN}✓ Proxy created successfully${NC}"
PROXY_ID=$(echo "$PROXY_RESULT" | grep -o '"id":"[^"]*' | sed 's/"id":"//')
else
echo -e "${RED}✗ Failed to create proxy${NC}"
cd ..
rm -rf $TEST_DIR
exit 1
fi
# Apply template to proxy
echo -e "Applying template to proxy..."
APPLY_RESULT=$(curl -s -X POST http://localhost:3000/api/templates/$TEMPLATE_ID/apply/$PROXY_ID \
-H "Authorization: Bearer $TOKEN")
if echo "$APPLY_RESULT" | grep -q "success"; then
echo -e "${GREEN}✓ Template applied successfully${NC}"
else
echo -e "${RED}✗ Failed to apply template${NC}"
# Clean up proxy
curl -s -X DELETE http://localhost:3000/api/proxies/$PROXY_ID \
-H "Authorization: Bearer $TOKEN" > /dev/null
cd ..
rm -rf $TEST_DIR
exit 1
fi
# Test 2: Create a backup and restore
echo -e "\nTest 2: Creating a backup and restoring"
# Create a backup
echo -e "Creating backup..."
BACKUP_RESULT=$(curl -s -X POST http://localhost:3000/api/backups \
-H "Authorization: Bearer $TOKEN")
if echo "$BACKUP_RESULT" | grep -q "success"; then
echo -e "${GREEN}✓ Backup created successfully${NC}"
BACKUP_ID=$(echo "$BACKUP_RESULT" | grep -o '"id":"[^"]*' | sed 's/"id":"//')
else
echo -e "${RED}✗ Failed to create backup${NC}"
# Clean up proxy
curl -s -X DELETE http://localhost:3000/api/proxies/$PROXY_ID \
-H "Authorization: Bearer $TOKEN" > /dev/null
cd ..
rm -rf $TEST_DIR
exit 1
fi
# Download backup
echo -e "Downloading backup..."
curl -s -X GET http://localhost:3000/api/backups/$BACKUP_ID \
-H "Authorization: Bearer $TOKEN" \
-o backup.json
if [ -s backup.json ]; then
echo -e "${GREEN}✓ Backup downloaded successfully${NC}"
else
echo -e "${RED}✗ Failed to download backup${NC}"
# Clean up
curl -s -X DELETE http://localhost:3000/api/proxies/$PROXY_ID \
-H "Authorization: Bearer $TOKEN" > /dev/null
curl -s -X DELETE http://localhost:3000/api/backups/$BACKUP_ID \
-H "Authorization: Bearer $TOKEN" > /dev/null
cd ..
rm -rf $TEST_DIR
exit 1
fi
# Create a second proxy to test restore
echo -e "Creating second proxy..."
PROXY2_RESULT=$(curl -s -X POST http://localhost:3000/api/proxies \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "{
\"name\":\"Integration Test Proxy 2\",
\"domains\":[\"integration-test-2.local\"],
\"upstream_url\":\"http://localhost:8001\",
\"ssl_type\":\"none\"
}")
if echo "$PROXY2_RESULT" | grep -q "success"; then
echo -e "${GREEN}✓ Second proxy created successfully${NC}"
PROXY2_ID=$(echo "$PROXY2_RESULT" | grep -o '"id":"[^"]*' | sed 's/"id":"//')
else
echo -e "${RED}✗ Failed to create second proxy${NC}"
# Clean up
curl -s -X DELETE http://localhost:3000/api/proxies/$PROXY_ID \
-H "Authorization: Bearer $TOKEN" > /dev/null
curl -s -X DELETE http://localhost:3000/api/backups/$BACKUP_ID \
-H "Authorization: Bearer $TOKEN" > /dev/null
cd ..
rm -rf $TEST_DIR
exit 1
fi
# Restore from backup
echo -e "Restoring from backup..."
RESTORE_RESULT=$(curl -s -X POST http://localhost:3000/api/backups/$BACKUP_ID/restore \
-H "Authorization: Bearer $TOKEN")
if echo "$RESTORE_RESULT" | grep -q "success"; then
echo -e "${GREEN}✓ Restore successful${NC}"
else
echo -e "${RED}✗ Failed to restore from backup${NC}"
# Clean up
curl -s -X DELETE http://localhost:3000/api/proxies/$PROXY_ID \
-H "Authorization: Bearer $TOKEN" > /dev/null
curl -s -X DELETE http://localhost:3000/api/proxies/$PROXY2_ID \
-H "Authorization: Bearer $TOKEN" > /dev/null
curl -s -X DELETE http://localhost:3000/api/backups/$BACKUP_ID \
-H "Authorization: Bearer $TOKEN" > /dev/null
cd ..
rm -rf $TEST_DIR
exit 1
fi
# Test 3: Verify Caddy configuration
echo -e "\nTest 3: Verifying Caddy configuration"
# Check Caddy config
echo -e "Checking Caddy configuration..."
CADDY_CONFIG=$(curl -s -X GET http://localhost:2019/config/)
if echo "$CADDY_CONFIG" | grep -q "integration-test.local"; then
echo -e "${GREEN}✓ Proxy configuration found in Caddy${NC}"
else
echo -e "${RED}✗ Proxy configuration not found in Caddy${NC}"
# Continue anyway as this might be due to Caddy not running
fi
# Clean up
echo -e "\nCleaning up..."
# Delete proxies
curl -s -X DELETE http://localhost:3000/api/proxies/$PROXY_ID \
-H "Authorization: Bearer $TOKEN" > /dev/null
echo -e "${GREEN}✓ Deleted test proxy${NC}"
# Delete backup
curl -s -X DELETE http://localhost:3000/api/backups/$BACKUP_ID \
-H "Authorization: Bearer $TOKEN" > /dev/null
echo -e "${GREEN}✓ Deleted test backup${NC}"
# Remove test directory
cd ..
rm -rf $TEST_DIR
echo -e "\n${GREEN}Integration tests completed successfully!${NC}"