-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_server.sh
More file actions
84 lines (69 loc) · 1.7 KB
/
test_server.sh
File metadata and controls
84 lines (69 loc) · 1.7 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
#!/bin/bash
# Test script for the C web server
# Usage: ./test_server.sh
SERVER="http://localhost:8080"
echo "================================"
echo "Testing C Web Server"
echo "================================"
echo ""
# Test 1: Home page
echo "1. Testing GET / (Home page)"
curl -s "$SERVER/" | head -n 5
echo ""
echo "---"
echo ""
# Test 2: Hello API
echo "2. Testing GET /api/hello"
curl -s "$SERVER/api/hello"
echo ""
echo ""
# Test 3: Hello API with name parameter
echo "3. Testing GET /api/hello?name=Alice"
curl -s "$SERVER/api/hello?name=Alice"
echo ""
echo ""
# Test 4: Time API
echo "4. Testing GET /api/time"
curl -s "$SERVER/api/time"
echo ""
echo ""
# Test 5: List users
echo "5. Testing GET /api/users"
curl -s "$SERVER/api/users"
echo ""
echo ""
# Test 6: Get specific user
echo "6. Testing GET /api/users/1"
curl -s "$SERVER/api/users/1"
echo ""
echo ""
# Test 7: Create user (POST)
echo "7. Testing POST /api/users"
curl -s -X POST "$SERVER/api/users" \
-H "Content-Type: application/json" \
-d '{"name":"John","email":"john@example.com"}'
echo ""
echo ""
# Test 8: Delete user
echo "8. Testing DELETE /api/users/2"
curl -s -X DELETE "$SERVER/api/users/2"
echo ""
echo ""
# Test 9: 404 - Not found
echo "9. Testing GET /nonexistent (should be 404)"
curl -s "$SERVER/nonexistent"
echo ""
echo ""
# Test 10: Protected route without auth
echo "10. Testing GET /admin (without auth - should fail)"
curl -s "$SERVER/admin"
echo ""
echo ""
# Test 11: Protected route with auth
echo "11. Testing GET /admin (with auth header)"
curl -s "$SERVER/admin" -H "Authorization: Bearer fake-token"
echo ""
echo ""
echo "================================"
echo "All tests completed!"
echo "================================"