2017-03-24 20:35:52 +01:00
|
|
|
|
|
2016-12-19 23:48:14 +01:00
|
|
|
|
#covered -i -p -q -r -v -c -S -C
|
|
|
|
|
#todo: -F, -l and -P should be tested over the network
|
|
|
|
|
Describe "Tests for scp command" -Tags "CI" {
|
2017-03-29 21:48:26 +02:00
|
|
|
|
BeforeAll {
|
|
|
|
|
if($OpenSSHTestInfo -eq $null)
|
|
|
|
|
{
|
|
|
|
|
Throw "`$OpenSSHTestInfo is null. Please run Setup-OpenSSHTestEnvironment to setup test environment."
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-19 23:48:14 +01:00
|
|
|
|
$fileName1 = "test.txt"
|
|
|
|
|
$fileName2 = "test2.txt"
|
|
|
|
|
$SourceDirName = "SourceDir"
|
2017-03-29 21:48:26 +02:00
|
|
|
|
$SourceDir = Join-Path "$($OpenSSHTestInfo["TestDataPath"])\SCP" $SourceDirName
|
2016-12-19 23:48:14 +01:00
|
|
|
|
$SourceFilePath = Join-Path $SourceDir $fileName1
|
2017-03-29 21:48:26 +02:00
|
|
|
|
$DestinationDir = Join-Path "$($OpenSSHTestInfo["TestDataPath"])\SCP" "DestDir"
|
2016-12-19 23:48:14 +01:00
|
|
|
|
$DestinationFilePath = Join-Path $DestinationDir $fileName1
|
|
|
|
|
$NestedSourceDir= Join-Path $SourceDir "nested"
|
|
|
|
|
$NestedSourceFilePath = Join-Path $NestedSourceDir $fileName2
|
2017-03-29 21:48:26 +02:00
|
|
|
|
$null = New-Item $SourceDir -ItemType directory -Force -ErrorAction SilentlyContinue
|
|
|
|
|
$null = New-Item $NestedSourceDir -ItemType directory -Force -ErrorAction SilentlyContinue
|
|
|
|
|
$null = New-item -path $SourceFilePath -force -ErrorAction SilentlyContinue
|
|
|
|
|
$null = New-item -path $NestedSourceFilePath -force -ErrorAction SilentlyContinue
|
2016-12-19 23:48:14 +01:00
|
|
|
|
"Test content111" | Set-content -Path $SourceFilePath
|
|
|
|
|
"Test content in nested dir" | Set-content -Path $NestedSourceFilePath
|
2017-03-29 21:48:26 +02:00
|
|
|
|
$null = New-Item $DestinationDir -ItemType directory -Force -ErrorAction SilentlyContinue
|
|
|
|
|
$sshcmd = (get-command ssh).Path
|
|
|
|
|
|
2017-03-24 20:35:52 +01:00
|
|
|
|
$server = $OpenSSHTestInfo["Target"]
|
|
|
|
|
$port = $OpenSSHTestInfo["Port"]
|
|
|
|
|
$ssouser = $OpenSSHTestInfo["SSOUser"]
|
2017-01-27 19:47:20 +01:00
|
|
|
|
$script:logNum = 0
|
2016-12-19 23:48:14 +01:00
|
|
|
|
|
2016-12-22 06:17:14 +01:00
|
|
|
|
$testData = @(
|
2016-12-19 23:48:14 +01:00
|
|
|
|
@{
|
|
|
|
|
Title = 'Simple copy local file to local file'
|
|
|
|
|
Source = $SourceFilePath
|
|
|
|
|
Destination = $DestinationFilePath
|
2017-03-29 21:48:26 +02:00
|
|
|
|
Options = "-P $port "
|
2016-12-22 06:17:14 +01:00
|
|
|
|
},
|
2016-12-19 23:48:14 +01:00
|
|
|
|
@{
|
|
|
|
|
Title = 'Simple copy local file to remote file'
|
|
|
|
|
Source = $SourceFilePath
|
2017-05-12 23:09:50 +02:00
|
|
|
|
Destination = "test_target:$DestinationFilePath"
|
2017-03-29 21:48:26 +02:00
|
|
|
|
Options = "-P $port -S $sshcmd"
|
2016-12-19 23:48:14 +01:00
|
|
|
|
},
|
|
|
|
|
@{
|
|
|
|
|
Title = 'Simple copy remote file to local file'
|
2017-05-12 23:09:50 +02:00
|
|
|
|
Source = "test_target:$SourceFilePath"
|
2017-03-29 21:48:26 +02:00
|
|
|
|
Destination = $DestinationFilePath
|
|
|
|
|
Options = "-P $port -p -c aes128-ctr -C"
|
2016-12-22 06:17:14 +01:00
|
|
|
|
},
|
2016-12-19 23:48:14 +01:00
|
|
|
|
@{
|
|
|
|
|
Title = 'Simple copy local file to local dir'
|
|
|
|
|
Source = $SourceFilePath
|
|
|
|
|
Destination = $DestinationDir
|
2017-03-29 21:48:26 +02:00
|
|
|
|
Options = "-P $port "
|
2016-12-22 06:17:14 +01:00
|
|
|
|
},
|
2016-12-19 23:48:14 +01:00
|
|
|
|
@{
|
|
|
|
|
Title = 'simple copy local file to remote dir'
|
|
|
|
|
Source = $SourceFilePath
|
2017-05-12 23:09:50 +02:00
|
|
|
|
Destination = "test_target:$DestinationDir"
|
2017-03-29 21:48:26 +02:00
|
|
|
|
Options = "-P $port -C -q"
|
file permission on ssh_config, authorized_keys, private keys, host keys, public keys. (#110)
1. Add file permission check when load or add ssh_config, authorized_keys, private keys, host keys,.
2. set the owner and ACE for create secure file, ex, private key in ssh-keygen.exe
3. Update script OpenSSHTestHelper.psm1 to be able to run Install-OpenSSH if the sshd is running on the machine.
4. add OpenSSHBinPath to path.
5. change indents in agentconfig.c
6. update test script to represent the changes
7. Add tests for:
* authorized_keys and ssh-keygen testing
* host keys file perm testing
* user private key file perm testing
* ssh-add test
* user ssh_config
2017-05-01 23:18:20 +02:00
|
|
|
|
}<#,
|
2016-12-19 23:48:14 +01:00
|
|
|
|
@{
|
|
|
|
|
Title = 'simple copy remote file to local dir'
|
2017-05-12 23:09:50 +02:00
|
|
|
|
Source = "test_target:$SourceFilePath"
|
2016-12-19 23:48:14 +01:00
|
|
|
|
Destination = $DestinationDir
|
2017-03-29 21:48:26 +02:00
|
|
|
|
Options = "-P $port "
|
file permission on ssh_config, authorized_keys, private keys, host keys, public keys. (#110)
1. Add file permission check when load or add ssh_config, authorized_keys, private keys, host keys,.
2. set the owner and ACE for create secure file, ex, private key in ssh-keygen.exe
3. Update script OpenSSHTestHelper.psm1 to be able to run Install-OpenSSH if the sshd is running on the machine.
4. add OpenSSHBinPath to path.
5. change indents in agentconfig.c
6. update test script to represent the changes
7. Add tests for:
* authorized_keys and ssh-keygen testing
* host keys file perm testing
* user private key file perm testing
* ssh-add test
* user ssh_config
2017-05-01 23:18:20 +02:00
|
|
|
|
}#>
|
2016-12-19 23:48:14 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
$testData1 = @(
|
|
|
|
|
@{
|
|
|
|
|
Title = 'copy from local dir to remote dir'
|
|
|
|
|
Source = $sourceDir
|
2017-05-12 23:09:50 +02:00
|
|
|
|
Destination = "test_target:$DestinationDir"
|
2017-03-29 21:48:26 +02:00
|
|
|
|
Options = "-P $port -r -p -c aes128-ctr"
|
2016-12-22 06:17:14 +01:00
|
|
|
|
},
|
2017-03-29 21:48:26 +02:00
|
|
|
|
@{
|
2016-12-19 23:48:14 +01:00
|
|
|
|
Title = 'copy from local dir to local dir'
|
|
|
|
|
Source = $sourceDir
|
|
|
|
|
Destination = $DestinationDir
|
2017-03-29 21:48:26 +02:00
|
|
|
|
Options = "-r "
|
|
|
|
|
},
|
2016-12-19 23:48:14 +01:00
|
|
|
|
@{
|
|
|
|
|
Title = 'copy from remote dir to local dir'
|
2017-05-12 23:09:50 +02:00
|
|
|
|
Source = "test_target:$sourceDir"
|
2016-12-19 23:48:14 +01:00
|
|
|
|
Destination = $DestinationDir
|
2017-03-29 21:48:26 +02:00
|
|
|
|
Options = "-P $port -C -r -q"
|
2016-12-19 23:48:14 +01:00
|
|
|
|
}
|
|
|
|
|
)
|
2017-01-27 19:47:20 +01:00
|
|
|
|
|
2017-03-31 20:47:24 +02:00
|
|
|
|
# for the first time, delete the existing log files.
|
2017-03-29 21:48:26 +02:00
|
|
|
|
if ($OpenSSHTestInfo['DebugMode'])
|
|
|
|
|
{
|
2017-03-31 20:47:24 +02:00
|
|
|
|
Clear-Content "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\ssh-agent.log" -Force -ErrorAction ignore
|
|
|
|
|
Clear-Content "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\sshd.log" -Force -ErrorAction ignore
|
2017-03-29 21:48:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-27 19:47:20 +01:00
|
|
|
|
function CheckTarget {
|
|
|
|
|
param([string]$target)
|
|
|
|
|
if(-not (Test-path $target))
|
2017-03-29 21:48:26 +02:00
|
|
|
|
{
|
|
|
|
|
if( $OpenSSHTestInfo["DebugMode"])
|
|
|
|
|
{
|
2017-03-31 20:47:24 +02:00
|
|
|
|
Copy-Item "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\ssh-agent.log" "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\failedagent$script:logNum.log" -Force
|
|
|
|
|
Copy-Item "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\sshd.log" "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\failedsshd$script:logNum.log" -Force
|
|
|
|
|
|
2017-03-29 21:48:26 +02:00
|
|
|
|
$script:logNum++
|
2017-03-31 20:47:24 +02:00
|
|
|
|
|
|
|
|
|
# clear the ssh-agent, sshd logs so that next testcase will get fresh logs.
|
|
|
|
|
Clear-Content "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\ssh-agent.log" -Force -ErrorAction ignore
|
|
|
|
|
Clear-Content "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\sshd.log" -Force -ErrorAction ignore
|
2017-03-29 21:48:26 +02:00
|
|
|
|
}
|
2017-01-27 19:47:20 +01:00
|
|
|
|
|
|
|
|
|
return $false
|
|
|
|
|
}
|
|
|
|
|
return $true
|
|
|
|
|
}
|
2016-12-19 23:48:14 +01:00
|
|
|
|
}
|
|
|
|
|
AfterAll {
|
|
|
|
|
|
2017-03-29 21:48:26 +02:00
|
|
|
|
if($OpenSSHTestInfo -eq $null)
|
|
|
|
|
{
|
|
|
|
|
#do nothing
|
|
|
|
|
}
|
|
|
|
|
elseif( -not $OpenSSHTestInfo['DebugMode'])
|
|
|
|
|
{
|
|
|
|
|
if(-not [string]::IsNullOrEmpty($SourceDir))
|
|
|
|
|
{
|
|
|
|
|
Get-Item $SourceDir | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
|
|
|
|
|
}
|
|
|
|
|
if(-not [string]::IsNullOrEmpty($DestinationDir))
|
|
|
|
|
{
|
|
|
|
|
Get-Item $DestinationDir | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-19 23:48:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-23 00:21:42 +01:00
|
|
|
|
BeforeAll {
|
2017-01-27 19:47:20 +01:00
|
|
|
|
$null = New-Item $DestinationDir -ItemType directory -Force -ErrorAction SilentlyContinue
|
2016-12-19 23:48:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AfterEach {
|
2016-12-23 00:21:42 +01:00
|
|
|
|
Get-ChildItem $DestinationDir -Recurse | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
|
2017-03-29 21:48:26 +02:00
|
|
|
|
}
|
2017-01-12 06:54:44 +01:00
|
|
|
|
|
2016-12-19 23:48:14 +01:00
|
|
|
|
|
2017-03-29 21:48:26 +02:00
|
|
|
|
It 'File copy: <Title> ' -TestCases:$testData {
|
|
|
|
|
param([string]$Title, $Source, $Destination, $Options)
|
2016-12-22 06:17:14 +01:00
|
|
|
|
|
2017-03-29 21:48:26 +02:00
|
|
|
|
iex "scp $Options $Source $Destination"
|
|
|
|
|
$LASTEXITCODE | Should Be 0
|
|
|
|
|
#validate file content. DestPath is the path to the file.
|
|
|
|
|
CheckTarget -target $DestinationFilePath | Should Be $true
|
2016-12-19 23:48:14 +01:00
|
|
|
|
|
2017-03-29 21:48:26 +02:00
|
|
|
|
$equal = @(Compare-Object (Get-ChildItem -path $SourceFilePath) (Get-ChildItem -path $DestinationFilePath) -Property Name, Length ).Length -eq 0
|
|
|
|
|
$equal | Should Be $true
|
2016-12-19 23:48:14 +01:00
|
|
|
|
|
2017-03-29 21:48:26 +02:00
|
|
|
|
if($Options.contains("-p"))
|
|
|
|
|
{
|
|
|
|
|
$equal = @(Compare-Object (Get-ChildItem -path $SourceFilePath).LastWriteTime.DateTime (Get-ChildItem -path $DestinationFilePath).LastWriteTime.DateTime ).Length -eq 0
|
2016-12-19 23:48:14 +01:00
|
|
|
|
$equal | Should Be $true
|
|
|
|
|
}
|
2017-03-29 21:48:26 +02:00
|
|
|
|
}
|
2016-12-22 06:17:14 +01:00
|
|
|
|
|
2017-03-29 21:48:26 +02:00
|
|
|
|
It 'Directory recursive copy: <Title> ' -TestCases:$testData1 {
|
|
|
|
|
param([string]$Title, $Source, $Destination, $Options)
|
2016-12-19 23:48:14 +01:00
|
|
|
|
|
2017-03-29 21:48:26 +02:00
|
|
|
|
iex "scp $Options $Source $Destination"
|
|
|
|
|
$LASTEXITCODE | Should Be 0
|
|
|
|
|
CheckTarget -target (join-path $DestinationDir $SourceDirName) | Should Be $true
|
2017-01-12 06:54:44 +01:00
|
|
|
|
|
2017-03-29 21:48:26 +02:00
|
|
|
|
$equal = @(Compare-Object (Get-Item -path $SourceDir ) (Get-Item -path (join-path $DestinationDir $SourceDirName) ) -Property Name, Length).Length -eq 0
|
|
|
|
|
$equal | Should Be $true
|
2017-01-12 06:54:44 +01:00
|
|
|
|
|
2017-03-29 21:48:26 +02:00
|
|
|
|
if($Options.contains("-p"))
|
|
|
|
|
{
|
|
|
|
|
$equal = @(Compare-Object (Get-Item -path $SourceDir).LastWriteTime.DateTime (Get-Item -path (join-path $DestinationDir $SourceDirName)).LastWriteTime.DateTime).Length -eq 0
|
2017-01-12 06:54:44 +01:00
|
|
|
|
$equal | Should Be $true
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-29 21:48:26 +02:00
|
|
|
|
$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
|
2017-01-12 06:54:44 +01:00
|
|
|
|
|
2017-03-29 21:48:26 +02:00
|
|
|
|
if($Options.contains("-p"))
|
|
|
|
|
{
|
|
|
|
|
$equal = @(Compare-Object (Get-ChildItem -Recurse -path $SourceDir).LastWriteTime.DateTime (Get-ChildItem -Recurse -path (join-path $DestinationDir $SourceDirName) ).LastWriteTime.DateTime).Length -eq 0
|
2017-01-12 06:54:44 +01:00
|
|
|
|
$equal | Should Be $true
|
|
|
|
|
}
|
2017-03-29 21:48:26 +02:00
|
|
|
|
}
|
2016-12-19 23:48:14 +01:00
|
|
|
|
}
|