mirror of
https://github.com/PowerShell/openssh-portable.git
synced 2025-07-27 15:54:22 +02:00
Password authention tests for SCP and SSH tests (#52)
This commit is contained in:
parent
3508cdc624
commit
50e4499fe0
@ -85,7 +85,7 @@ Class Machine
|
|||||||
[string] $ClientKeyDirectory
|
[string] $ClientKeyDirectory
|
||||||
[string] $knownHostOfCurrentUser
|
[string] $knownHostOfCurrentUser
|
||||||
[string] $OpenSSHdir = $PSScriptRoot
|
[string] $OpenSSHdir = $PSScriptRoot
|
||||||
[string] $ToolsPath = "$env:ProgramData\chocolatey\lib\sysinternals\tools"
|
[string] $ToolsPath = "$env:ProgramData\chocolatey\lib\sysinternals\tools"
|
||||||
|
|
||||||
Machine() {
|
Machine() {
|
||||||
$this.Platform = Set-Platform
|
$this.Platform = Set-Platform
|
||||||
@ -106,13 +106,13 @@ Class Machine
|
|||||||
}
|
}
|
||||||
|
|
||||||
[void] InitializeClient() {
|
[void] InitializeClient() {
|
||||||
$this.ClientKeyDirectory = join-path ($env:USERPROFILE) ".ssh"
|
$this.ClientKeyDirectory = join-path $PSScriptRoot "clientkeys"
|
||||||
if(-not (Test-path $this.ClientKeyDirectory -PathType Container))
|
if(-not (Test-path $this.ClientKeyDirectory -PathType Container))
|
||||||
{
|
{
|
||||||
New-Item -Path $this.ClientKeyDirectory -ItemType Directory -Force -ErrorAction silentlycontinue
|
New-Item -Path $this.ClientKeyDirectory -ItemType Directory -Force -ErrorAction silentlycontinue
|
||||||
}
|
}
|
||||||
|
|
||||||
Remove-Item -Path "$($this.ClientKeyDirectory)\*" -Force -ea silentlycontinue
|
Remove-Item -Path "$($this.ClientKeyDirectory)\*" -Force -ea silentlycontinue
|
||||||
|
|
||||||
$this.knownHostOfCurrentUser = join-path ($env:USERPROFILE) ".ssh/known_hosts"
|
$this.knownHostOfCurrentUser = join-path ($env:USERPROFILE) ".ssh/known_hosts"
|
||||||
|
|
||||||
@ -131,8 +131,7 @@ Class Machine
|
|||||||
$this.clientPrivateKeyPaths += $keyPath
|
$this.clientPrivateKeyPaths += $keyPath
|
||||||
$this.clientPublicKeyPaths += "$keyPath.pub"
|
$this.clientPublicKeyPaths += "$keyPath.pub"
|
||||||
$str = ".\ssh-keygen -t $key -P """" -f $keyPath"
|
$str = ".\ssh-keygen -t $key -P """" -f $keyPath"
|
||||||
$this.RunCmd($str)
|
$this.RunCmd($str)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,16 +210,22 @@ Class Machine
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[void] CleanupServer() {
|
[void] CleanupServer() {
|
||||||
Remove-Item -Path $this.localAdminAuthorizedKeyPath -Force -ea silentlycontinue
|
$sshPath = split-path $this.localAdminAuthorizedKeyPath -Parent
|
||||||
|
if(Test-Path $sshPath -PathType Container )
|
||||||
|
{
|
||||||
|
Remove-item -path $sshPath -force -Recurse
|
||||||
|
}
|
||||||
|
|
||||||
if ( $this.Platform -eq [PlatformType]::Windows )
|
if ( $this.Platform -eq [PlatformType]::Windows )
|
||||||
{
|
{
|
||||||
$this.CleanupLocalAccountTokenFilterPolicy()
|
$this.CleanupLocalAccountTokenFilterPolicy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[void] CleanupClient() {
|
[void] CleanupClient() {
|
||||||
Remove-Item -Path "$this.clientKeyPath\*" -Force -ea silentlycontinue
|
Remove-item -path $($this.ClientKeyDirectory) -force -Recurse -ea silentlycontinue
|
||||||
|
$this.CleanupPasswordSetting()
|
||||||
}
|
}
|
||||||
|
|
||||||
[void] RunCmd($Str) {
|
[void] RunCmd($Str) {
|
||||||
@ -248,6 +253,19 @@ Class Machine
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[void] AddPasswordSetting([string] $pass) {
|
||||||
|
if ($this.Platform -eq [PlatformType]::Windows) {
|
||||||
|
$env:SSH_ASKPASS="$($env:ComSpec) /c echo $pass"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[void] CleanupPasswordSetting() {
|
||||||
|
if ($this.Platform -eq [PlatformType]::Windows -and (Test-Path env:SSH_ASKPASS))
|
||||||
|
{
|
||||||
|
remove-item "env:SSH_ASKPASS" -ErrorAction SilentlyContinue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#Set LocalAccountTokenFilterPolicy
|
#Set LocalAccountTokenFilterPolicy
|
||||||
[void] SetLocalAccountTokenFilterPolicy($setting) {
|
[void] SetLocalAccountTokenFilterPolicy($setting) {
|
||||||
$path = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\system"
|
$path = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\system"
|
||||||
@ -308,6 +326,7 @@ Class Machine
|
|||||||
$shell_app = $null
|
$shell_app = $null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#this does not work when "using module"; works fine when import the module
|
||||||
[void] DownloadPStools()
|
[void] DownloadPStools()
|
||||||
{
|
{
|
||||||
$machinePath = [Environment]::GetEnvironmentVariable('Path', 'MACHINE')
|
$machinePath = [Environment]::GetEnvironmentVariable('Path', 'MACHINE')
|
||||||
|
@ -98,31 +98,30 @@ Describe "Tests for scp command" -Tags "CI" {
|
|||||||
It 'SCP usage' {
|
It 'SCP usage' {
|
||||||
#TODO: usage output does not redirect to file
|
#TODO: usage output does not redirect to file
|
||||||
}
|
}
|
||||||
}#>
|
}#>
|
||||||
|
|
||||||
#this context only run on windows
|
|
||||||
Context "Key is Secured in ssh-agent on server" {
|
Context "Key is Secured in ssh-agent on server" {
|
||||||
BeforeAll {
|
BeforeAll {
|
||||||
$Server.SecureHostKeys($server.PrivateHostKeyPaths)
|
$Server.SecureHostKeys($server.PrivateHostKeyPaths)
|
||||||
$identifyFile = $client.clientPrivateKeyPaths[0]
|
$privateKeyFile = $client.clientPrivateKeyPaths[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
AfterAll {
|
AfterAll {
|
||||||
$Server.CleanupHostKeys()
|
$Server.CleanupHostKeys()
|
||||||
}
|
}
|
||||||
|
|
||||||
It 'File Copy with -i option: <Title> ' -TestCases:$testData {
|
It 'File copy with -i option and private key: <Title> ' -TestCases:$testData {
|
||||||
param([string]$Title, $Source, $Destination)
|
param([string]$Title, $Source, $Destination)
|
||||||
.\scp -i $identifyFile $Source $Destination
|
.\scp -i $privateKeyFile $Source $Destination
|
||||||
#validate file content. DestPath is the path to the file.
|
#validate file content. DestPath is the path to the file.
|
||||||
$equal = @(Compare-Object (Get-ChildItem -path $SourceFilePath) (Get-ChildItem -path $DestinationFilePath) -Property Name, Length).Length -eq 0
|
$equal = @(Compare-Object (Get-ChildItem -path $SourceFilePath) (Get-ChildItem -path $DestinationFilePath) -Property Name, Length).Length -eq 0
|
||||||
$equal | Should Be $true
|
$equal | Should Be $true
|
||||||
}
|
}
|
||||||
|
|
||||||
It 'Directory recursive Copy with -i option: <Title> ' -TestCases:$testData1 {
|
It 'Directory recursive copy with -i option and private key: <Title> ' -TestCases:$testData1 {
|
||||||
param([string]$Title, $Source, $Destination)
|
param([string]$Title, $Source, $Destination)
|
||||||
|
|
||||||
.\scp -r -i $identifyFile $Source $Destination
|
.\scp -r -i $privateKeyFile $Source $Destination
|
||||||
|
|
||||||
$equal = @(Compare-Object (Get-Item -path $SourceDir ) (Get-Item -path (join-path $DestinationDir $SourceDirName) ) -Property Name, Length).Length -eq 0
|
$equal = @(Compare-Object (Get-Item -path $SourceDir ) (Get-Item -path (join-path $DestinationDir $SourceDirName) ) -Property Name, Length).Length -eq 0
|
||||||
$equal | Should Be $true
|
$equal | Should Be $true
|
||||||
@ -130,10 +129,9 @@ Describe "Tests for scp command" -Tags "CI" {
|
|||||||
|
|
||||||
$equal = @(Compare-Object (Get-ChildItem -Recurse -path $SourceDir) (Get-ChildItem -Recurse -path (join-path $DestinationDir $SourceDirName) ) -Property Name, Length).Length -eq 0
|
$equal = @(Compare-Object (Get-ChildItem -Recurse -path $SourceDir) (Get-ChildItem -Recurse -path (join-path $DestinationDir $SourceDirName) ) -Property Name, Length).Length -eq 0
|
||||||
$equal | Should Be $true
|
$equal | Should Be $true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#this context only run on windows
|
|
||||||
Context "Single signon with keys -p -v -c option Secured in ssh-agent" {
|
Context "Single signon with keys -p -v -c option Secured in ssh-agent" {
|
||||||
BeforeAll {
|
BeforeAll {
|
||||||
$Server.SecureHostKeys($server.PrivateHostKeyPaths)
|
$Server.SecureHostKeys($server.PrivateHostKeyPaths)
|
||||||
@ -149,27 +147,27 @@ Describe "Tests for scp command" -Tags "CI" {
|
|||||||
.\ssh-add.exe -D
|
.\ssh-add.exe -D
|
||||||
}
|
}
|
||||||
|
|
||||||
It 'File Copy with -S option (positive)' {
|
It 'File copy with -S option (positive)' {
|
||||||
.\scp -S .\ssh.exe $SourceFilePath "$($server.localAdminUserName)@$($server.MachineName):$DestinationFilePath"
|
.\scp -S .\ssh.exe $SourceFilePath "$($server.localAdminUserName)@$($server.MachineName):$DestinationFilePath"
|
||||||
#validate file content. DestPath is the path to the file.
|
#validate file content. DestPath is the path to the file.
|
||||||
$equal = @(Compare-Object (Get-ChildItem -path $SourceFilePath) (Get-ChildItem -path $DestinationFilePath) -Property Name, Length).Length -eq 0
|
$equal = @(Compare-Object (Get-ChildItem -path $SourceFilePath) (Get-ChildItem -path $DestinationFilePath) -Property Name, Length).Length -eq 0
|
||||||
$equal | Should Be $true
|
$equal | Should Be $true
|
||||||
}
|
}
|
||||||
|
|
||||||
It 'File Copy with -p -c -v option: <Title> ' -TestCases:$testData {
|
It 'File copy with -p -c -v option: <Title> ' -TestCases:$testData {
|
||||||
param([string]$Title, $Source, $Destination)
|
param([string]$Title, $Source, $Destination)
|
||||||
|
|
||||||
.\scp -p -c aes128-ctr -v -C $Source $Destination
|
.\scp -p -c aes128-ctr -v -C $Source $Destination
|
||||||
#validate file content. DestPath is the path to the file.
|
#validate file content. DestPath is the path to the file.
|
||||||
$equal = @(Compare-Object (Get-ChildItem -path $SourceFilePath) (Get-ChildItem -path $DestinationFilePath) -Property Name, Length, LastWriteTime.DateTime).Length -eq 0
|
$equal = @(Compare-Object (Get-ChildItem -path $SourceFilePath) (Get-ChildItem -path $DestinationFilePath) -Property Name, Length, LastWriteTime.DateTime).Length -eq 0
|
||||||
$equal | Should Be $true
|
$equal | Should Be $true
|
||||||
}
|
}
|
||||||
|
|
||||||
It 'Directory recursive Copy with -r -p -v option: <Title> ' -TestCases:$testData1 {
|
It 'Directory recursive copy with -r -p -v option: <Title> ' -TestCases:$testData1 {
|
||||||
param([string]$Title, $Source, $Destination)
|
param([string]$Title, $Source, $Destination)
|
||||||
.\scp -r -p -c aes128-ctr -v $Source $Destination
|
.\scp -r -p -c aes128-ctr -v $Source $Destination
|
||||||
|
|
||||||
$equal = @(Compare-Object (Get-Item -path $SourceDir ) (Get-Item -path (join-path $DestinationDir $SourceDirName) ) -Property Name, Length).Length -eq 0
|
$equal = @(Compare-Object (Get-Item -path $SourceDir ) (Get-Item -path (join-path $DestinationDir $SourceDirName) ) -Property Name, Length, LastWriteTime.DateTime).Length -eq 0
|
||||||
$equal | Should Be $true
|
$equal | Should Be $true
|
||||||
|
|
||||||
$equal = @(Compare-Object (Get-ChildItem -Recurse -path $SourceDir) (Get-ChildItem -Recurse -path (join-path $DestinationDir $SourceDirName) ) -Property Name, Length, LastWriteTime.DateTime).Length -eq 0
|
$equal = @(Compare-Object (Get-ChildItem -Recurse -path $SourceDir) (Get-ChildItem -Recurse -path (join-path $DestinationDir $SourceDirName) ) -Property Name, Length, LastWriteTime.DateTime).Length -eq 0
|
||||||
@ -177,12 +175,12 @@ Describe "Tests for scp command" -Tags "CI" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Context "Key based authentication with -i -C -q options. host keys are not secured on server" {
|
Context "Private key authentication with -i -C -q options. host keys are not secured on server" {
|
||||||
BeforeAll {
|
BeforeAll {
|
||||||
$identifyFile = $client.clientPrivateKeyPaths[0]
|
$identifyFile = $client.clientPrivateKeyPaths[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
It 'File Copy with -i -C -q options: <Title> ' -TestCases:$testData{
|
It 'File copy with -i -C -q options: <Title> ' -TestCases:$testData{
|
||||||
param([string]$Title, $Source, $Destination)
|
param([string]$Title, $Source, $Destination)
|
||||||
|
|
||||||
.\scp -i $identifyFile -C -q $Source $Destination
|
.\scp -i $identifyFile -C -q $Source $Destination
|
||||||
@ -191,16 +189,45 @@ Describe "Tests for scp command" -Tags "CI" {
|
|||||||
$equal | Should Be $true
|
$equal | Should Be $true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
It 'Directory recursive copy with -i -C -r and -q options: <Title> ' -TestCases:$testData1 {
|
||||||
It 'Directory recursive Copy with -i and -q options: <Title> ' -TestCases:$testData1 {
|
|
||||||
param([string]$Title, $Source, $Destination)
|
param([string]$Title, $Source, $Destination)
|
||||||
|
|
||||||
.\scp -i $identifyFile -r -q $Source $Destination
|
.\scp -i $identifyFile -C -r -q $Source $Destination
|
||||||
$equal = @(Compare-Object (Get-Item -path $SourceDir ) (Get-Item -path (join-path $DestinationDir $SourceDirName) ) -Property Name, Length).Length -eq 0
|
$equal = @(Compare-Object (Get-Item -path $SourceDir ) (Get-Item -path (join-path $DestinationDir $SourceDirName) ) -Property Name, Length).Length -eq 0
|
||||||
$equal | Should Be $true
|
$equal | Should Be $true
|
||||||
|
|
||||||
$equal = @(Compare-Object (Get-ChildItem -Recurse -path $SourceDir) (Get-ChildItem -Recurse -path (join-path $DestinationDir $SourceDirName) ) -Property Name, Length).Length -eq 0
|
$equal = @(Compare-Object (Get-ChildItem -Recurse -path $SourceDir) (Get-ChildItem -Recurse -path (join-path $DestinationDir $SourceDirName) ) -Property Name, Length).Length -eq 0
|
||||||
$equal | Should Be $true
|
$equal | Should Be $true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Context "Password authentication" {
|
||||||
|
BeforeAll {
|
||||||
|
$client.AddPasswordSetting($server.localAdminPassword)
|
||||||
|
}
|
||||||
|
|
||||||
|
AfterAll {
|
||||||
|
$client.CleanupPasswordSetting()
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'File copy with -p and -v options: <Title> ' -TestCases:$testData {
|
||||||
|
param([string]$Title, $Source, $Destination)
|
||||||
|
|
||||||
|
.\scp -v -p $Source $Destination
|
||||||
|
#validate file content. DestPath is the path to the file.
|
||||||
|
$equal = @(Compare-Object (Get-ChildItem -path $SourceFilePath) (Get-ChildItem -path $DestinationFilePath) -Property Name, Length, LastWriteTime.DateTime).Length -eq 0
|
||||||
|
$equal | Should Be $true
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'Directory recursive copy with -p and -v options: <Title> ' -TestCases:$testData1 {
|
||||||
|
param([string]$Title, $Source, $Destination)
|
||||||
|
|
||||||
|
.\scp -r -v $Source $Destination
|
||||||
|
$equal = @(Compare-Object (Get-Item -path $SourceDir ) (Get-Item -path (join-path $DestinationDir $SourceDirName) ) -Property Name, Length, LastWriteTime.DateTime).Length -eq 0
|
||||||
|
$equal | Should Be $true
|
||||||
|
|
||||||
|
$equal = @(Compare-Object (Get-ChildItem -Recurse -path $SourceDir) (Get-ChildItem -Recurse -path (join-path $DestinationDir $SourceDirName) ) -Property Name, Length, LastWriteTime.DateTime).Length -eq 0
|
||||||
|
$equal | Should Be $true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,5 +135,28 @@ Describe "Tests for ssh command" -Tags "CI" {
|
|||||||
#validate file content.
|
#validate file content.
|
||||||
Get-Content $filePath | Should be $server.MachineName
|
Get-Content $filePath | Should be $server.MachineName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Context "password authentication" {
|
||||||
|
BeforeAll {
|
||||||
|
$client.AddPasswordSetting($server.localAdminPassword)
|
||||||
|
Remove-Item -Path $filePath -Force -ea silentlycontinue
|
||||||
|
}
|
||||||
|
|
||||||
|
AfterAll {
|
||||||
|
$client.CleanupPasswordSetting()
|
||||||
|
}
|
||||||
|
|
||||||
|
AfterEach {
|
||||||
|
Remove-Item -Path $filePath -Force -ea silentlycontinue
|
||||||
|
}
|
||||||
|
|
||||||
|
It '<Title>' -TestCases:$testData {
|
||||||
|
param([string]$Title, $LogonStr, $Options)
|
||||||
|
|
||||||
|
$str = ".\ssh $($Options) $($LogonStr) hostname > $filePath"
|
||||||
|
$client.RunCmd($str)
|
||||||
|
#validate file content.
|
||||||
|
Get-Content $filePath | Should be $server.MachineName
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user