79 lines
3.6 KiB
PowerShell
79 lines
3.6 KiB
PowerShell
# Test Windows Print Service CORS and Endpoints
|
|
# Run this PowerShell script to test the service
|
|
|
|
Write-Host "Testing Quality Label Printing Service..." -ForegroundColor Green
|
|
Write-Host "=========================================" -ForegroundColor Green
|
|
|
|
# Test 1: Health check
|
|
Write-Host "`n1. Testing Health Endpoint..." -ForegroundColor Yellow
|
|
try {
|
|
$response = Invoke-RestMethod -Uri "http://localhost:8765/health" -Method GET -TimeoutSec 5
|
|
Write-Host "✅ Health check successful:" -ForegroundColor Green
|
|
$response | ConvertTo-Json -Depth 3
|
|
} catch {
|
|
Write-Host "❌ Health check failed: $($_.Exception.Message)" -ForegroundColor Red
|
|
}
|
|
|
|
# Test 2: CORS preflight (OPTIONS request)
|
|
Write-Host "`n2. Testing CORS Preflight (OPTIONS)..." -ForegroundColor Yellow
|
|
try {
|
|
$headers = @{
|
|
'Origin' = 'http://localhost:5000'
|
|
'Access-Control-Request-Method' = 'POST'
|
|
'Access-Control-Request-Headers' = 'Content-Type'
|
|
}
|
|
|
|
$response = Invoke-WebRequest -Uri "http://localhost:8765/print/silent" -Method OPTIONS -Headers $headers -TimeoutSec 5
|
|
Write-Host "✅ CORS preflight successful - Status: $($response.StatusCode)" -ForegroundColor Green
|
|
|
|
# Check CORS headers
|
|
$corsHeaders = @('Access-Control-Allow-Origin', 'Access-Control-Allow-Methods', 'Access-Control-Allow-Headers')
|
|
foreach ($header in $corsHeaders) {
|
|
if ($response.Headers[$header]) {
|
|
Write-Host " $header: $($response.Headers[$header])" -ForegroundColor Cyan
|
|
} else {
|
|
Write-Host " ❌ Missing header: $header" -ForegroundColor Red
|
|
}
|
|
}
|
|
} catch {
|
|
Write-Host "❌ CORS preflight failed: $($_.Exception.Message)" -ForegroundColor Red
|
|
}
|
|
|
|
# Test 3: Printers endpoint
|
|
Write-Host "`n3. Testing Printers Endpoint..." -ForegroundColor Yellow
|
|
try {
|
|
$response = Invoke-RestMethod -Uri "http://localhost:8765/printers" -Method GET -TimeoutSec 5
|
|
Write-Host "✅ Printers endpoint successful:" -ForegroundColor Green
|
|
$response | ConvertTo-Json -Depth 3
|
|
} catch {
|
|
Write-Host "❌ Printers endpoint failed: $($_.Exception.Message)" -ForegroundColor Red
|
|
}
|
|
|
|
# Test 4: Service status
|
|
Write-Host "`n4. Checking Windows Service Status..." -ForegroundColor Yellow
|
|
try {
|
|
$service = Get-Service -Name "QualityLabelPrinting" -ErrorAction Stop
|
|
Write-Host "✅ Service Status: $($service.Status)" -ForegroundColor Green
|
|
Write-Host " Service Name: $($service.Name)" -ForegroundColor Cyan
|
|
Write-Host " Display Name: $($service.DisplayName)" -ForegroundColor Cyan
|
|
} catch {
|
|
Write-Host "❌ Service not found or error: $($_.Exception.Message)" -ForegroundColor Red
|
|
}
|
|
|
|
# Test 5: Check service logs
|
|
Write-Host "`n5. Recent Service Logs..." -ForegroundColor Yellow
|
|
$logPath = "C:\Program Files\QualityLabelPrinting\PrintService\print_service.log"
|
|
if (Test-Path $logPath) {
|
|
Write-Host "📋 Last 10 log entries:" -ForegroundColor Cyan
|
|
Get-Content $logPath -Tail 10 | ForEach-Object { Write-Host " $_" -ForegroundColor White }
|
|
} else {
|
|
Write-Host "❌ Log file not found at: $logPath" -ForegroundColor Red
|
|
}
|
|
|
|
Write-Host "`n=========================================" -ForegroundColor Green
|
|
Write-Host "Service test completed!" -ForegroundColor Green
|
|
Write-Host "`nNext steps:" -ForegroundColor Yellow
|
|
Write-Host "1. If any tests failed, restart the service: sc restart QualityLabelPrinting" -ForegroundColor White
|
|
Write-Host "2. Check firewall settings if connection refused" -ForegroundColor White
|
|
Write-Host "3. Verify no other applications using port 8765" -ForegroundColor White
|
|
Write-Host "4. Test in browser: http://localhost:8765/health" -ForegroundColor White |