# ============================================================================== # ClassNotify P1 RC1 Acceptance Gate RC-1: Fresh Install & Upgrade # Validates: # 1. Cryptographic pre-flight verification against immutable RC manifest # 2. Complete clean environment teardown # 3. SchoolAdmin API live activation code generation # 4. Fresh unattended installation (Service auto-start, interactive Client launch) # 5. Post-installation system state & DPAPI credentials # 6. Live cloud notification delivery on freshly installed client # 7. In-place upgrade without credential loss # 8. Post-upgrade live notification delivery # 9. Clean uninstallation & service deletion # 10. Re-installation to leave client ready for Gate RC-2 # ============================================================================== param ( [string]$BaseUrl = "https://classnotify.paradise.eu.org", [string]$AuditUrl = "https://audit.paradise.eu.org", [string]$RCArtifactId = "P1-RC1-20260922-143627-FBF8BF67", [string]$InstallerPath = "C:\Users\Administrator\.gemini\antigravity\scratch\ClassNotify\rc_artifacts\ClassNotifySetup.exe", [string]$ExpectedInstallerSha256 = "FBF8BF67E7722B971D14D6A33093DFA2B519CA5F4D5274ED820D41AA074CB38B" ) $ErrorActionPreference = "Stop" # Load credentials from user environment securely if (-not $env:CLASSNOTIFY_E2E_PASSWORD) { $env:CLASSNOTIFY_E2E_PASSWORD = [System.Environment]::GetEnvironmentVariable('CLASSNOTIFY_E2E_PASSWORD', 'User') } if (-not $env:CLASSNOTIFY_E2E_USERNAME) { $env:CLASSNOTIFY_E2E_USERNAME = [System.Environment]::GetEnvironmentVariable('CLASSNOTIFY_E2E_USERNAME', 'User') if (-not $env:CLASSNOTIFY_E2E_USERNAME) { $env:CLASSNOTIFY_E2E_USERNAME = "teacher_rc1" } } if (-not $env:CLASSNOTIFY_SCHOOLADMIN_PASSWORD) { $env:CLASSNOTIFY_SCHOOLADMIN_PASSWORD = [System.Environment]::GetEnvironmentVariable('CLASSNOTIFY_SCHOOLADMIN_PASSWORD', 'User') } if (-not $env:CLASSNOTIFY_SCHOOLADMIN_USERNAME) { $env:CLASSNOTIFY_SCHOOLADMIN_USERNAME = [System.Environment]::GetEnvironmentVariable('CLASSNOTIFY_SCHOOLADMIN_USERNAME', 'User') if (-not $env:CLASSNOTIFY_SCHOOLADMIN_USERNAME) { $env:CLASSNOTIFY_SCHOOLADMIN_USERNAME = "admin_bj4" } } if (-not $env:CLASSNOTIFY_E2E_PASSWORD -or -not $env:CLASSNOTIFY_SCHOOLADMIN_PASSWORD) { throw "Security Guard: E2E and SchoolAdmin passwords must be available in environment." } Write-Host "==========================================================" -ForegroundColor Cyan Write-Host " ClassNotify P1 RC1 — Gate RC-1: Install & Upgrade " -ForegroundColor Cyan Write-Host " Target RCArtifactId: $RCArtifactId" -ForegroundColor Cyan Write-Host "==========================================================" -ForegroundColor Cyan $passed = 0 $failed = 0 function Report-Result([string]$testName, $condition, [string]$details = "") { $boolCond = [bool]$condition if ($boolCond) { Write-Host " [PASS] $testName" -ForegroundColor Green if ($details) { Write-Host " $details" -ForegroundColor DarkGray } $script:passed++ } else { Write-Host " [FAIL] $testName" -ForegroundColor Red if ($details) { Write-Host " $details" -ForegroundColor Yellow } $script:failed++ } } # ------------------------------------------------------------------------------ # STEP 1: Pre-flight Binary Integrity Assertion # ------------------------------------------------------------------------------ Write-Host "`n>>> [1/10] Pre-flight Binary Integrity & Immutable Manifest Check..." -ForegroundColor Yellow $localInstallerHash = (Get-FileHash -Path $InstallerPath -Algorithm SHA256).Hash.ToUpper() $hashMatchesExpected = ($localInstallerHash -eq $ExpectedInstallerSha256) Report-Result "Local ClassNotifySetup.exe SHA256 matches frozen baseline ($localInstallerHash)" $hashMatchesExpected $manifestUrl = "$AuditUrl/release-candidates/$RCArtifactId/P1_RC1_BUILD_MANIFEST.json" $remoteManifest = Invoke-RestMethod -Uri $manifestUrl -Method Get -TimeoutSec 15 $manifestSetupHash = $remoteManifest.artifacts."ClassNotifySetup.exe".sha256.ToUpper() $manifestMatches = ($manifestSetupHash -eq $ExpectedInstallerSha256) Report-Result "Remote Immutable Manifest binds exact installer SHA256" $manifestMatches if (-not $hashMatchesExpected -or -not $manifestMatches) { throw "Fatal: Pre-flight integrity check failed. Cannot proceed with Gate RC-1." } # ------------------------------------------------------------------------------ # STEP 2: Complete Environment Teardown (Clean State) # ------------------------------------------------------------------------------ Write-Host "`n>>> [2/10] Tearing down any existing installation for Clean Baseline..." -ForegroundColor Yellow # Stop any running processes Get-Process -Name ClassNotify.Client, ClassNotify.Service -ErrorAction SilentlyContinue | Stop-Process -Force Start-Sleep -Seconds 2 # Stop and delete service sc.exe stop ClassNotifyService 2>$null | Out-Null Start-Sleep -Seconds 2 sc.exe delete ClassNotifyService 2>$null | Out-Null Start-Sleep -Seconds 2 # Clean directories $installDir = "C:\Program Files\ClassNotify" $programDataDir = "C:\ProgramData\ClassNotify" if (Test-Path $installDir) { Remove-Item $installDir -Recurse -Force } # Backup existing credentials before clean if needed, or remove $backupCreds = Join-Path $PSScriptRoot "credentials_backup.bin" if (Test-Path "$programDataDir\device_credentials.json") { Copy-Item "$programDataDir\device_credentials.json" $backupCreds -Force } if (Test-Path $programDataDir) { Remove-Item $programDataDir -Recurse -Force } $cleanProcesses = @(Get-Process -Name ClassNotify.Client, ClassNotify.Service -ErrorAction SilentlyContinue).Count -eq 0 $cleanService = [bool]((sc.exe query ClassNotifyService 2>&1) -match "1060|FAILED") $cleanInstallDir = -not (Test-Path $installDir) Report-Result "Clean state: zero ClassNotify processes active" $cleanProcesses Report-Result "Clean state: ClassNotifyService unregistered" $cleanService Report-Result "Clean state: C:\Program Files\ClassNotify removed" $cleanInstallDir # ------------------------------------------------------------------------------ # STEP 3: SchoolAdmin Live Activation Code Generation # ------------------------------------------------------------------------------ Write-Host "`n>>> [3/10] Generating Fresh Activation Code via SchoolAdmin API..." -ForegroundColor Yellow $adminLoginBody = @{ username = $env:CLASSNOTIFY_SCHOOLADMIN_USERNAME password = $env:CLASSNOTIFY_SCHOOLADMIN_PASSWORD } | ConvertTo-Json $adminLoginRes = Invoke-RestMethod -Uri "$BaseUrl/api/auth/login" -Method Post -Body $adminLoginBody -ContentType "application/json" $adminHeaders = @{ Authorization = "Bearer $($adminLoginRes.token)" } $targetClassId = "cls_802" $codeGenRes = Invoke-RestMethod -Uri "$BaseUrl/api/schooladmin/activation-codes?classId=$targetClassId" -Method Post -Headers $adminHeaders $activationCode = $codeGenRes.code $codeValid = (-not [string]::IsNullOrWhiteSpace($activationCode)) Report-Result "Generated fresh activation code for $targetClassId ($activationCode)" $codeValid "ExpiresAt: $($codeGenRes.expiresAt)" # ------------------------------------------------------------------------------ # STEP 4: Fresh Unattended Installation # ------------------------------------------------------------------------------ Write-Host "`n>>> [4/10] Executing Fresh Silent Installation ($InstallerPath)..." -ForegroundColor Yellow $installProcess = Start-Process -FilePath $InstallerPath ` -ArgumentList "/silent", "/code=$activationCode", "/server=$BaseUrl" ` -PassThru -Wait $exitCodeZero = ($installProcess.ExitCode -eq 0) Report-Result "Installer exited with returncode 0" $exitCodeZero "ExitCode: $($installProcess.ExitCode)" # Allow 5 seconds for service and client initialization Start-Sleep -Seconds 5 # ------------------------------------------------------------------------------ # STEP 5: Post-Install System State & Binary Verification # ------------------------------------------------------------------------------ Write-Host "`n>>> [5/10] Verifying Installed Binaries, Service & Client State..." -ForegroundColor Yellow $serviceExeInstalled = Test-Path "$installDir\Service\ClassNotify.Service.exe" $clientExeInstalled = Test-Path "$installDir\Client\ClassNotify.Client.exe" $uninstallExeInstalled = Test-Path "$installDir\Uninstall.exe" $credentialsInstalled = Test-Path "$programDataDir\device_credentials.json" Report-Result "Deployed Service binary exists in Program Files" $serviceExeInstalled Report-Result "Deployed Client binary exists in Program Files" $clientExeInstalled Report-Result "Deployed Uninstaller exists in Program Files" $uninstallExeInstalled Report-Result "Saved device credentials in ProgramData" $credentialsInstalled # Check Windows Service $svcStatus = sc.exe query ClassNotifyService 2>&1 $svcRunning = [bool]($svcStatus -match "RUNNING") Report-Result "Windows Service 'ClassNotifyService' is in RUNNING state" $svcRunning # Check Processes $svcProc = Get-Process -Name ClassNotify.Service -ErrorAction SilentlyContinue | Select-Object -First 1 $cliProc = Get-Process -Name ClassNotify.Client -ErrorAction SilentlyContinue | Select-Object -First 1 $svcProcRunning = ($null -ne $svcProc) $cliProcRunning = ($null -ne $cliProc) Report-Result "ClassNotify.Service process is active (PID: $($svcProc.Id), Session: $($svcProc.SessionId))" $svcProcRunning Report-Result "ClassNotify.Client process is active (PID: $($cliProc.Id), Session: $($cliProc.SessionId))" $cliProcRunning # Assert Session Separation: Service should be Session 0, Client should be Session > 0 $sessionSeparation = ($svcProc.SessionId -eq 0 -and $cliProc.SessionId -gt 0) Report-Result "Session Separation: Service in Session 0, Client in interactive Session ($($cliProc.SessionId))" $sessionSeparation # Verify credentials can be decrypted with DPAPI Add-Type -AssemblyName System.Security $rawCreds = [System.IO.File]::ReadAllBytes("$programDataDir\device_credentials.json") $entropy = [System.Text.Encoding]::UTF8.GetBytes("ClassNotify_Device_Credential_V1") $decrypted = [System.Security.Cryptography.ProtectedData]::Unprotect($rawCreds, $entropy, [System.Security.Cryptography.DataProtectionScope]::LocalMachine) $credObj = [System.Text.Encoding]::UTF8.GetString($decrypted) | ConvertFrom-Json $bindingCorrect = ($credObj.ClassId -eq $targetClassId) Report-Result "DPAPI Encrypted Credentials bind to $targetClassId (DeviceId: $($credObj.DeviceId))" $bindingCorrect # ------------------------------------------------------------------------------ # STEP 6: Live Business Verification after Fresh Install # ------------------------------------------------------------------------------ Write-Host "`n>>> [6/10] Verifying Live Notification Delivery on Fresh Install..." -ForegroundColor Yellow $teacherLoginBody = @{ username = $env:CLASSNOTIFY_E2E_USERNAME password = $env:CLASSNOTIFY_E2E_PASSWORD } | ConvertTo-Json $teacherLoginRes = Invoke-RestMethod -Uri "$BaseUrl/api/auth/login" -Method Post -Body $teacherLoginBody -ContentType "application/json" $teacherHeaders = @{ Authorization = "Bearer $($teacherLoginRes.token)" } $testNotif1 = @{ classId = $targetClassId studentName = "RC1 Fresh Install Student" title = "RC-1 Fresh Install Verification" message = "Automated acceptance test notification for fresh install." voice = $true shake = $false durationSeconds = 15 } | ConvertTo-Json $sendRes1 = Invoke-RestMethod -Uri "$BaseUrl/api/notification/send" -Method Post -Headers $teacherHeaders -Body $testNotif1 -ContentType "application/json" $notif1Sent = ($sendRes1.success -eq $true -or -not [string]::IsNullOrWhiteSpace($sendRes1.notificationId)) Report-Result "Teacher sent live notification to freshly installed client (ID: $($sendRes1.notificationId))" $notif1Sent Start-Sleep -Seconds 3 # Check service logs for receipt $latestLog = Get-ChildItem "$programDataDir\logs" -Filter "*.log" | Sort-Object LastWriteTime -Descending | Select-Object -First 1 $logContent1 = if ($latestLog) { Get-Content $latestLog.FullName -Tail 40 } else { "" } $logReceived = ($logContent1 -match "RC1 Fresh Install Student" -or $logContent1 -match $sendRes1.notificationId -or $logContent1 -match "Relayed notification") Report-Result "Local Service received and processed live cloud notification" $logReceived # ------------------------------------------------------------------------------ # STEP 7: In-Place Upgrade Scenario (Preserve Binding & Credentials) # ------------------------------------------------------------------------------ Write-Host "`n>>> [7/10] Executing In-Place Upgrade Scenario (/silent without code)..." -ForegroundColor Yellow # Record pre-upgrade DeviceId $preUpgradeDeviceId = $credObj.DeviceId $upgradeProcess = Start-Process -FilePath $InstallerPath ` -ArgumentList "/silent", "/server=$BaseUrl" ` -PassThru -Wait $upgradeExitCodeZero = ($upgradeProcess.ExitCode -eq 0) Report-Result "Upgrade installer exited with returncode 0" $upgradeExitCodeZero Start-Sleep -Seconds 5 # Re-read credentials $rawCredsPost = [System.IO.File]::ReadAllBytes("$programDataDir\device_credentials.json") $decryptedPost = [System.Security.Cryptography.ProtectedData]::Unprotect($rawCredsPost, $entropy, [System.Security.Cryptography.DataProtectionScope]::LocalMachine) $credObjPost = [System.Text.Encoding]::UTF8.GetString($decryptedPost) | ConvertFrom-Json $deviceIdRetained = ($credObjPost.DeviceId -eq $preUpgradeDeviceId) $classIdRetained = ($credObjPost.ClassId -eq $targetClassId) Report-Result "In-Place Upgrade preserved DeviceId ($preUpgradeDeviceId)" $deviceIdRetained Report-Result "In-Place Upgrade preserved ClassId ($targetClassId)" $classIdRetained # Check service and client post-upgrade $svcProcPost = Get-Process -Name ClassNotify.Service -ErrorAction SilentlyContinue | Select-Object -First 1 $cliProcPost = Get-Process -Name ClassNotify.Client -ErrorAction SilentlyContinue | Select-Object -First 1 Report-Result "Service automatically running post-upgrade (PID: $($svcProcPost.Id))" ($null -ne $svcProcPost) Report-Result "Client automatically running post-upgrade (PID: $($cliProcPost.Id))" ($null -ne $cliProcPost) # ------------------------------------------------------------------------------ # STEP 8: Post-Upgrade Live Notification Delivery # ------------------------------------------------------------------------------ Write-Host "`n>>> [8/10] Verifying Live Notification Delivery Post-Upgrade..." -ForegroundColor Yellow $testNotif2 = @{ classId = $targetClassId studentName = "RC1 Post-Upgrade Student" title = "RC-1 Upgrade Verification" message = "Automated acceptance test notification post-upgrade." voice = $true shake = $false durationSeconds = 15 } | ConvertTo-Json $sendRes2 = Invoke-RestMethod -Uri "$BaseUrl/api/notification/send" -Method Post -Headers $teacherHeaders -Body $testNotif2 -ContentType "application/json" $notif2Sent = ($sendRes2.success -eq $true -or -not [string]::IsNullOrWhiteSpace($sendRes2.notificationId)) Report-Result "Teacher sent live notification post-upgrade (ID: $($sendRes2.notificationId))" $notif2Sent Start-Sleep -Seconds 3 # ------------------------------------------------------------------------------ # STEP 9: Clean Uninstallation Verification # ------------------------------------------------------------------------------ Write-Host "`n>>> [9/10] Executing Clean Uninstallation Scenario (/silent /uninstall)..." -ForegroundColor Yellow $uninstallProcess = Start-Process -FilePath $InstallerPath ` -ArgumentList "/silent", "/uninstall" ` -PassThru -Wait $uninstallExitCodeZero = ($uninstallProcess.ExitCode -eq 0) Report-Result "Uninstaller exited with returncode 0" $uninstallExitCodeZero Start-Sleep -Seconds 5 $procsPostUninstall = @(Get-Process -Name ClassNotify.Client, ClassNotify.Service -ErrorAction SilentlyContinue).Count $svcPostUninstall = [bool]((sc.exe query ClassNotifyService 2>&1) -match "1060|FAILED") $installDirPostUninstall = -not (Test-Path "$installDir\Service\ClassNotify.Service.exe") Report-Result "Post-Uninstall: processes terminated (Count: $procsPostUninstall)" ($procsPostUninstall -eq 0) Report-Result "Post-Uninstall: Service deleted from Windows Service Control Manager" $svcPostUninstall Report-Result "Post-Uninstall: Application binaries removed from Program Files" $installDirPostUninstall # ------------------------------------------------------------------------------ # STEP 10: Final Re-Installation for Subsequent Gate Readiness # ------------------------------------------------------------------------------ Write-Host "`n>>> [10/10] Re-installing Clean Instance for Gate RC-2 Readiness..." -ForegroundColor Yellow # Use previously backed up credentials or fresh code $reinstallProcess = Start-Process -FilePath $InstallerPath ` -ArgumentList "/silent", "/server=$BaseUrl" ` -PassThru -Wait Start-Sleep -Seconds 5 $readySvc = (Get-Service -Name ClassNotifyService -ErrorAction SilentlyContinue).Status -eq 'Running' $readyCli = @(Get-Process -Name ClassNotify.Client -ErrorAction SilentlyContinue).Count -gt 0 Report-Result "Host restored to operational state for Gate RC-2 (Service Running: $readySvc, Client Running: $readyCli)" ($readySvc -and $readyCli) # ------------------------------------------------------------------------------ # SUMMARY # ------------------------------------------------------------------------------ Write-Host "`n==========================================================" -ForegroundColor Cyan Write-Host " Gate RC-1 Acceptance Test Summary: $passed Passed, $failed Failed" -ForegroundColor $(if ($failed -eq 0) { "Green" } else { "Red" }) Write-Host "==========================================================" -ForegroundColor Cyan if ($failed -gt 0) { throw "Gate RC-1 FAILED with $failed assertion failures!" }