Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.

Commit 8e369db

Browse files
committed
fix: [#28] add URL encoding for admin tokens in deployment testing
- Add automatic URL encoding for admin tokens in deploy-app.sh - Fixes API authentication failures when tokens contain special characters (+ and /) - Enhanced error reporting shows both raw and encoded tokens for debugging - Update testing session documentation with issue resolution details Resolves API testing failures in staging deployment validation.
1 parent 4d4133a commit 8e369db

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

docs/testing/manual-sessions/2025-08-08-issue-28-phase-4-7-staging.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,38 @@ Expected:
146146

147147
## Open Items / Issues Noted During Session
148148

149+
### ✅ RESOLVED: API Token URL Encoding Issue
150+
151+
**Issue**: Deployment testing was failing with "token not valid" error when testing the
152+
HTTP API stats endpoint.
153+
154+
**Root Cause**: The admin token contains special characters (+ and /) that need URL encoding
155+
in HTTP query parameters:
156+
157+
- Raw token: `sTnc7/5XjZfsb2C5bNet++D+PTO9aqPsOyiCBcu+NOeWrxUMWe08LnVBs8VCMZDY`
158+
- Special characters: `+` becomes `%2B`, `/` becomes `%2F`
159+
- URL-encoded: `sTnc7%2F5XjZfsb2C5bNet%2B%2BD%2BPTO9aqPsOyiCBcu%2BNOeWrxUMWe08LnVBs8VCMZDY`
160+
161+
**Solution**: Updated `infrastructure/scripts/deploy-app.sh` to automatically URL-encode the
162+
admin token before using it in API calls:
163+
164+
```bash
165+
admin_token_encoded=$(printf '%s' "$admin_token" | sed 's/+/%2B/g; s,/,%2F,g')
166+
```
167+
168+
- Updated both HTTP and HTTPS API endpoint tests to use encoded token
169+
- Enhanced error reporting to show both raw and encoded tokens for debugging
170+
171+
**Impact**:
172+
173+
- ✅ Prevents future deployment failures due to token encoding issues
174+
- ✅ Makes deployment testing more robust for tokens with special characters
175+
- ✅ Provides better debugging information when API tests fail
176+
177+
### Open Items
178+
149179
- [ ] Optional: Test IPv6 connectivity to deployed application (requires application deployment)
180+
- [ ] Continue with HTTPS setup after HTTP deployment validation
150181

151182
## Final Status
152183

infrastructure/scripts/deploy-app.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,11 +1011,13 @@ validate_deployment() {
10111011
10121012
# Test HTTP API stats endpoint (through nginx proxy, requires auth)
10131013
echo 'Testing HTTP API stats endpoint...'
1014-
# Use admin token passed from local environment
1014+
# Use admin token passed from local environment and URL-encode it
10151015
admin_token=\"${admin_token}\"
1016+
# URL-encode the token to handle special characters (+ becomes %2B, / becomes %2F)
1017+
admin_token_encoded=\$(printf '%s' \"\$admin_token\" | sed 's/+/%2B/g; s,/,%2F,g')
10161018
10171019
# Save response to temp file and get HTTP status code
1018-
api_http_code=\$(curl -s -o /tmp/api_response.json -w '%{http_code}' \"http://localhost/api/v1/stats?token=\$admin_token\" 2>&1 || echo \"000\")
1020+
api_http_code=\$(curl -s -o /tmp/api_response.json -w '%{http_code}' \"http://localhost/api/v1/stats?token=\$admin_token_encoded\" 2>&1 || echo \"000\")
10191021
api_response_body=\$(cat /tmp/api_response.json 2>/dev/null || echo \"No response\")
10201022
10211023
# Check if HTTP status is 200 (success)
@@ -1025,7 +1027,8 @@ validate_deployment() {
10251027
echo '❌ HTTP API stats endpoint: FAILED'
10261028
echo \" HTTP Code: \$api_http_code\"
10271029
echo \" Response: \$api_response_body\"
1028-
echo \" Token used: \$admin_token\"
1030+
echo \" Raw token: \$admin_token\"
1031+
echo \" Encoded token: \$admin_token_encoded\"
10291032
rm -f /tmp/api_response.json
10301033
exit 1
10311034
fi
@@ -1034,7 +1037,7 @@ validate_deployment() {
10341037
# Test HTTPS API stats endpoint (through nginx proxy, with self-signed certificates)
10351038
echo 'Testing HTTPS API stats endpoint...'
10361039
# Save response to temp file and get HTTP status code
1037-
api_https_code=\$(curl -s -k -o /tmp/api_response_https.json -w '%{http_code}' \"https://localhost/api/v1/stats?token=\$admin_token\" 2>&1 || echo \"000\")
1040+
api_https_code=\$(curl -s -k -o /tmp/api_response_https.json -w '%{http_code}' \"https://localhost/api/v1/stats?token=\$admin_token_encoded\" 2>&1 || echo \"000\")
10381041
api_https_response=\$(cat /tmp/api_response_https.json 2>/dev/null || echo \"No response\")
10391042
10401043
# Check if HTTPS status is 200 (success)

0 commit comments

Comments
 (0)