-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-api.sh
More file actions
111 lines (94 loc) · 3.61 KB
/
test-api.sh
File metadata and controls
111 lines (94 loc) · 3.61 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
#!/bin/bash
# Test script for Midjourney Proxy API
# Usage: ./test-api.sh <your-railway-app-url> <your-api-secret>
if [ $# -ne 2 ]; then
echo "Usage: $0 <railway-app-url> <api-secret>"
echo "Example: $0 https://your-app.railway.app your-api-secret"
exit 1
fi
APP_URL=$1
API_SECRET=$2
echo "🧪 Testing Midjourney Proxy API"
echo "================================"
echo "App URL: $APP_URL"
echo "API Secret: ${API_SECRET:0:10}..."
echo ""
# Test health endpoint
echo "1. Testing health endpoint..."
HEALTH_RESPONSE=$(curl -s -w "%{http_code}" -o /tmp/health_response "$APP_URL/health")
HEALTH_CODE=${HEALTH_RESPONSE: -3}
if [ "$HEALTH_CODE" = "200" ]; then
echo "✅ Health check passed"
cat /tmp/health_response | jq . 2>/dev/null || cat /tmp/health_response
else
echo "❌ Health check failed (HTTP $HEALTH_CODE)"
cat /tmp/health_response
fi
echo ""
# Test API documentation
echo "2. Testing API documentation..."
DOC_RESPONSE=$(curl -s -w "%{http_code}" -o /tmp/doc_response "$APP_URL/doc.html")
DOC_CODE=${DOC_RESPONSE: -3}
if [ "$DOC_CODE" = "200" ]; then
echo "✅ API documentation accessible"
else
echo "❌ API documentation failed (HTTP $DOC_CODE)"
fi
echo ""
# Test API with authentication
echo "3. Testing API authentication..."
AUTH_RESPONSE=$(curl -s -w "%{http_code}" -o /tmp/auth_response \
-H "mj-api-secret: $API_SECRET" \
"$APP_URL/mj/task/list")
AUTH_CODE=${AUTH_RESPONSE: -3}
if [ "$AUTH_CODE" = "200" ]; then
echo "✅ API authentication successful"
cat /tmp/auth_response | jq . 2>/dev/null || cat /tmp/auth_response
else
echo "❌ API authentication failed (HTTP $AUTH_CODE)"
cat /tmp/auth_response
fi
echo ""
# Test without authentication (should fail)
echo "4. Testing API without authentication..."
NO_AUTH_RESPONSE=$(curl -s -w "%{http_code}" -o /tmp/no_auth_response \
"$APP_URL/mj/task/list")
NO_AUTH_CODE=${NO_AUTH_RESPONSE: -3}
if [ "$NO_AUTH_CODE" = "401" ] || [ "$NO_AUTH_CODE" = "403" ]; then
echo "✅ API properly rejects unauthenticated requests"
else
echo "⚠️ API security check: Expected 401/403, got $NO_AUTH_CODE"
fi
echo ""
# Test imagine endpoint (dry run)
echo "5. Testing imagine endpoint structure..."
IMAGINE_RESPONSE=$(curl -s -w "%{http_code}" -o /tmp/imagine_response \
-X POST \
-H "Content-Type: application/json" \
-H "mj-api-secret: $API_SECRET" \
-d '{"prompt": "test prompt --dry-run"}' \
"$APP_URL/mj/submit/imagine")
IMAGINE_CODE=${IMAGINE_RESPONSE: -3}
echo "Imagine endpoint response (HTTP $IMAGINE_CODE):"
cat /tmp/imagine_response | jq . 2>/dev/null || cat /tmp/imagine_response
echo ""
# Summary
echo "📊 Test Summary"
echo "==============="
echo "Health Check: $([ "$HEALTH_CODE" = "200" ] && echo "✅ PASS" || echo "❌ FAIL")"
echo "Documentation: $([ "$DOC_CODE" = "200" ] && echo "✅ PASS" || echo "❌ FAIL")"
echo "Authentication: $([ "$AUTH_CODE" = "200" ] && echo "✅ PASS" || echo "❌ FAIL")"
echo "Security: $([ "$NO_AUTH_CODE" = "401" ] || [ "$NO_AUTH_CODE" = "403" ] && echo "✅ PASS" || echo "⚠️ CHECK")"
echo ""
if [ "$HEALTH_CODE" = "200" ] && [ "$DOC_CODE" = "200" ] && [ "$AUTH_CODE" = "200" ]; then
echo "🎉 All basic tests passed! Your Midjourney Proxy is ready to use."
echo ""
echo "📚 Next steps:"
echo " - Visit $APP_URL/doc.html for API documentation"
echo " - Test with a real Midjourney prompt"
echo " - Monitor logs in Railway dashboard"
else
echo "⚠️ Some tests failed. Check the Railway logs for more details."
fi
# Cleanup
rm -f /tmp/health_response /tmp/doc_response /tmp/auth_response /tmp/no_auth_response /tmp/imagine_response