# Test para verificar sincronización de incidentes críticos # entre módulo Auditoría y módulo Seguridad Write-Host "`n=== TEST: Sincronización de Incidentes Críticos ===" -ForegroundColor Cyan # 1. Login Write-Host "`n1. Autenticando..." -ForegroundColor Yellow $loginBody = @{ email = "admin@aduanasoft.com" password = "admin123" tenant_slug = "aduanasoft" } | ConvertTo-Json try { $loginResponse = Invoke-RestMethod -Uri "http://localhost/api/v1/auth/login" -Method Post -Body $loginBody -ContentType "application/json" $token = $loginResponse.access_token $headers = @{ "Authorization" = "Bearer $token" } Write-Host "✓ Autenticado correctamente" -ForegroundColor Green } catch { Write-Host "✗ Error en login: $_" -ForegroundColor Red exit 1 } # 2. Obtener stats del módulo Auditoría Write-Host "`n2. Consultando módulo Auditoría (/audit/stats)..." -ForegroundColor Yellow try { $auditStats = Invoke-RestMethod -Uri "http://localhost/api/v1/audit/stats" -Headers $headers $auditCritical = $auditStats.critical_today Write-Host "✓ Incidentes críticos en Auditoría: $auditCritical" -ForegroundColor Green } catch { Write-Host "✗ Error consultando Auditoría: $_" -ForegroundColor Red exit 1 } # 3. Obtener stats del módulo Seguridad Write-Host "`n3. Consultando módulo Seguridad (/audit/security/analysis)..." -ForegroundColor Yellow try { $securityAnalysis = Invoke-RestMethod -Uri "http://localhost/api/v1/audit/security/analysis?hours=24" -Headers $headers $securityCritical = $securityAnalysis.critical_actions_count Write-Host "✓ Acciones críticas en Seguridad: $securityCritical" -ForegroundColor Green } catch { Write-Host "✗ Error consultando Seguridad: $_" -ForegroundColor Red exit 1 } # 4. Comparar resultados Write-Host "`n4. Comparación:" -ForegroundColor Yellow Write-Host " Auditoría: $auditCritical incidentes críticos" -ForegroundColor White Write-Host " Seguridad: $securityCritical acciones críticas" -ForegroundColor White if ($auditCritical -eq $securityCritical) { Write-Host "`n✓ SINCRONIZADOS: Ambos módulos reportan el mismo número" -ForegroundColor Green Write-Host " Los contadores están alineados correctamente." -ForegroundColor Green } else { Write-Host "`n✗ DESINCRONIZADOS: Los números no coinciden" -ForegroundColor Red Write-Host " Diferencia: $([Math]::Abs($auditCritical - $securityCritical)) registros" -ForegroundColor Red } Write-Host "`n=== Detalles adicionales ===" -ForegroundColor Cyan Write-Host "Amenazas detectadas: $($securityAnalysis.total_threats_detected)" -ForegroundColor White Write-Host "Nivel de riesgo: $($securityAnalysis.overall_risk_level)" -ForegroundColor White Write-Host "Login fallidos: $($securityAnalysis.failed_login_attempts)" -ForegroundColor White Write-Host "IPs sospechosas: $($securityAnalysis.suspicious_ips_count)" -ForegroundColor White Write-Host "`n=== Test completado ===" -ForegroundColor Cyan