@@ -134,6 +134,20 @@ Match User matchuser
134
134
}
135
135
}
136
136
}
137
+
138
+ function Set-SSHDConfigLine
139
+ {
140
+ param ([string ]$line , [string ]$file )
141
+ $sshdconfig_ori = Join-Path $Global :OpenSSHTestInfo [" ServiceConfigDir" ] sshd_config
142
+ if (Test-Path $file ) {
143
+ Remove-Item $file - Force
144
+ }
145
+ Copy-Item $sshdconfig_ori $file
146
+ get-acl $sshdconfig_ori | set-acl $file
147
+ $content = Get-Content - Path $file
148
+ $newContent = @ ($line ) + $content
149
+ Set-Content - Path $file - Value $newContent
150
+ }
137
151
138
152
# skip when the task schedular (*-ScheduledTask) cmdlets does not exist
139
153
$ts = (get-command get-ScheduledTask - ErrorAction SilentlyContinue)
@@ -365,4 +379,50 @@ Match User matchuser
365
379
Remove-UserFromLocalGroup - UserName $matchuser - GroupName $allowGroup1
366
380
}
367
381
}
382
+
383
+ Context " Tests of Other SSHD Config Directives via -T" {
384
+ BeforeAll {
385
+ $tI = 1
386
+ $absoluteFilePath = Join-Path $testDir " includeFile"
387
+ $relativeFilePath = " includeFile"
388
+ $progDataPath = Join-Path $env: ProgramData $relativeFilePath
389
+ # adding a line that would not be in a default sshd_config file
390
+ $content = " loglevel DEBUG3"
391
+ $content | Set-Content $absoluteFilePath
392
+ $content | Set-Content $progDataPath
393
+ $sshdconfig_custom = Join-Path $Global :OpenSSHTestInfo [" ServiceConfigDir" ] sshd_config_custom
394
+ $binPath = Join-Path $ ($OpenSSHTestInfo [' OpenSSHBinPath' ]) " sshd.exe"
395
+ }
396
+
397
+ AfterAll {
398
+ $tC ++
399
+ if (Test-Path $absoluteFilePath ) {
400
+ Remove-Item $absoluteFilePath - force
401
+ }
402
+ if (Test-Path $progDataPath ) {
403
+ Remove-Item $progDataPath - force
404
+ }
405
+ if (Test-Path $sshdconfig_custom ) {
406
+ Remove-Item $sshdconfig_custom - force
407
+ }
408
+ }
409
+
410
+ It " $tC .$tI - Include Directive with absolute path starting with forward slash" {
411
+ Set-SSHDConfigLine - line " Include /$absoluteFilePath " - file $sshdconfig_custom
412
+ $result = Invoke-Expression " $binPath -T -f '$sshdconfig_custom '"
413
+ $result.Contains ($content ) | Should Be $true
414
+ }
415
+
416
+ It " $tC .$tI - Include Directive with absolute path starting with drive" {
417
+ Set-SSHDConfigLine - line " Include $absoluteFilePath " - file $sshdconfig_custom
418
+ $result = Invoke-Expression " $binPath -T -f '$sshdconfig_custom '"
419
+ $result.Contains ($content ) | Should Be $true
420
+ }
421
+
422
+ It " $tC .$tI - Include Directive with filename, relative to ProgramData" {
423
+ Set-SSHDConfigLine - line " Include $relativeFilePath " - file $sshdconfig_custom
424
+ $result = Invoke-Expression " $binPath -T -f '$sshdconfig_custom '"
425
+ $result.Contains ($content ) | Should Be $true
426
+ }
427
+ }
368
428
}
0 commit comments