$baseUrl = "https://classnotify.paradise.eu.org" $ErrorActionPreference = "Continue" Write-Host "==========================================" -ForegroundColor Cyan Write-Host " ClassNotify P0 Security Verification " -ForegroundColor Cyan Write-Host "==========================================" -ForegroundColor Cyan # 1. Health check Write-Host "`n[Test 1] Health Check Probe..." -ForegroundColor Yellow $health = Invoke-RestMethod -Uri "$baseUrl/api/health" -Method Get Write-Host "Status: $($health.status), Version: $($health.version)" -ForegroundColor Green # 2. Login as SchoolAdmin (Beijing No.4) Write-Host "`n[Test 2] Login as SchoolAdmin (admin_bj4)..." -ForegroundColor Yellow $adminUser = if ($env:CLASSNOTIFY_SCHOOLADMIN_USERNAME) { $env:CLASSNOTIFY_SCHOOLADMIN_USERNAME } else { "admin_bj4" } $adminPass = $env:CLASSNOTIFY_SCHOOLADMIN_PASSWORD if (-not $adminPass) { throw "CLASSNOTIFY_SCHOOLADMIN_PASSWORD is required" } $adminLogin = @{ username = $adminUser; password = $adminPass } | ConvertTo-Json $adminRes = Invoke-RestMethod -Uri "$baseUrl/api/auth/login" -Method Post -Body $adminLogin -ContentType "application/json" $adminToken = $adminRes.token Write-Host "Logged in as: $($adminRes.fullName), Role: $($adminRes.role)" -ForegroundColor Green # 3. P0-02 Test: SchoolAdmin attempts to create a SuperAdmin (Privilege Escalation) Write-Host "`n[Test 3] P0-02: SchoolAdmin attempts to create SuperAdmin account..." -ForegroundColor Yellow $badUser = @{ username = "hacker_admin_$(Get-Random)" password = "password123" fullName = "Hacker SuperAdmin" role = "SuperAdmin" } | ConvertTo-Json $adminHeaders = @{ Authorization = "Bearer $adminToken" } try { $createRes = Invoke-RestMethod -Uri "$baseUrl/api/schooladmin/teachers" -Method Post -Headers $adminHeaders -Body $badUser -ContentType "application/json" Write-Host "Created user response: $($createRes | ConvertTo-Json -Compress)" # Verify the user's actual role in the teacher list (must NOT be SuperAdmin) $teachers = Invoke-RestMethod -Uri "$baseUrl/api/schooladmin/teachers" -Method Get -Headers $adminHeaders $createdUser = $teachers | Where-Object { $_.fullName -eq "Hacker SuperAdmin" } if ($createdUser.role -eq "SuperAdmin") { Write-Error "FAIL: P0-02 vulnerability detected! User was created with SuperAdmin role!" } else { Write-Host "PASS: Privilege escalation blocked! Role was forced to: $($createdUser.role)" -ForegroundColor Green } } catch { Write-Host "PASS: Create SuperAdmin rejected with error: $($_.Exception.Message)" -ForegroundColor Green } # 4. P0-12 Test: Teacher attempts to call /api/device/generate-code (Must Fail 403 Forbidden) Write-Host "`n[Test 4] P0-12: Teacher attempts to generate device activation code..." -ForegroundColor Yellow $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" } $teacherLogin = @{ username = $teacherUser; password = $teacherPass } | ConvertTo-Json $teacherRes = Invoke-RestMethod -Uri "$baseUrl/api/auth/login" -Method Post -Body $teacherLogin -ContentType "application/json" $teacherHeaders = @{ Authorization = "Bearer $($teacherRes.token)" } try { Invoke-RestMethod -Uri "$baseUrl/api/device/generate-code?classId=cls_801" -Method Post -Headers $teacherHeaders Write-Error "FAIL: P0-12 vulnerability detected! Teacher was able to generate activation code!" } catch { Write-Host "PASS: Teacher denied from generating code (403 Forbidden): $($_.Exception.Message)" -ForegroundColor Green } # 5. P0-12 Test: SchoolAdmin attempts to generate code for nonexistent / cross-tenant class (Must Fail 404) Write-Host "`n[Test 5] P0-12: SchoolAdmin attempts to generate code for nonexistent class..." -ForegroundColor Yellow try { Invoke-RestMethod -Uri "$baseUrl/api/schooladmin/activation-codes?classId=cls_nonexistent_999" -Method Post -Headers $adminHeaders Write-Error "FAIL: Nonexistent class code generation should have failed!" } catch { Write-Host "PASS: Code generation for invalid class rejected: $($_.Exception.Message)" -ForegroundColor Green } # 6. P0-12 Test: Valid code generation by SchoolAdmin for existing class Write-Host "`n[Test 6] Valid code generation by SchoolAdmin for cls_801..." -ForegroundColor Yellow $validCodeRes = Invoke-RestMethod -Uri "$baseUrl/api/schooladmin/activation-codes?classId=cls_801" -Method Post -Headers $adminHeaders Write-Host "PASS: Successfully generated valid activation code: $($validCodeRes.code)" -ForegroundColor Green Write-Host "`n==========================================" -ForegroundColor Cyan Write-Host " All P0 Verification Tests Completed! " -ForegroundColor Cyan Write-Host "==========================================" -ForegroundColor Cyan