-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-user-api.sh
More file actions
executable file
·71 lines (60 loc) · 2.19 KB
/
test-user-api.sh
File metadata and controls
executable file
·71 lines (60 loc) · 2.19 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
#!/bin/bash
# User Management API Test Script
echo "🧪 Testing Asteroid Radio User Management API"
echo "=============================================="
echo ""
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Test 1: Get User Stats
echo -e "${BLUE}Test 1: Get User Statistics${NC}"
echo "GET /asteroid/api/users/stats"
curl -s http://localhost:8080/asteroid/api/users/stats | jq .
echo ""
# Test 2: Get All Users
echo -e "${BLUE}Test 2: Get All Users${NC}"
echo "GET /asteroid/api/users"
curl -s http://localhost:8080/asteroid/api/users | jq .
echo ""
# Test 3: Create New User (requires authentication)
echo -e "${BLUE}Test 3: Create New User (will fail without auth)${NC}"
echo "POST /asteroid/api/users/create"
curl -s -X POST http://localhost:8080/asteroid/api/users/create \
-d "username=testuser" \
-d "email=test@example.com" \
-d "password=testpass123" \
-d "role=listener" | jq .
echo ""
# Test 4: Login as admin (to get session for authenticated requests)
echo -e "${BLUE}Test 4: Login as Admin${NC}"
echo "POST /asteroid/login"
COOKIES=$(mktemp)
curl -s -c $COOKIES -X POST http://localhost:8080/asteroid/login \
-d "username=admin" \
-d "password=asteroid123" \
-w "\nHTTP Status: %{http_code}\n"
echo ""
# Test 5: Create user with authentication
echo -e "${BLUE}Test 5: Create New User (authenticated)${NC}"
echo "POST /asteroid/api/users/create (with session)"
curl -s -b $COOKIES -X POST http://localhost:8080/asteroid/api/users/create \
-d "username=testuser_$(date +%s)" \
-d "email=test_$(date +%s)@example.com" \
-d "password=testpass123" \
-d "role=listener" | jq .
echo ""
# Test 6: Get updated user list
echo -e "${BLUE}Test 6: Get Updated User List${NC}"
echo "GET /asteroid/api/users"
curl -s -b $COOKIES http://localhost:8080/asteroid/api/users | jq '.users | length as $count | "Total users: \($count)"'
echo ""
# Test 7: Update user role (if endpoint exists)
echo -e "${BLUE}Test 7: Check Track Count${NC}"
echo "GET /admin/tracks"
curl -s -b $COOKIES http://localhost:8080/admin/tracks | jq '.tracks | length as $count | "Total tracks: \($count)"'
echo ""
# Cleanup
rm -f $COOKIES
echo -e "${GREEN}✅ API Tests Complete!${NC}"