forked from openssh/openssh-portable
-
Notifications
You must be signed in to change notification settings - Fork 339
add pester test for event viewer scenarios #788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
63a6b71
add pester test for event viewer scenarios
tgauth e59f226
revert ci changes
tgauth 4e4500c
Update regress/pesterTests/EventLogging.Tests.ps1
tgauth 5bf0c48
Update regress/pesterTests/EventLogging.Tests.ps1
tgauth 3039917
Update EventLogging.Tests.ps1
tgauth 265ff1c
add comments
tgauth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
If ($PSVersiontable.PSVersion.Major -le 2) {$PSScriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path} | ||
Import-Module $PSScriptRoot\CommonUtils.psm1 -Force | ||
Import-Module OpenSSHUtils -Force | ||
$tC = 1 | ||
$tI = 0 | ||
$suite = "EventLogging" | ||
Describe "Tests for admin and non-admin event logs" -Tags "CI" { | ||
BeforeAll { | ||
if($OpenSSHTestInfo -eq $null) | ||
{ | ||
Throw "`$OpenSSHTestInfo is null. Please run Set-OpenSSHTestEnvironment to set test environments." | ||
} | ||
|
||
$testDir = "$($OpenSSHTestInfo["TestDataPath"])\$suite" | ||
if( -not (Test-path $testDir -PathType Container)) | ||
{ | ||
$null = New-Item $testDir -ItemType directory -Force -ErrorAction SilentlyContinue | ||
} | ||
|
||
$server = $OpenSSHTestInfo["Target"] | ||
$nonadminusername = $OpenSSHTestInfo['NonAdminUser'] | ||
$adminusername = $OpenSSHTestInfo['AdminUser'] | ||
$opensshbinpath = $OpenSSHTestInfo['OpenSSHBinPath'] | ||
$password = $OpenSSHTestInfo['TestAccountPW'] | ||
$port = 47003 | ||
$sshdDelay = $OpenSSHTestInfo["DelayTime"] | ||
|
||
# Register OpenSSH events in Event Viewer | ||
$etwman = Join-Path $opensshbinpath "openssh-events.man" | ||
if (-not (Test-Path $etwman -PathType Leaf)) { | ||
throw "openssh events manifest is not present in OpenSSH binary path" | ||
} | ||
wevtutil im "$etwman" | Out-Null | ||
} | ||
|
||
AfterEach { $tI++ } | ||
|
||
AfterAll { | ||
# Unregister etw provider | ||
wevtutil um "$etwman" | ||
} | ||
|
||
Context "Tests Logs for SSH connections" { | ||
BeforeAll { | ||
Add-PasswordSetting -Pass $password | ||
$tI=1 | ||
} | ||
|
||
BeforeEach { | ||
# disable the OpenSSH log channels | ||
wevtutil sl "OpenSSH/Debug" /e:false /q:true | Out-Null | ||
wevtutil sl "OpenSSH/Operational" /e:false /q:true | Out-Null | ||
# clear any existing logs | ||
wevtutil cl "OpenSSH/Debug" | Out-Null | ||
wevtutil cl "OpenSSH/Operational" | Out-Null | ||
# enable the OpenSSH log channels | ||
wevtutil sl "OpenSSH/Debug" /e:true /q:true | Out-Null | ||
wevtutil sl "OpenSSH/Operational" /e:true /q:true | Out-Null | ||
} | ||
|
||
AfterAll { | ||
Remove-PasswordSetting | ||
$tC++ | ||
} | ||
|
||
It "$tC.$tI-Nonadmin SSH Connection" { | ||
$o = ssh -l $nonadminusername test_target echo 1234 | ||
$o | Should Be 1234 | ||
Start-Sleep $sshdDelay | ||
# query the OpenSSH log channels to make sure events were captured | ||
$eventLogDebug = wevtutil qe "OpenSSH/Debug" /c:5 /f:text | ||
$eventLogDebug | Should Not Be $null | ||
$eventLogOperational = wevtutil qe "OpenSSH/Operational" /c:5 /f:text | ||
$eventLogOperational | Should Not Be $null | ||
} | ||
|
||
It "$tC.$tI-Admin SSH Connection" { | ||
$o = ssh -l $adminusername test_target echo 1234 | ||
$o | Should Be 1234 | ||
Start-Sleep $sshdDelay | ||
# query the OpenSSH log channels to make sure events were captured | ||
$eventLogDebug = wevtutil qe "OpenSSH/Debug" /c:5 /f:text | ||
$eventLogDebug | Should Not Be $null | ||
$eventLogOperational = wevtutil qe "OpenSSH/Operational" /c:5 /f:text | ||
$eventLogOperational | Should Not Be $null | ||
} | ||
} | ||
|
||
Context "Tests Logs for SFTP connections" { | ||
|
||
BeforeAll { | ||
|
||
function Setup-KeyBasedAuth | ||
{ | ||
param([string] $Username, [string] $KeyFilePath, [string] $UserProfile) | ||
|
||
$userSSHProfilePath = Join-Path $UserProfile .ssh | ||
|
||
if (-not (Test-Path $userSSHProfilePath -PathType Container)) { | ||
New-Item $userSSHProfilePath -ItemType directory -Force -ErrorAction Stop | Out-Null | ||
} | ||
|
||
$authorizedkeyPath = Join-Path $userSSHProfilePath authorized_keys | ||
|
||
if($OpenSSHTestInfo["NoLibreSSL"]) | ||
{ | ||
ssh-keygen.exe -t ed25519 -f $KeyFilePath -Z -P "" aes128-ctr | ||
} | ||
else | ||
{ | ||
ssh-keygen.exe -t ed25519 -f $KeyFilePath -P "" | ||
} | ||
Copy-Item "$KeyFilePath.pub" $authorizedkeyPath -Force -ErrorAction SilentlyContinue | ||
Repair-AuthorizedKeyPermission -Filepath $authorizedkeyPath -confirm:$false | ||
} | ||
|
||
$AdminUserProfile = $OpenSSHTestInfo['AdminUserProfile'] | ||
$NonAdminUserProfile = $OpenSSHTestInfo['NonAdminUserProfile'] | ||
|
||
$KeyFileName = $nonadminusername + "_sshtest_EventLog_ed25519" | ||
$NonadminKeyFilePath = Join-Path $testDir $keyFileName | ||
Remove-Item -path "$NonadminKeyFilePath*" -Force -ErrorAction SilentlyContinue | ||
Setup-KeyBasedAuth -Username $nonadminusername -KeyFilePath $NonadminKeyFilePath -UserProfile $NonAdminUserProfile | ||
|
||
$KeyFileName = $adminusername + "_sshtest_EventLog_ed25519" | ||
$AdminKeyFilePath = Join-Path $testDir $keyFileName | ||
Remove-Item -path "$AdminKeyFilePath*" -Force -ErrorAction SilentlyContinue | ||
Setup-KeyBasedAuth -Username $adminusername -KeyFilePath $AdminKeyFilePath -UserProfile $AdminUserProfile | ||
|
||
#create batch file | ||
$commands = | ||
"ls | ||
exit" | ||
$batchFilePath = Join-Path $testDir "$tC.$tI.commands.txt" | ||
Set-Content $batchFilePath -Encoding UTF8 -value $commands | ||
|
||
$tI = 1 | ||
} | ||
|
||
BeforeEach { | ||
# disable the OpenSSH log channels | ||
wevtutil sl "OpenSSH/Debug" /e:false /q:true | Out-Null | ||
wevtutil sl "OpenSSH/Operational" /e:false /q:true | Out-Null | ||
# clear any existing logs | ||
wevtutil cl "OpenSSH/Debug" | Out-Null | ||
wevtutil cl "OpenSSH/Operational" | Out-Null | ||
# enable the OpenSSH log channels | ||
wevtutil sl "OpenSSH/Debug" /e:true /q:true | Out-Null | ||
wevtutil sl "OpenSSH/Operational" /e:true /q:true | Out-Null | ||
} | ||
|
||
AfterAll { | ||
Remove-Item -path "$NonadminKeyFilePath*" -Force -ErrorAction SilentlyContinue | ||
Remove-Item -path "$AdminKeyFilePath*" -Force -ErrorAction SilentlyContinue | ||
|
||
$authorized_key = Join-Path '.ssh' authorized_keys | ||
$AdminAuthKeysPath = Join-Path $AdminUserProfile $authorized_key | ||
$NonAdminAuthKeysPath = Join-Path $NonAdminUserProfile $authorized_key | ||
Remove-Item -path "$AdminAuthKeysPath*" -Force -ErrorAction SilentlyContinue | ||
Remove-Item -path "$NonAdminAuthKeysPath*" -Force -ErrorAction SilentlyContinue | ||
|
||
$tC++ | ||
} | ||
|
||
It "$tC.$tI-Nonadmin SFTP Connection" { | ||
sftp -i $NonadminKeyFilePath -b $batchFilePath -o User=$nonadminusername test_target | ||
Start-Sleep $sshdDelay | ||
# query the OpenSSH log channels to make sure events were captured | ||
$eventLogDebug = wevtutil qe "OpenSSH/Debug" /c:5 /f:text | ||
$eventLogDebug | Should Not Be $null | ||
$eventLogOperational = wevtutil qe "OpenSSH/Operational" /c:5 /f:text | ||
$eventLogOperational | Should Not Be $null | ||
} | ||
|
||
It "$tC.$tI-Admin SFTP Connection" { | ||
sftp -i $AdminKeyFilePath -b $batchFilePath -o User=$adminusername test_target | ||
Start-Sleep $sshdDelay | ||
# query the OpenSSH log channels to make sure events were captured | ||
$eventLogDebug = wevtutil qe "OpenSSH/Debug" /c:5 /f:text | ||
$eventLogDebug | Should Not Be $null | ||
$eventLogOperational = wevtutil qe "OpenSSH/Operational" /c:5 /f:text | ||
$eventLogOperational | Should Not Be $null | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.