Fix tenant register 2
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ================================================================
|
||||
# Complete Authentication Test with Registration
|
||||
# Complete Authentication Test with Registration - FIXED VERSION
|
||||
# Tests the full user lifecycle: registration → login → API access
|
||||
# ================================================================
|
||||
|
||||
@@ -14,7 +14,8 @@ AUTH_BASE="$API_BASE/api/v1/auth"
|
||||
TEST_EMAIL="test-$(date +%s)@bakery.com" # Unique email for each test
|
||||
TEST_PASSWORD="SecurePass123!"
|
||||
TEST_NAME="Test Baker"
|
||||
TENANT_ID="test-tenant-$(date +%s)"
|
||||
# ✅ FIX: Generate a proper UUID for tenant testing (will be replaced after bakery creation)
|
||||
TENANT_ID=$(uuidgen 2>/dev/null || python3 -c "import uuid; print(uuid.uuid4())" 2>/dev/null || echo "00000000-0000-0000-0000-000000000000")
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
@@ -73,6 +74,12 @@ if ! check_service_health "http://localhost:8001" "Auth Service"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check Tenant Service
|
||||
if ! check_service_health "http://localhost:8005" "Tenant Service"; then
|
||||
log_error "Tenant Service is not running. Check: docker-compose logs tenant-service"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check Data Service
|
||||
if ! check_service_health "http://localhost:8004" "Data Service"; then
|
||||
log_warning "Data Service is not running, but continuing with auth tests..."
|
||||
@@ -149,13 +156,13 @@ fi
|
||||
echo ""
|
||||
|
||||
# ================================================================
|
||||
# STEP 4: ACCESSING PROTECTED ENDPOINTS
|
||||
# STEP 3: ACCESSING PROTECTED ENDPOINTS
|
||||
# ================================================================
|
||||
|
||||
log_step "Step 4: Testing protected endpoints with authentication"
|
||||
log_step "Step 3: Testing protected endpoints with authentication"
|
||||
|
||||
# 4a. Get current user info
|
||||
log_step "4a. Getting current user profile"
|
||||
# 3a. Get current user info
|
||||
log_step "3a. Getting current user profile"
|
||||
|
||||
USER_PROFILE_RESPONSE=$(curl -s -X GET "$API_BASE/api/v1/users/me" \
|
||||
-H "Authorization: Bearer $ACCESS_TOKEN")
|
||||
@@ -171,53 +178,11 @@ fi
|
||||
|
||||
echo ""
|
||||
|
||||
# 4b. Test data service through gateway
|
||||
log_step "4b. Testing data service through gateway"
|
||||
|
||||
DATA_RESPONSE=$(curl -s -X GET "$API_BASE/api/v1/data/sales" \
|
||||
-H "Authorization: Bearer $ACCESS_TOKEN" \
|
||||
-H "X-Tenant-ID: $TENANT_ID")
|
||||
|
||||
echo "Data Service Response:"
|
||||
echo "$DATA_RESPONSE" | jq '.'
|
||||
|
||||
if [ "$(echo "$DATA_RESPONSE" | jq -r '.status // "unknown"')" != "error" ]; then
|
||||
log_success "Data service access successful!"
|
||||
else
|
||||
log_warning "Data service returned error (may be expected for new tenant)"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# 4c. Test training service through gateway
|
||||
log_step "4c. Testing training service through gateway"
|
||||
|
||||
TRAINING_RESPONSE=$(curl -s -X POST "$API_BASE/api/v1/training/jobs" \
|
||||
-H "Authorization: Bearer $ACCESS_TOKEN" \
|
||||
-H "X-Tenant-ID: $TENANT_ID" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"include_weather": true,
|
||||
"include_traffic": false,
|
||||
"min_data_points": 30
|
||||
}')
|
||||
|
||||
echo "Training Service Response:"
|
||||
echo "$TRAINING_RESPONSE" | jq '.'
|
||||
|
||||
if echo "$TRAINING_RESPONSE" | jq -e '.job_id // .message' > /dev/null; then
|
||||
log_success "Training service access successful!"
|
||||
else
|
||||
log_warning "Training service access may have issues"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# ================================================================
|
||||
# STEP 5: TENANT REGISTRATION (OPTIONAL)
|
||||
# STEP 4: TENANT REGISTRATION (BAKERY CREATION)
|
||||
# ================================================================
|
||||
|
||||
log_step "Step 5: Registering a bakery/tenant"
|
||||
log_step "Step 4: Registering a bakery/tenant"
|
||||
|
||||
BAKERY_RESPONSE=$(curl -s -X POST "$API_BASE/api/v1/tenants/register" \
|
||||
-H "Authorization: Bearer $ACCESS_TOKEN" \
|
||||
@@ -235,19 +200,80 @@ echo "Bakery Registration Response:"
|
||||
echo "$BAKERY_RESPONSE" | jq '.'
|
||||
|
||||
if echo "$BAKERY_RESPONSE" | jq -e '.id' > /dev/null; then
|
||||
# ✅ FIX: Use the actual tenant ID returned from bakery creation
|
||||
TENANT_ID=$(echo "$BAKERY_RESPONSE" | jq -r '.id')
|
||||
log_success "Bakery registration successful! Tenant ID: $TENANT_ID"
|
||||
else
|
||||
log_warning "Bakery registration endpoint may not be fully implemented"
|
||||
log_error "Bakery registration failed!"
|
||||
echo "Response: $BAKERY_RESPONSE"
|
||||
# Continue with tests using placeholder UUID for other endpoints
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# ================================================================
|
||||
# STEP 6: TOKEN REFRESH
|
||||
# STEP 5: TEST DATA SERVICE WITH TENANT ID
|
||||
# ================================================================
|
||||
|
||||
log_step "Step 6: Testing token refresh"
|
||||
log_step "Step 5: Testing data service through gateway"
|
||||
|
||||
# Only test with valid tenant ID
|
||||
if [ "$TENANT_ID" != "00000000-0000-0000-0000-000000000000" ]; then
|
||||
DATA_RESPONSE=$(curl -s -X GET "$API_BASE/api/v1/data/sales" \
|
||||
-H "Authorization: Bearer $ACCESS_TOKEN" \
|
||||
-H "X-Tenant-ID: $TENANT_ID")
|
||||
|
||||
echo "Data Service Response:"
|
||||
echo "$DATA_RESPONSE" | jq '.'
|
||||
|
||||
if [ "$(echo "$DATA_RESPONSE" | jq -r '.status // "unknown"')" != "error" ]; then
|
||||
log_success "Data service access successful!"
|
||||
else
|
||||
log_warning "Data service returned error (may be expected for new tenant)"
|
||||
fi
|
||||
else
|
||||
log_warning "Skipping data service test - no valid tenant ID"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# ================================================================
|
||||
# STEP 6: TEST TRAINING SERVICE WITH TENANT ID
|
||||
# ================================================================
|
||||
|
||||
log_step "Step 6: Testing training service through gateway"
|
||||
|
||||
# Only test with valid tenant ID
|
||||
if [ "$TENANT_ID" != "00000000-0000-0000-0000-000000000000" ]; then
|
||||
TRAINING_RESPONSE=$(curl -s -X POST "$API_BASE/api/v1/training/jobs" \
|
||||
-H "Authorization: Bearer $ACCESS_TOKEN" \
|
||||
-H "X-Tenant-ID: $TENANT_ID" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"include_weather": true,
|
||||
"include_traffic": false,
|
||||
"min_data_points": 30
|
||||
}')
|
||||
|
||||
echo "Training Service Response:"
|
||||
echo "$TRAINING_RESPONSE" | jq '.'
|
||||
|
||||
if echo "$TRAINING_RESPONSE" | jq -e '.job_id // .message' > /dev/null; then
|
||||
log_success "Training service access successful!"
|
||||
else
|
||||
log_warning "Training service access may have issues"
|
||||
fi
|
||||
else
|
||||
log_warning "Skipping training service test - no valid tenant ID"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# ================================================================
|
||||
# STEP 7: TOKEN REFRESH
|
||||
# ================================================================
|
||||
|
||||
log_step "Step 7: Testing token refresh"
|
||||
|
||||
REFRESH_RESPONSE=$(curl -s -X POST "$AUTH_BASE/refresh" \
|
||||
-H "Content-Type: application/json" \
|
||||
@@ -268,19 +294,19 @@ fi
|
||||
echo ""
|
||||
|
||||
# ================================================================
|
||||
# STEP 7: DIRECT SERVICE HEALTH CHECKS
|
||||
# STEP 8: DIRECT SERVICE HEALTH CHECKS
|
||||
# ================================================================
|
||||
|
||||
log_step "Step 7: Testing direct service access (without gateway)"
|
||||
log_step "Step 8: Testing direct service access (without gateway)"
|
||||
|
||||
# Test auth service directly
|
||||
log_step "7a. Auth service direct health check"
|
||||
log_step "8a. Auth service direct health check"
|
||||
AUTH_HEALTH=$(curl -s -X GET "http://localhost:8001/health")
|
||||
echo "Auth Service Health:"
|
||||
echo "$AUTH_HEALTH" | jq '.'
|
||||
|
||||
# Test other services if available
|
||||
log_step "7b. Other services health check"
|
||||
log_step "8b. Other services health check"
|
||||
|
||||
services=("8002:Training" "8003:Forecasting" "8004:Data" "8005:Tenant" "8006:Notification")
|
||||
|
||||
@@ -299,10 +325,10 @@ done
|
||||
echo ""
|
||||
|
||||
# ================================================================
|
||||
# STEP 8: LOGOUT
|
||||
# STEP 9: LOGOUT
|
||||
# ================================================================
|
||||
|
||||
log_step "Step 8: Logging out user"
|
||||
log_step "Step 9: Logging out user"
|
||||
|
||||
LOGOUT_RESPONSE=$(curl -s -X POST "$AUTH_BASE/logout" \
|
||||
-H "Authorization: Bearer $ACCESS_TOKEN" \
|
||||
@@ -342,12 +368,12 @@ echo ""
|
||||
echo "Services Tested:"
|
||||
echo " 🌐 API Gateway"
|
||||
echo " 🔐 Auth Service"
|
||||
echo " 🏢 Tenant Service (bakery registration)"
|
||||
echo " 📊 Data Service (through gateway)"
|
||||
echo " 🤖 Training Service (through gateway)"
|
||||
echo " 🏢 Tenant Service (bakery registration)"
|
||||
echo ""
|
||||
|
||||
if [ -n "$TENANT_ID" ]; then
|
||||
if [ "$TENANT_ID" != "00000000-0000-0000-0000-000000000000" ]; then
|
||||
echo "Tenant Created:"
|
||||
echo " 🏪 Tenant ID: $TENANT_ID"
|
||||
echo ""
|
||||
|
||||
Reference in New Issue
Block a user