@@ -119,6 +119,8 @@ WARNING: Following changes will be made to OpenSSH configuration
119
119
- will be replaced with a test sshd_config
120
120
- $HOME \.ssh\known_hosts will be backed up as known_hosts.ori
121
121
- will be replaced with a test known_hosts
122
+ - $HOME \.ssh\config will be backed up as config.ori
123
+ - will be replaced with a test config
122
124
- sshd test listener will be on port 47002
123
125
- $HOME \.ssh\known_hosts will be modified with test host key entry
124
126
- test accounts - ssouser, pubkeyuser, and passwduser will be added
@@ -172,17 +174,23 @@ WARNING: Following changes will be made to OpenSSH configuration
172
174
173
175
# Backup existing known_hosts and replace with test version
174
176
# TODO - account for custom known_hosts locations
175
- $knowHostsDirectoryPath = Join-Path $home .ssh
176
- $knowHostsFilePath = Join-Path $knowHostsDirectoryPath known_hosts
177
- if (-not (Test-Path $knowHostsDirectoryPath - PathType Container))
177
+ $dotSshDirectoryPath = Join-Path $home .ssh
178
+ $knowHostsFilePath = Join-Path $dotSshDirectoryPath known_hosts
179
+ if (-not (Test-Path $dotSshDirectoryPath - PathType Container))
178
180
{
179
- New-Item - ItemType Directory - Path $knowHostsDirectoryPath - Force - ErrorAction SilentlyContinue | out-null
181
+ New-Item - ItemType Directory - Path $dotSshDirectoryPath - Force - ErrorAction SilentlyContinue | out-null
180
182
}
181
- if ((Test-Path $knowHostsFilePath - PathType Leaf) -and (-not (Test-Path (Join-Path $knowHostsDirectoryPath known_hosts.ori) - PathType Leaf))) {
182
- Copy-Item $knowHostsFilePath (Join-Path $knowHostsDirectoryPath known_hosts.ori) - Force
183
+ if ((Test-Path $knowHostsFilePath - PathType Leaf) -and (-not (Test-Path (Join-Path $dotSshDirectoryPath known_hosts.ori) - PathType Leaf))) {
184
+ Copy-Item $knowHostsFilePath (Join-Path $dotSshDirectoryPath known_hosts.ori) - Force
183
185
}
184
186
Copy-Item (Join-Path $Script :E2ETestDirectory known_hosts) $knowHostsFilePath - Force
185
187
188
+ $sshConfigFilePath = Join-Path $dotSshDirectoryPath config
189
+ if ((Test-Path $sshConfigFilePath - PathType Leaf) -and (-not (Test-Path (Join-Path $dotSshDirectoryPath config.ori) - PathType Leaf))) {
190
+ Copy-Item $sshConfigFilePath (Join-Path $dotSshDirectoryPath config.ori) - Force
191
+ }
192
+ Copy-Item (Join-Path $Script :E2ETestDirectory ssh_config) $sshConfigFilePath - Force
193
+
186
194
# create test accounts
187
195
# TODO - this is Windows specific. Need to be in PAL
188
196
foreach ($user in $OpenSSHTestAccounts )
@@ -212,6 +220,7 @@ WARNING: Following changes will be made to OpenSSH configuration
212
220
$testPriKeypath = Join-Path $Script :E2ETestDirectory sshtest_userssokey_ed25519
213
221
Cleanup- SecureFileACL - FilePath $testPriKeypath - owner $owner
214
222
cmd / c " ssh-add $testPriKeypath 2>&1 >> $Script :TestSetupLogFile "
223
+ Backup-OpenSSHTestInfo
215
224
}
216
225
# TODO - this is Windows specific. Need to be in PAL
217
226
function Get-LocalUserProfile
@@ -314,6 +323,14 @@ function Cleanup-OpenSSHTestEnvironment
314
323
Remove-Item $originKnowHostsPath - Force - ErrorAction SilentlyContinue
315
324
}
316
325
326
+ # Restore ssh_config
327
+ $originConfigPath = Join-Path $home .ssh\config.ori
328
+ if (Test-Path $originConfigPath )
329
+ {
330
+ Copy-Item $originConfigPath (Join-Path $home .ssh\config) - Force - ErrorAction SilentlyContinue
331
+ Remove-Item $originConfigPath - Force - ErrorAction SilentlyContinue
332
+ }
333
+
317
334
# Delete accounts
318
335
foreach ($user in $OpenSSHTestAccounts )
319
336
{
@@ -395,7 +412,7 @@ function Run-OpenSSHE2ETest
395
412
# Discover all CI tests and run them.
396
413
Push-Location $Script :E2ETestDirectory
397
414
Write-Log - Message " Running OpenSSH E2E tests..."
398
- $testFolders = Get-ChildItem * .tests.ps1 - Recurse - Exclude SSHDConfig.tests.ps1 , SSH.Tests.ps1 | ForEach-Object { Split-Path $_.FullName } | Sort-Object - Unique
415
+ $testFolders = Get-ChildItem * .tests.ps1 - Recurse | ForEach-Object { Split-Path $_.FullName } | Sort-Object - Unique
399
416
Invoke-Pester $testFolders - OutputFormat NUnitXml - OutputFile $Script :E2ETestResultsFile - Tag ' CI'
400
417
Pop-Location
401
418
}
@@ -439,6 +456,56 @@ function Run-OpenSSHUnitTest
439
456
$testfailed
440
457
}
441
458
459
+ function Backup-OpenSSHTestInfo
460
+ {
461
+ param
462
+ (
463
+ [string ] $BackupFile = $null
464
+ )
465
+
466
+ if ($Global :OpenSSHTestInfo -eq $null ) {
467
+ Throw " `$ OpenSSHTestInfo is null. Did you run Setup-OpenSSHTestEnvironment yet?"
468
+ }
469
+
470
+ $testInfo = $Global :OpenSSHTestInfo
471
+
472
+ if ([String ]::IsNullOrEmpty($BackupFile )) {
473
+ $BackupFile = Join-Path $testInfo [" TestDataPath" ] " OpenSSHTestInfo_backup.txt"
474
+ }
475
+
476
+ $null | Set-Content $BackupFile
477
+
478
+ foreach ($key in $testInfo.Keys ) {
479
+ $value = $testInfo [$key ]
480
+ Add-Content $BackupFile " $key ,$value "
481
+ }
482
+ }
483
+
484
+ function Recover-OpenSSHTestInfo
485
+ {
486
+ param
487
+ (
488
+ [Parameter (Mandatory = $true )]
489
+ [ValidateNotNullOrEmpty ()]
490
+ [string ] $BackupFile
491
+ )
492
+
493
+ if ($Global :OpenSSHTestInfo -ne $null )
494
+ {
495
+ $Global :OpenSSHTestInfo.Clear ()
496
+ $Global :OpenSSHTestInfo = $null
497
+ }
498
+
499
+ $Global :OpenSSHTestInfo = @ {}
500
+
501
+ $entries = Get-Content $BackupFile
502
+
503
+ foreach ($entry in $entries ) {
504
+ $data = $entry.Split (" ," )
505
+ $Global :OpenSSHTestInfo [$data [0 ]] = $data [1 ]
506
+ }
507
+ }
508
+
442
509
<#
443
510
Write-Log
444
511
#>
@@ -460,4 +527,4 @@ function Write-Log
460
527
}
461
528
}
462
529
463
- Export-ModuleMember - Function Setup- OpenSSHTestEnvironment, Cleanup- OpenSSHTestEnvironment, Run- OpenSSHUnitTest, Run- OpenSSHE2ETest
530
+ Export-ModuleMember - Function Setup- OpenSSHTestEnvironment, Cleanup- OpenSSHTestEnvironment, Run- OpenSSHUnitTest, Run- OpenSSHE2ETest, Backup-OpenSSHTestInfo , Recover - OpenSSHTestInfo
0 commit comments