From 38e78e7163886659b80d5fbc3db1bf3540081d2c Mon Sep 17 00:00:00 2001 From: Urtzi Alfaro Date: Sun, 20 Jul 2025 23:15:57 +0200 Subject: [PATCH] Fix tenant register --- gateway/app/routes/tenant.py | 4 +- scripts/test_unified_auth.sh | 85 +++++++++++------------------- services/auth/docker-compose.yml | 1 - services/tenant/app/api/tenants.py | 2 +- shared/config/base.py | 2 +- 5 files changed, 34 insertions(+), 60 deletions(-) diff --git a/gateway/app/routes/tenant.py b/gateway/app/routes/tenant.py index 1e19e796..ef36ec87 100644 --- a/gateway/app/routes/tenant.py +++ b/gateway/app/routes/tenant.py @@ -12,7 +12,7 @@ from app.core.config import settings logger = logging.getLogger(__name__) router = APIRouter() -@router.post("/") +@router.post("/register") async def create_tenant(request: Request): """Proxy tenant creation to tenant service""" try: @@ -21,7 +21,7 @@ async def create_tenant(request: Request): async with httpx.AsyncClient(timeout=10.0) as client: response = await client.post( - f"{settings.TENANT_SERVICE_URL}/tenants", + f"{settings.TENANT_SERVICE_URL}/api/v1/tenants/register", content=body, headers={ "Content-Type": "application/json", diff --git a/scripts/test_unified_auth.sh b/scripts/test_unified_auth.sh index 54def8e5..68f446f5 100755 --- a/scripts/test_unified_auth.sh +++ b/scripts/test_unified_auth.sh @@ -119,37 +119,6 @@ fi echo "" - -# ================================================================ -# STEP 5: TENANT REGISTRATION (OPTIONAL) -# ================================================================ - -log_step "Step 5: Registering a bakery/tenant" - -BAKERY_RESPONSE=$(curl -s -X POST "$API_BASE/api/v1/tenants/bakeries" \ - -H "Authorization: Bearer $ACCESS_TOKEN" \ - -H "Content-Type: application/json" \ - -d "{ - \"name\": \"Test Bakery $(date +%H%M)\", - \"business_type\": \"bakery\", - \"address\": \"Calle Test 123\", - \"city\": \"Madrid\", - \"postal_code\": \"28001\", - \"phone\": \"+34600123456\" - }") - -echo "Bakery Registration Response:" -echo "$BAKERY_RESPONSE" | jq '.' - -if echo "$BAKERY_RESPONSE" | jq -e '.id' > /dev/null; then - 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" -fi - -echo "" - # ================================================================ # STEP 2: USER LOGIN # ================================================================ @@ -179,30 +148,6 @@ fi echo "" -# ================================================================ -# STEP 3: TOKEN VERIFICATION -# ================================================================ - -log_step "Step 3: Verifying access token" - -VERIFY_RESPONSE=$(curl -s -X POST "$AUTH_BASE/verify" \ - -H "Content-Type: application/json" \ - -d "{ - \"token\": \"$ACCESS_TOKEN\" - }") - -echo "Token Verification Response:" -echo "$VERIFY_RESPONSE" | jq '.' - -if echo "$VERIFY_RESPONSE" | jq -e '.valid' > /dev/null; then - log_success "Token verification successful!" -else - log_error "Token verification failed!" - exit 1 -fi - -echo "" - # ================================================================ # STEP 4: ACCESSING PROTECTED ENDPOINTS # ================================================================ @@ -268,6 +213,36 @@ fi echo "" +# ================================================================ +# STEP 5: TENANT REGISTRATION (OPTIONAL) +# ================================================================ + +log_step "Step 5: Registering a bakery/tenant" + +BAKERY_RESPONSE=$(curl -s -X POST "$API_BASE/api/v1/tenants/register" \ + -H "Authorization: Bearer $ACCESS_TOKEN" \ + -H "Content-Type: application/json" \ + -d "{ + \"name\": \"Test Bakery $(date +%H%M)\", + \"business_type\": \"bakery\", + \"address\": \"Calle Test 123\", + \"city\": \"Madrid\", + \"postal_code\": \"28001\", + \"phone\": \"+34600123456\" + }") + +echo "Bakery Registration Response:" +echo "$BAKERY_RESPONSE" | jq '.' + +if echo "$BAKERY_RESPONSE" | jq -e '.id' > /dev/null; then + 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" +fi + +echo "" + # ================================================================ # STEP 6: TOKEN REFRESH # ================================================================ diff --git a/services/auth/docker-compose.yml b/services/auth/docker-compose.yml index 55c583cc..5f3d7b47 100644 --- a/services/auth/docker-compose.yml +++ b/services/auth/docker-compose.yml @@ -53,7 +53,6 @@ services: - DATABASE_URL=postgresql+asyncpg://auth_user:auth_pass123@auth-db:5432/auth_db - REDIS_URL=redis://redis:6379/0 - RABBITMQ_URL=amqp://bakery:forecast123@rabbitmq:5672/ - - JWT_SECRET_KEY=your-super-secret-jwt-key-change-in-production - DEBUG=true - LOG_LEVEL=INFO ports: diff --git a/services/tenant/app/api/tenants.py b/services/tenant/app/api/tenants.py index a7de8909..3c91fc72 100644 --- a/services/tenant/app/api/tenants.py +++ b/services/tenant/app/api/tenants.py @@ -19,7 +19,7 @@ from shared.auth.decorators import require_authentication, get_current_user, get logger = structlog.get_logger() router = APIRouter() -@router.post("/bakeries", response_model=TenantResponse) +@router.post("/tenants/register", response_model=TenantResponse) @require_authentication async def register_bakery( bakery_data: BakeryRegistration, diff --git a/shared/config/base.py b/shared/config/base.py index 27e839f4..ea17df52 100644 --- a/shared/config/base.py +++ b/shared/config/base.py @@ -87,7 +87,7 @@ class BaseServiceSettings(BaseSettings): # ================================================================ # JWT Configuration - JWT_SECRET_KEY: str = os.getenv("JWT_SECRET_KEY", "change-this-in-production") + JWT_SECRET_KEY: str = os.getenv("JWT_SECRET_KEY", "your-super-secret-jwt-key-change-in-production-min-32-characters-long") JWT_ALGORITHM: str = os.getenv("JWT_ALGORITHM", "HS256") JWT_ACCESS_TOKEN_EXPIRE_MINUTES: int = int(os.getenv("JWT_ACCESS_TOKEN_EXPIRE_MINUTES", "30")) JWT_REFRESH_TOKEN_EXPIRE_DAYS: int = int(os.getenv("JWT_REFRESH_TOKEN_EXPIRE_DAYS", "7"))