tahamajs/IE / Projects /scripts /run_qa_e2e.sh
tahamajs's picture
download
raw
6.52 kB
#!/bin/bash
set -e
BASE_URL="http://localhost:9095"
echo "=================================================="
echo "🧪 STARTING SENIOR QA AUTOMATION E2E TEST SUITE"
echo "Target Base URL: $BASE_URL"
echo "=================================================="
# Wait for server readiness
echo "⏳ Waiting for server readiness..."
for i in {1..20}; do
status=$(curl -s -o /dev/null -w "%{http_code}" "$BASE_URL/api/articles" || echo "000")
if [ "$status" = "200" ]; then
echo "✅ Server is ONLINE and accepting HTTP requests!"
break
fi
sleep 2
done
# Result arrays
declare -a ENDPOINTS
declare -a METHODS
declare -a EXPECTEDS
declare -a ACTUALS
declare -a RESULTS
add_result() {
ENDPOINTS+=("$1")
METHODS+=("$2")
EXPECTEDS+=("$3")
ACTUALS+=("$4")
RESULTS+=("$5")
}
# 1. Validation Test - Password Too Short
echo ""
echo "▶ Running Test Case 1: Validation - Password Too Short"
code=$(curl -s -o /dev/null -w "%{http_code}" -X POST "$BASE_URL/api/auth/register" \
-H "Content-Type: application/json" \
-d '{"username":"qa_val_1", "password":"123"}')
if [ "$code" = "400" ]; then
add_result "/api/auth/register" "POST" "400 Bad Request" "$code" "PASS"
else
add_result "/api/auth/register" "POST" "400 Bad Request" "$code" "FAIL"
fi
# 2. Validation Test - Password Too Weak
echo "▶ Running Test Case 2: Validation - Password Too Weak"
code=$(curl -s -o /dev/null -w "%{http_code}" -X POST "$BASE_URL/api/auth/register" \
-H "Content-Type: application/json" \
-d '{"username":"qa_val_2", "password":"password"}')
if [ "$code" = "400" ]; then
add_result "/api/auth/register" "POST" "400 Bad Request" "$code" "PASS"
else
add_result "/api/auth/register" "POST" "400 Bad Request" "$code" "FAIL"
fi
# 3. Validation Test - Missing Contact Info (Email or Phone Required)
echo "▶ Running Test Case 3: Validation - Missing Contact Info"
code=$(curl -s -o /dev/null -w "%{http_code}" -X POST "$BASE_URL/api/auth/register" \
-H "Content-Type: application/json" \
-d '{"username":"qa_val_3", "password":"QaPassword123"}')
if [ "$code" = "400" ]; then
add_result "/api/auth/register" "POST" "400 Bad Request" "$code" "PASS"
else
add_result "/api/auth/register" "POST" "400 Bad Request" "$code" "FAIL"
fi
# 4. Happy Path Register
echo "▶ Running Test Case 4: Happy Path User Registration"
reg_resp=$(curl -s -X POST "$BASE_URL/api/auth/register" \
-H "Content-Type: application/json" \
-d '{"username":"testuser_qa", "password":"QaPassword123", "email":"qa@example.com", "fullName":"QA Automation Engineer"}')
code=$(curl -s -o /dev/null -w "%{http_code}" -X POST "$BASE_URL/api/auth/register" \
-H "Content-Type: application/json" \
-d '{"username":"testuser_qa_fresh", "password":"QaPassword123", "email":"qa_fresh@example.com", "fullName":"QA Engineer Fresh"}')
if [ "$code" = "200" ] || [ "$code" = "201" ]; then
add_result "/api/auth/register" "POST" "200 OK / 201 Created" "$code" "PASS"
else
add_result "/api/auth/register" "POST" "200 OK / 201 Created" "$code" "FAIL"
fi
# 5. Duplicate User Conflict Test
echo "▶ Running Test Case 5: Duplicate Conflict Check"
code=$(curl -s -o /dev/null -w "%{http_code}" -X POST "$BASE_URL/api/auth/register" \
-H "Content-Type: application/json" \
-d '{"username":"testuser_qa_fresh", "password":"QaPassword123", "email":"qa_another@example.com"}')
if [ "$code" = "409" ]; then
add_result "/api/auth/register" "POST" "409 Conflict" "$code" "PASS"
else
add_result "/api/auth/register" "POST" "409 Conflict" "$code" "FAIL"
fi
# 6. Login & JWT Token Extraction
echo "▶ Running Test Case 6: Login & Token Extraction"
login_json=$(curl -s -X POST "$BASE_URL/api/auth/login" \
-H "Content-Type: application/json" \
-d '{"username":"testuser_qa_fresh", "password":"QaPassword123"}')
TOKEN=$(echo "$login_json" | grep -o '"token":"[^"]*' | cut -d'"' -f4 || echo "")
if [ -n "$TOKEN" ]; then
echo "🔑 Successfully extracted JWT token (${#TOKEN} chars)"
add_result "/api/auth/login" "POST" "200 OK (Token Extracted)" "200 OK" "PASS"
else
echo "❌ Failed to extract token: $login_json"
add_result "/api/auth/login" "POST" "200 OK (Token Extracted)" "FAILED" "FAIL"
fi
# 7. Protected Endpoint WITH Token
echo "▶ Running Test Case 7: Access Protected Profile WITH Token"
code=$(curl -s -o /dev/null -w "%{http_code}" -X GET "$BASE_URL/api/users/me" \
-H "Authorization: Bearer $TOKEN")
if [ "$code" = "200" ]; then
add_result "/api/users/me" "GET" "200 OK" "$code" "PASS"
else
add_result "/api/users/me" "GET" "200 OK" "$code" "FAIL"
fi
# 8. Protected Endpoint WITHOUT Token
echo "▶ Running Test Case 8: Access Protected Profile WITHOUT Token"
code=$(curl -s -o /dev/null -w "%{http_code}" -X GET "$BASE_URL/api/users/me")
if [ "$code" = "401" ] || [ "$code" = "302" ]; then
add_result "/api/users/me" "GET" "401 Unauthorized" "$code" "PASS"
else
add_result "/api/users/me" "GET" "401 Unauthorized" "$code" "FAIL"
fi
# 9. Protected Endpoint WITH Corrupted Token
echo "▶ Running Test Case 9: Access Protected Profile WITH Invalid Token"
code=$(curl -s -o /dev/null -w "%{http_code}" -X GET "$BASE_URL/api/users/me" \
-H "Authorization: Bearer INVALID_DUMMY_TOKEN")
if [ "$code" = "401" ] || [ "$code" = "403" ] || [ "$code" = "302" ]; then
add_result "/api/users/me" "GET" "401 Unauthorized" "$code" "PASS"
else
add_result "/api/users/me" "GET" "401 Unauthorized" "$code" "FAIL"
fi
# 10. Public Endpoint Guest Access
echo "▶ Running Test Case 10: Public Articles Endpoint (Guest Access)"
code=$(curl -s -o /dev/null -w "%{http_code}" -X GET "$BASE_URL/api/articles")
if [ "$code" = "200" ]; then
add_result "/api/articles" "GET" "200 OK" "$code" "PASS"
else
add_result "/api/articles" "GET" "200 OK" "$code" "FAIL"
fi
echo ""
echo "=========================================================================================="
echo "📊 END-TO-END QA AUTOMATION TEST RESULTS SUMMARY"
echo "=========================================================================================="
printf "%-30s | %-7s | %-22s | %-12s | %-6s\n" "ENDPOINT" "METHOD" "EXPECTED STATUS" "ACTUAL STATUS" "RESULT"
echo "------------------------------------------------------------------------------------------"
for i in "${!ENDPOINTS[@]}"; do
printf "%-30s | %-7s | %-22s | %-12s | %-6s\n" "${ENDPOINTS[$i]}" "${METHODS[$i]}" "${EXPECTEDS[$i]}" "${ACTUALS[$i]}" "${RESULTS[$i]}"
done
echo "=========================================================================================="

Xet Storage Details

Size:
6.52 kB
·
Xet hash:
a4e4b7646288d7abe993a1bfd62521f6b767c5d873069cc3022ba8dfed3cf2ef

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.