From 13eae6e28d667cd6fc349f5ce8774c045eb2bc73 Mon Sep 17 00:00:00 2001 From: Vivian Thiebaut Date: Fri, 10 Feb 2023 15:13:16 -0500 Subject: [PATCH 1/3] Add test for UnusedConnectionTimeout --- regress/pesterTests/SSHDConfig.tests.ps1 | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/regress/pesterTests/SSHDConfig.tests.ps1 b/regress/pesterTests/SSHDConfig.tests.ps1 index 47a8259595f..36cb3a6ccb9 100644 --- a/regress/pesterTests/SSHDConfig.tests.ps1 +++ b/regress/pesterTests/SSHDConfig.tests.ps1 @@ -41,6 +41,7 @@ Describe "Tests of sshd_config" -Tags "CI" { Add-Content $sshdconfig_custom @" +UnusedConnectionTimeout 2 DenyUsers denyuser1 deny*2 denyuse?3, AllowUsers allowuser1 allowu*r2 allow?se?3 allowuser4 localuser1 localu*r2 loc?lu?er3 localadmin matchuser DenyGroups denygroup1 denygr*p2 deny?rou?3 @@ -211,6 +212,27 @@ Match User matchuser $tC++ } + It "$tC.$tI-Test UnusedConnectionTimeout" -skip:$skip { + #Run + Start-SSHDTestDaemon -WorkDir $opensshbinpath -Arguments "-d -f $sshdConfigPath -E $sshdlog" -Port $port + Add-UserToLocalGroup -UserName $localuser1 -Password $password -GroupName $allowGroup1 + + # Start SSH process with Remote Forwarding Option to create a connection that doesn't prevent "Unused Connection Timeout" + $p = Start-Process -FilePath ssh -ArgumentList "-p $port -N -T -R 8080 $localuser1@$server" -PassThru + Wait-Process $p.Id -Timeout 5 -ErrorAction SilentlyContinue -ErrorVariable timeouted + if (-not $p.HasExited) + { + Stop-Process $p.Id + } + + $timeouted | Should Be $null + $p.ExitCode | Should Be 255 + + Stop-SSHDTestDaemon -Port $port + sleep $sshdDelay + Remove-UserFromLocalGroup -UserName $localuser1 -GroupName $allowGroup1 + } + It "$tC.$tI-User with full name in the list of AllowUsers" -skip:$skip { #Run Start-SSHDTestDaemon -WorkDir $opensshbinpath -Arguments "-d -f $sshdConfigPath -E $sshdlog" -Port $port From 5435f75509afa919c42d3ae00cce7cac3ca5e0c3 Mon Sep 17 00:00:00 2001 From: Vivian Thiebaut Date: Fri, 10 Feb 2023 15:20:47 -0500 Subject: [PATCH 2/3] Add -Force to Stop-Process --- regress/pesterTests/SSHDConfig.tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/regress/pesterTests/SSHDConfig.tests.ps1 b/regress/pesterTests/SSHDConfig.tests.ps1 index 36cb3a6ccb9..f096fd148b6 100644 --- a/regress/pesterTests/SSHDConfig.tests.ps1 +++ b/regress/pesterTests/SSHDConfig.tests.ps1 @@ -222,7 +222,7 @@ Match User matchuser Wait-Process $p.Id -Timeout 5 -ErrorAction SilentlyContinue -ErrorVariable timeouted if (-not $p.HasExited) { - Stop-Process $p.Id + Stop-Process $p.Id -Force } $timeouted | Should Be $null From b3030036b598a21f541bdeb6d0bd213ea8842323 Mon Sep 17 00:00:00 2001 From: Vivian Thiebaut Date: Fri, 10 Feb 2023 16:12:59 -0500 Subject: [PATCH 3/3] Listen to port 35000 instead of 8080 --- regress/pesterTests/SSHDConfig.tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/regress/pesterTests/SSHDConfig.tests.ps1 b/regress/pesterTests/SSHDConfig.tests.ps1 index f096fd148b6..6a2dfbb31b6 100644 --- a/regress/pesterTests/SSHDConfig.tests.ps1 +++ b/regress/pesterTests/SSHDConfig.tests.ps1 @@ -218,8 +218,8 @@ Match User matchuser Add-UserToLocalGroup -UserName $localuser1 -Password $password -GroupName $allowGroup1 # Start SSH process with Remote Forwarding Option to create a connection that doesn't prevent "Unused Connection Timeout" - $p = Start-Process -FilePath ssh -ArgumentList "-p $port -N -T -R 8080 $localuser1@$server" -PassThru - Wait-Process $p.Id -Timeout 5 -ErrorAction SilentlyContinue -ErrorVariable timeouted + $p = Start-Process -FilePath ssh -ArgumentList "-p $port -N -T -R 35000 $localuser1@$server" -PassThru + Wait-Process $p.Id -Timeout 10 -ErrorAction SilentlyContinue -ErrorVariable timeouted if (-not $p.HasExited) { Stop-Process $p.Id -Force