$baseUrl = "https://classnotify.paradise.eu.org" Write-Host "=== 1. Public Health Check ===" -ForegroundColor Cyan $health = Invoke-RestMethod -Uri "$baseUrl/" -Method Get $health | ConvertTo-Json Write-Host "`n=== 2. Teacher Login (JWT) ===" -ForegroundColor Cyan $teacherUser = if ($env:CLASSNOTIFY_E2E_USERNAME) { $env:CLASSNOTIFY_E2E_USERNAME } else { "teacher_zhang" } $teacherPass = $env:CLASSNOTIFY_E2E_PASSWORD if (-not $teacherPass) { throw "CLASSNOTIFY_E2E_PASSWORD is required" } $loginBody = @{ username = $teacherUser; password = $teacherPass } | ConvertTo-Json $loginRes = Invoke-RestMethod -Uri "$baseUrl/api/auth/login" -Method Post -Body $loginBody -ContentType "application/json" Write-Host "Teacher: $($loginRes.fullName), Tenant: $($loginRes.tenantId)" $token = $loginRes.token Write-Host "`n=== 3. Authorized Teacher Send Notification ===" -ForegroundColor Cyan $headers = @{ Authorization = "Bearer $token" } $notifBody = @{ classId = "cls_801" studentName = "Zhang San" title = "Office Call" message = "Zhang San, please come to Office 301 immediately" voice = $true shake = $true durationSeconds = 15 } | ConvertTo-Json $sendRes = Invoke-RestMethod -Uri "$baseUrl/api/notification/send" -Method Post -Headers $headers -Body $notifBody -ContentType "application/json" $sendRes | ConvertTo-Json Write-Host "`n=== 4. Anonymous Send Attempt (Must Fail 401) ===" -ForegroundColor Cyan try { Invoke-RestMethod -Uri "$baseUrl/api/notification/send" -Method Post -Body $notifBody -ContentType "application/json" Write-Error "Anonymous send should have failed!" } catch { Write-Host "Anonymous send correctly rejected: $($_.Exception.Message)" -ForegroundColor Green } Write-Host "`n=== 5. Cross-Tenant Notification Attempt (Must Fail 403) ===" -ForegroundColor Cyan try { $teacherLiPass = $env:CLASSNOTIFY_TEACHER_LI_PASSWORD if (-not $teacherLiPass) { $teacherLiPass = $teacherPass } $loginLi = @{ username = "teacher_li"; password = $teacherLiPass } | ConvertTo-Json $liRes = Invoke-RestMethod -Uri "$baseUrl/api/auth/login" -Method Post -Body $loginLi -ContentType "application/json" $liHeaders = @{ Authorization = "Bearer $($liRes.token)" } $crossBody = @{ classId = "cls_802" # cls_802 only exists in Beijing No.4, NOT in Shanghai High studentName = "Wang Wu" title = "Cross Tenant Attempt" message = "Testing cross tenant isolation" } | ConvertTo-Json Invoke-RestMethod -Uri "$baseUrl/api/notification/send" -Method Post -Headers $liHeaders -Body $crossBody -ContentType "application/json" Write-Error "Cross-tenant send should have failed!" } catch { Write-Host "Cross-tenant send correctly rejected: $($_.Exception.Message)" -ForegroundColor Green } Write-Host "`n=== ALL PRODUCTION SECURITY CHECKS PASSED ===" -ForegroundColor Green