<# Testet die Link-Prüfung von launch-rdp.ps1 und launch-ssh.ps1, ohne etwas zu starten. Aufruf (im Ordner mit den Skripten): powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\test-launcher.ps1 #> $ErrorActionPreference = 'Stop' $rdp = Join-Path $PSScriptRoot 'launch-rdp.ps1' $ssh = Join-Path $PSScriptRoot 'launch-ssh.ps1' $fehler = 0 function Pruefe-Gueltig($Skript, $Url, $ErwartetTeil) { try { $b = & $Skript -Url $Url -Pruefen $text = "$($b.Programm) $($b.Argumente) $($b.RdpInhalt)" if ($text.Contains($ErwartetTeil)) { Write-Host "OK $Url" -ForegroundColor Green } else { Write-Host "FEHLER $Url -> '$text' enthält nicht '$ErwartetTeil'" -ForegroundColor Red $script:fehler++ } } catch { Write-Host "FEHLER $Url -> abgelehnt: $($_.Exception.Message)" -ForegroundColor Red $script:fehler++ } } function Pruefe-Ungueltig($Skript, $Url) { try { $b = & $Skript -Url $Url -Pruefen Write-Host "FEHLER $Url -> wurde akzeptiert: $($b.Programm) $($b.Argumente)" -ForegroundColor Red $script:fehler++ } catch { Write-Host "OK $Url (abgelehnt: $($_.Exception.Message))" -ForegroundColor Green } } Write-Host "`n== Gültige RDP-Links ==" -ForegroundColor Cyan Pruefe-Gueltig $rdp 'itrdp://connect?host=test-server-01.example.local&port=3389' '/v:test-server-01.example.local:3389' Pruefe-Gueltig $rdp 'itrdp://connect/?host=192.0.2.10&port=3390' '/v:192.0.2.10:3390' Pruefe-Gueltig $rdp 'itrdp://connect?host=2001%3Adb8%3A%3A1&port=3389' '/v:[2001:db8::1]:3389' Pruefe-Gueltig $rdp 'itrdp://connect?host=srv01' '/v:srv01:3389' Pruefe-Gueltig $rdp 'ITRDP://connect?host=srv01&port=3389&user=test_admin' 'username:s:test_admin' Write-Host "`n== Gültige SSH-Links ==" -ForegroundColor Cyan Pruefe-Gueltig $ssh 'itssh://connect?host=test-server-01.example.local&port=22&user=root' '-p 22 -l root test-server-01.example.local' Pruefe-Gueltig $ssh 'itssh://connect?host=fe80%3A%3A1&port=2222' '-p 2222 fe80::1' Write-Host "`n== Ungültige Links (müssen abgelehnt werden) ==" -ForegroundColor Cyan $ungueltig = @( 'itrdp://connect?host=srv01%3Bcalc.exe', 'itrdp://connect?host=srv01%26whoami', 'itrdp://connect?host=srv01%7Cx', 'itrdp://connect?host=%24(calc)', 'itrdp://connect?host=srv01%20%2Fadmin', 'itrdp://connect?host=srv01%0A', 'itrdp://connect?host=-srv01', 'itrdp://connect?host=%5B2001%3Adb8%3A%3A1%5D', 'itrdp://connect?host=fe80%3A%3A1%25eth0', 'itrdp://connect?host=srv01&port=0', 'itrdp://connect?host=srv01&port=65536', 'itrdp://connect?host=srv01&port=22a', 'itrdp://connect?host=srv01&user=DOMAIN%5Cuser', 'itrdp://connect?host=srv01&user=a%22b', 'itrdp://connect?host=srv01&host=srv02', 'itrdp://connect?host=srv01&cmd=x', 'itrdp://connect?host=srv01 /admin', 'itrdp://andere?host=srv01', 'itssh://connect?host=srv01', 'itrdp://connect?port=3389', '' ) foreach ($u in $ungueltig) { Pruefe-Ungueltig $rdp $u } Pruefe-Ungueltig $ssh 'itssh://connect?host=srv01&user=root%3Bcalc' Pruefe-Ungueltig $ssh 'itrdp://connect?host=srv01' Write-Host '' if ($fehler -eq 0) { Write-Host 'Alle Tests bestanden.' -ForegroundColor Green exit 0 } Write-Host "$fehler Test(s) fehlgeschlagen." -ForegroundColor Red exit 1