2018-02-13 18:23:53 +01:00
|
|
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
# Licensed under the MIT License.
|
2017-04-22 02:23:08 +02:00
|
|
|
$imageName = "remotetestimage"
|
|
|
|
Describe "Basic remoting test with docker" -tags @("Scenario","Slow"){
|
|
|
|
BeforeAll {
|
|
|
|
$Timeout = 600 # 10 minutes to run these tests
|
|
|
|
$dockerimage = docker images --format "{{ .Repository }}" $imageName
|
|
|
|
if ( $dockerimage -ne $imageName ) {
|
|
|
|
$pending = $true
|
|
|
|
write-warning "Docker image '$imageName' not found, not running tests"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$pending = $false
|
|
|
|
}
|
|
|
|
|
|
|
|
# give the containers something to do, otherwise they will exit and be removed
|
|
|
|
Write-Verbose -verbose "setting up docker container PowerShell server"
|
2019-01-15 08:31:52 +01:00
|
|
|
$server = docker run -d $imageName powershell -c Start-Sleep -Seconds $timeout
|
2017-04-22 02:23:08 +02:00
|
|
|
Write-Verbose -verbose "setting up docker container PowerShell client"
|
2019-01-15 08:31:52 +01:00
|
|
|
$client = docker run -d $imageName powershell -c Start-Sleep -Seconds $timeout
|
2017-04-22 02:23:08 +02:00
|
|
|
|
|
|
|
# get fullpath to installed core powershell
|
2019-05-11 00:34:27 +02:00
|
|
|
Write-Verbose -verbose "Getting path to PowerShell"
|
2017-10-18 02:25:11 +02:00
|
|
|
$powershellcorepath = docker exec $server powershell -c "(get-childitem 'c:\program files\powershell\*\pwsh.exe').fullname"
|
2017-04-22 02:23:08 +02:00
|
|
|
if ( ! $powershellcorepath )
|
|
|
|
{
|
|
|
|
$pending = $true
|
2019-05-11 00:34:27 +02:00
|
|
|
write-warning "Cannot find powershell executable, not running tests"
|
2017-04-22 02:23:08 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
$powershellcoreversion = ($powershellcorepath -split "[\\/]")[-2]
|
|
|
|
# we will need the configuration of the core powershell endpoint
|
|
|
|
$powershellcoreConfiguration = "powershell.${powershellcoreversion}"
|
|
|
|
|
|
|
|
# capture the hostnames of the containers which will be used by the tests
|
|
|
|
write-verbose -verbose "getting server hostname"
|
|
|
|
$serverhostname = docker exec $server hostname
|
|
|
|
write-verbose -verbose "getting client hostname"
|
|
|
|
$clienthostname = docker exec $client hostname
|
|
|
|
|
|
|
|
# capture the versions of full and core PowerShell
|
|
|
|
write-verbose -verbose "getting powershell full version"
|
|
|
|
$fullVersion = docker exec $client powershell -c "`$psversiontable.psversion.tostring()"
|
2017-10-18 02:25:11 +02:00
|
|
|
if ( ! $fullVersion )
|
2017-04-22 02:23:08 +02:00
|
|
|
{
|
|
|
|
$pending = $true
|
|
|
|
write-warning "Cannot determine PowerShell full version, not running tests"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-05-11 00:34:27 +02:00
|
|
|
write-verbose -verbose "getting powershell version"
|
2017-04-22 02:23:08 +02:00
|
|
|
$coreVersion = docker exec $client "$powershellcorepath" -c "`$psversiontable.psversion.tostring()"
|
2017-10-18 02:25:11 +02:00
|
|
|
if ( ! $coreVersion )
|
2017-04-22 02:23:08 +02:00
|
|
|
{
|
|
|
|
$pending = $true
|
2019-05-11 00:34:27 +02:00
|
|
|
write-warning "Cannot determine PowerShell version, not running tests"
|
2017-04-22 02:23:08 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AfterAll {
|
|
|
|
# to debug, comment out the following
|
|
|
|
if ( $pending -eq $false ) {
|
|
|
|
docker rm -f $server
|
|
|
|
docker rm -f $client
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-11 00:34:27 +02:00
|
|
|
It "Full powershell can get correct remote powershell version" -pending:$pending {
|
2017-07-22 06:03:49 +02:00
|
|
|
$result = docker exec $client powershell -c "`$ss = [security.securestring]::new(); '11aa!!AA'.ToCharArray() | ForEach-Object { `$ss.appendchar(`$_)}; `$c = [pscredential]::new('testuser',`$ss); `$ses=new-pssession $serverhostname -configurationname $powershellcoreConfiguration -auth basic -credential `$c; invoke-command -session `$ses { `$psversiontable.psversion.tostring() }"
|
Update pester syntax to v4 (#11544)
* Capitalize 'Should' command and fix whitespace
```powershell
$_ -ireplace '\s?\|\s?should\b',' | Should'
```
* Capitalise and apply hyphen to 'Not' parameter
```powershell
$_ -ireplace '(\| Should) not\b','$1 -Not'
```
* Capitalise and apply hyphen to 'Be' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?) -?be\b','$1 -Be'
```
* Capitalise and apply hyphen to 'BeExactly' parameter
$_ -ireplace '(\| Should(?: -Not)?) -?beexactly\b','$1 -BeExactly'
* Capitalise and apply hyphen to 'BeGreaterThan' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?) -?begreaterthan\b','$1 -BeGreaterThan'
```
* Use 'BeTrue' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?) -Be\s\$?true\b','$1 -BeTrue'
```
* Use 'BeFalse' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?) -Be\s\$?false\b','$1 -BeFalse'
```
* Capitalise and apply hyphen to 'Match' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?)\s-?match\b','$1 -Match'
```
* Capitalise and apply hyphen to 'Throw' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?)\s-?throw\b','$1 -Throw'
```
* Capitalise and apply hyphen to 'BeNullOrEmpty' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?)\s-?benullorempty\b','$1 -BeNullOrEmpty'
```
* Capitalise 'Because' parameter
```powershell
$_ -ireplace '\s-because\b',' -Because'
```
* Fix 'BeNullOrEmpty'
2020-01-11 16:41:59 +01:00
|
|
|
$result | Should -Be $coreVersion
|
2017-04-22 02:23:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Full powershell can get correct remote powershell full version" -pending:$pending {
|
2017-07-22 06:03:49 +02:00
|
|
|
$result = docker exec $client powershell -c "`$ss = [security.securestring]::new(); '11aa!!AA'.ToCharArray() | ForEach-Object { `$ss.appendchar(`$_)}; `$c = [pscredential]::new('testuser',`$ss); `$ses=new-pssession $serverhostname -auth basic -credential `$c; invoke-command -session `$ses { `$psversiontable.psversion.tostring() }"
|
Update pester syntax to v4 (#11544)
* Capitalize 'Should' command and fix whitespace
```powershell
$_ -ireplace '\s?\|\s?should\b',' | Should'
```
* Capitalise and apply hyphen to 'Not' parameter
```powershell
$_ -ireplace '(\| Should) not\b','$1 -Not'
```
* Capitalise and apply hyphen to 'Be' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?) -?be\b','$1 -Be'
```
* Capitalise and apply hyphen to 'BeExactly' parameter
$_ -ireplace '(\| Should(?: -Not)?) -?beexactly\b','$1 -BeExactly'
* Capitalise and apply hyphen to 'BeGreaterThan' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?) -?begreaterthan\b','$1 -BeGreaterThan'
```
* Use 'BeTrue' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?) -Be\s\$?true\b','$1 -BeTrue'
```
* Use 'BeFalse' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?) -Be\s\$?false\b','$1 -BeFalse'
```
* Capitalise and apply hyphen to 'Match' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?)\s-?match\b','$1 -Match'
```
* Capitalise and apply hyphen to 'Throw' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?)\s-?throw\b','$1 -Throw'
```
* Capitalise and apply hyphen to 'BeNullOrEmpty' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?)\s-?benullorempty\b','$1 -BeNullOrEmpty'
```
* Capitalise 'Because' parameter
```powershell
$_ -ireplace '\s-because\b',' -Because'
```
* Fix 'BeNullOrEmpty'
2020-01-11 16:41:59 +01:00
|
|
|
$result | Should -Be $fullVersion
|
2017-04-22 02:23:08 +02:00
|
|
|
}
|
|
|
|
|
2019-05-11 00:34:27 +02:00
|
|
|
It "Core powershell can get correct remote powershell version" -pending:$pending {
|
2017-07-22 06:03:49 +02:00
|
|
|
$result = docker exec $client "$powershellcorepath" -c "`$ss = [security.securestring]::new(); '11aa!!AA'.ToCharArray() | ForEach-Object { `$ss.appendchar(`$_)}; `$c = [pscredential]::new('testuser',`$ss); `$ses=new-pssession $serverhostname -configurationname $powershellcoreConfiguration -auth basic -credential `$c; invoke-command -session `$ses { `$psversiontable.psversion.tostring() }"
|
Update pester syntax to v4 (#11544)
* Capitalize 'Should' command and fix whitespace
```powershell
$_ -ireplace '\s?\|\s?should\b',' | Should'
```
* Capitalise and apply hyphen to 'Not' parameter
```powershell
$_ -ireplace '(\| Should) not\b','$1 -Not'
```
* Capitalise and apply hyphen to 'Be' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?) -?be\b','$1 -Be'
```
* Capitalise and apply hyphen to 'BeExactly' parameter
$_ -ireplace '(\| Should(?: -Not)?) -?beexactly\b','$1 -BeExactly'
* Capitalise and apply hyphen to 'BeGreaterThan' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?) -?begreaterthan\b','$1 -BeGreaterThan'
```
* Use 'BeTrue' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?) -Be\s\$?true\b','$1 -BeTrue'
```
* Use 'BeFalse' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?) -Be\s\$?false\b','$1 -BeFalse'
```
* Capitalise and apply hyphen to 'Match' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?)\s-?match\b','$1 -Match'
```
* Capitalise and apply hyphen to 'Throw' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?)\s-?throw\b','$1 -Throw'
```
* Capitalise and apply hyphen to 'BeNullOrEmpty' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?)\s-?benullorempty\b','$1 -BeNullOrEmpty'
```
* Capitalise 'Because' parameter
```powershell
$_ -ireplace '\s-because\b',' -Because'
```
* Fix 'BeNullOrEmpty'
2020-01-11 16:41:59 +01:00
|
|
|
$result | Should -Be $coreVersion
|
2017-04-22 02:23:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Core powershell can get correct remote powershell full version" -pending:$pending {
|
2017-07-22 06:03:49 +02:00
|
|
|
$result = docker exec $client "$powershellcorepath" -c "`$ss = [security.securestring]::new(); '11aa!!AA'.ToCharArray() | ForEach-Object { `$ss.appendchar(`$_)}; `$c = [pscredential]::new('testuser',`$ss); `$ses=new-pssession $serverhostname -auth basic -credential `$c; invoke-command -session `$ses { `$psversiontable.psversion.tostring() }"
|
Update pester syntax to v4 (#11544)
* Capitalize 'Should' command and fix whitespace
```powershell
$_ -ireplace '\s?\|\s?should\b',' | Should'
```
* Capitalise and apply hyphen to 'Not' parameter
```powershell
$_ -ireplace '(\| Should) not\b','$1 -Not'
```
* Capitalise and apply hyphen to 'Be' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?) -?be\b','$1 -Be'
```
* Capitalise and apply hyphen to 'BeExactly' parameter
$_ -ireplace '(\| Should(?: -Not)?) -?beexactly\b','$1 -BeExactly'
* Capitalise and apply hyphen to 'BeGreaterThan' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?) -?begreaterthan\b','$1 -BeGreaterThan'
```
* Use 'BeTrue' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?) -Be\s\$?true\b','$1 -BeTrue'
```
* Use 'BeFalse' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?) -Be\s\$?false\b','$1 -BeFalse'
```
* Capitalise and apply hyphen to 'Match' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?)\s-?match\b','$1 -Match'
```
* Capitalise and apply hyphen to 'Throw' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?)\s-?throw\b','$1 -Throw'
```
* Capitalise and apply hyphen to 'BeNullOrEmpty' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?)\s-?benullorempty\b','$1 -BeNullOrEmpty'
```
* Capitalise 'Because' parameter
```powershell
$_ -ireplace '\s-because\b',' -Because'
```
* Fix 'BeNullOrEmpty'
2020-01-11 16:41:59 +01:00
|
|
|
$result | Should -Be $fullVersion
|
2017-04-22 02:23:08 +02:00
|
|
|
}
|
|
|
|
}
|