Skip to content

Commit

Permalink
#115 Cleaned up NewIshSession.Tests.ps1, make sure to set ISHRemote.P…
Browse files Browse the repository at this point in the history
…esterSetup.ps1 import-module to release as debug is not build as package yet. Updated the storyline of all nice improvements Ivo did.
  • Loading branch information
ddemeyer committed Aug 17, 2021
1 parent e22feec commit 7735e09
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 112 deletions.
28 changes: 17 additions & 11 deletions Doc/TheExecution-ISHRemote-7.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,37 @@ A table that describes what works, where cmdlets have been rewired, where tests
<Copy SourceFiles="$(TargetPath)-Help.xml" DestinationFolder="$(TargetDir.Replace(`netstandard2.0`,`net5.0`))\" />
</Target>
1. Error `System.Runtime.Loader.AssemblyLoadContext.OnAssemblyResolve(RuntimeAssembly assembly, String assemblyFullName)
New-IshSession: Could not load file or assembly 'System.ServiceModel.Primitives` brought me here [Resolving PowerShell Module Assembly Dependency Conflicts](https://devblogs.microsoft.com/powershell/resolving-powershell-module-assembly-dependency-conflicts/). By running `[System.AppDomain]::CurrentDomain.GetAssemblies() | Out-GridView` you can see that my wanted (latest) version 4.8.1 is not competing with the out-of-the-box version of PowerShell/dotnet.
New-IshSession: Could not load file or assembly 'System.ServiceModel.Primitives' brought me here [Resolving PowerShell Module Assembly Dependency Conflicts](https://devblogs.microsoft.com/powershell/resolving-powershell-module-assembly-dependency-conflicts/). By running `[System.AppDomain]::CurrentDomain.GetAssemblies() | Out-GridView` you can see that my wanted (latest) version 4.8.1 is not competing with the out-of-the-box version of PowerShell/dotnet.
Publishing problem perhaps, as copying %USER%\.nuget\packages\system.servicemodel.http\4.8.1\lib\netcore50\System.ServiceModel.Http.dll to \Source\ISHRemote\Trisoft.ISHRemote\bin\Debug\net5.0 and same for System.ServiceModel.Primitives.dll made it work under PowerShell 7. So next up is MSBuild/Publish routines/knowledge, inspired by Azure module. Could be caused by `<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>`
1. Kudos to @ivandelagemaat for getting the build sytem running, one module for Windows PowerShell and PowerShell Core. Below some quick notes on the most important victories. Even integrated the NuGet package of `XmlDoc2CmdletDoc`
1. He added a `.github/workflows/continuous-integration.yml` file that autobuilds this branch. And `\Source\ISHRemote\Directory.Build.props`
1. Rolled back to older 'System.ServiceModel.Primitives' versions. The ones that came with PowerShell SDK, this avoids the Azure assembly loader variations and more.
1. Earlier code used proxy `Application25Soap12` which is lowered to `Application25Soap` (probably 1.1) which in essence is ASMX anyway.
1. Consider build.props, and script
1. Inspired from `\Properties\AssemblyInfo.cs`, `\Properties\AssemblyInfo.targets` and `\Properties\ModuleManifest.targets`
1. `Trisoft.ISHRemote\ISHRemote.PostBuild.ps1`
1. It looks like `PSSnapIn` was wiring up the format xml. The class was removed, who now suggests to pick up the rendering format xml.
1. `ISHRemote.psm1` in a multi-target framework setup can detect in PowerShell if it is `Core` or `Desktop` and in turn if it is Framework, Core 3, Core 5 (or higher) by `[Environment]::Version` (which returns 5.0.3.-1)... based on `$PSVersionTable`
1. Cleaned up `NewIshSession.Tests.ps1` noticing the HTTPS/SSL (even TLS1.3) is missing, Timeout parameters are uncertain, PSCredential is a gap... but test has been cleaned up given 48 successes
## Next
1. `ISHRemote.psm1` in a multi-target framework setup can detect in PowerShell if it is `Core` or `Desktop` and in turn if it is Framework, Core 3, Core 5 (or higher) by `[Environment]::Version` (which returns 5.0.3.-1)
1. Remove `System.Reflection...` again if I go multi-target.
1. Build `Debug` in the same way as `Release` with copied `Scripts` folder (also the only folder for PSScriptAnalyzer to enforce) so that `ISHRemote.PesterSetup.ps1` can keep pointing to the `Debug` packaged ISHRemote.
1. `$IshSession.Protocol` with enum values `Asmx-AuthenticationContext` and `OpenAPI-BasicAuthentication`... defaults currently to Asmx, could later be detected based on the url or `clientconfiguration.xml`
1. Is `CertificateValidationHelper.cs` and `ServicePointManagerHelper.cs` still the way to do certificate bypass? Make sure TLS 1.3 is activated (possible since net4.8 and higher)
1. `TrisoftCmdlet.cs` says `[assembly: ComVisible(false)]` ... brrr? Why?
1. Parameter `-PSCredential` doesn't work because of `SecureString` being Windows cryptography only according to https://github.com/PowerShell/PowerShell/issues/1654 ... what is next? Needs alignment with https://devblogs.microsoft.com/powershell/secretmanagement-and-secretstore-release-candidate-2/
1. Also a `New-IshSession` scheduled task code sample like in the past using Windows-only `ConvertTo-SecureString` is required, perhaps over Secret Management.
1. Upon WCF Proxy retrieval from IshSession object, there used to be a `VerifyTokenValidity` that would check the authentication, and potentially re-authenticate all proxies. For `AuthenticationContext` we only now it is valid for 7 days, so ISHRemote could track that or the script using ISHRemote should handle that for now. Actually if you pass `AuthenticationContext` by ref on every call it gets refreshed anyway, so only a problem if IshSession is not used for 7+ days.
1. Consider build.props, and script
1. Inspired from `\Properties\AssemblyInfo.cs`, `\Properties\AssemblyInfo.targets` and `\Properties\ModuleManifest.targets`
1. `Trisoft.ISHRemote\ISHRemote.PostBuild.ps1`
1. It looks like `PSSnapIn` was wiring up the format xml. The class was removed, who now suggests to pick up the rendering format xml.
1. Is `CertificateValidationHelper.cs` and `ServicePointManagerHelper.cs` still the way to do certificate bypass?
1. `TrisoftCmdlet.cs` says `[assembly: ComVisible(false)]` ... brrr? Why?
# Backlog
The below is a list to consider, before execution is preferably transformed into github issues
1. Local `.snk` signing file, get inspired by Azure modules
1. Enable Tls13, this force NET Framework 4.8 ... is that part of netstandard2.0? Should we consider two build targets and have the `ISHRemote.psm1` decide at runtime which set to load?
1. Auto complete on parameters
1. `Get-Help` can still be based on tripple-slash (`///`) using `\ISHRemote\Source\Tools\XmlDoc2CmdletDoc`. Some source indicate separate markdown files, next to the C# source and Pester test files.
1. `Get-Help` can still be based on tripple-slash (`///`) using `\ISHRemote\Source\Tools\XmlDoc2CmdletDoc`. Some source indicate separate markdown files, next to the C# source and Pester test files. There is a NuGet package, native .NET (Core) integrated.
# References
* HTTPS and SoapClient11 or SoapClient12 is discussed on https://medium.com/grensesnittet/integrating-with-soap-web-services-in-net-core-adebfad173fb
* Error `System.Runtime.Loader.AssemblyLoadContext.OnAssemblyResolve(RuntimeAssembly assembly, String assemblyFullName)
New-IshSession: Could not load file or assembly 'System.ServiceModel.Primitives` brought me here [Resolving PowerShell Module Assembly Dependency Conflicts](https://devblogs.microsoft.com/powershell/resolving-powershell-module-assembly-dependency-conflicts/). By running `[System.AppDomain]::CurrentDomain.GetAssemblies() | Out-GridView` you can see which assemblies are loaded in your fresh PowerShell session.
New-IshSession: Could not load file or assembly 'System.ServiceModel.Primitives' brought me here [Resolving PowerShell Module Assembly Dependency Conflicts](https://devblogs.microsoft.com/powershell/resolving-powershell-module-assembly-dependency-conflicts/). By running `[System.AppDomain]::CurrentDomain.GetAssemblies() | Out-GridView` you can see which assemblies are loaded in your fresh PowerShell session. Rolled back to older 'System.ServiceModel.Primitives' versions. The ones that came with PowerShell SDK, this avoids the Azure assembly loader variations and more.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Describe "New-IshSession" -Tags "Read" {
}
}

Context New-IshSession UserNamePassword" {
Context "New-IshSession UserNamePassword" {
It "Parameter WsBaseUrl invalid" {
{ New-IshSession -WsBaseUrl "http:///INVALIDWSBASEURL" -IshUserName "INVALIDISHUSERNAME" -IshPassword "INVALIDISHPASSWORD" } | Should Throw "Invalid URI"
}
Expand All @@ -28,35 +28,6 @@ Describe "New-IshSession" -Tags "Read" {
It "Parameter IshPassword specified" {
{ New-IshSession -WsBaseUrl $webServicesBaseUrl -IshUserName $ishUserName -IshPassword "INVALIDISHPASSWORD" } | Should Throw
}
It "Parameter IshUserName empty falls back to NetworkCredential/ActiveDirectory" {
{ New-IshSession -WsBaseUrl $webServicesBaseUrl -IshUserName "" -IshPassword "IGNOREISHPASSWORD" } | Should Not Throw "Cannot validate argument on parameter 'IshUserName'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again."
}
}

Context New-IshSession ActiveDirectory" {
It "Parameter WsBaseUrl invalid" {
{ New-IshSession -WsBaseUrl "http:///INVALIDWSBASEURL" } | Should Throw "Invalid URI"
}
}

Context New-IshSession PSCredential" {
It "Parameter WsBaseUrl invalid" {
{
$securePassword = ConvertTo-SecureString $ishPassword -AsPlainText -Force
$mycredentials = New-Object System.Management.Automation.PSCredential ($ishUserName, $securePassword)
New-IshSession -WsBaseUrl "http:///INVALIDWSBASEURL" -PSCredential $mycredentials
} | Should Throw "Invalid URI"
}
It "Parameter PSCredential invalid" {
$securePassword = ConvertTo-SecureString "INVALIDPASSWORD" -AsPlainText -Force
$mycredentials = New-Object System.Management.Automation.PSCredential ("INVALIDISHUSERNAME", $securePassword)
{ New-IshSession -WsBaseUrl $webServicesBaseUrl -PSCredential $mycredentials } | Should Throw
}
It "Parameter PSCredential" {
$securePassword = ConvertTo-SecureString $ishPassword -AsPlainText -Force
$mycredentials = New-Object System.Management.Automation.PSCredential ($ishUserName, $securePassword)
{ New-IshSession -WsBaseUrl $webServicesBaseUrl -PSCredential $mycredentials } | Should Not Throw
}
}

Context "New-IshSession returns IshSession object" {
Expand Down Expand Up @@ -119,12 +90,6 @@ Describe "New-IshSession" -Tags "Read" {
It "IshSession.Timeout defaults to 20s" {
$ishSession.Timeout.TotalMilliseconds -eq 20000 | Should Be $true
}
It "IshSession.TimeoutIssue" {
$ishSession.TimeoutIssue.TotalMilliseconds -gt 0 | Should Be $true
}
It "IshSession.TimeoutService" {
$ishSession.TimeoutService.TotalMilliseconds -gt 0 | Should Be $true
}
It "IshSession.StrictMetadataPreference" {
$ishSession.StrictMetadataPreference | Should Be "Continue"
}
Expand Down Expand Up @@ -164,38 +129,6 @@ Describe "New-IshSession" -Tags "Read" {
}
}

Context "New-IshSession TimeoutIssue" {
It "Parameter TimeoutIssue Invalid" {
{ $ishSession = New-IshSession -WsBaseUrl $webServicesBaseUrl -IshUserName $ishUserName -IshPassword $ishPassword -TimeoutIssue "INVALIDTimeoutIssue" } | Should Throw
}
It "IshSession.TimeoutIssue set to 30s" {
$ishSession = New-IshSession -WsBaseUrl $webServicesBaseUrl -IshUserName $ishUserName -IshPassword $ishPassword -TimeoutIssue (New-TimeSpan -Seconds 30)
$ishSession.TimeoutIssue.TotalMilliseconds | Should Be "30000"
}
It "IshSession.TimeoutIssue set to 1ms execution" {
# The request channel timed out while waiting for a reply after 00:00:00.0000017. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout.
{ New-IshSession -WsBaseUrl $webServicesBaseUrl -IshUserName $ishUserName -IshPassword $ishPassword -TimeoutIssue (New-Object TimeSpan(0,0,0,0,1)) } | Should Throw
}
}

Context "New-IshSession TimeoutService" {
It "Parameter TimeoutService Invalid" {
{ $ishSession = New-IshSession -WsBaseUrl $webServicesBaseUrl -IshUserName $ishUserName -IshPassword $ishPassword -TimeoutService "INVALIDTIMEOUTSERVICE" } | Should Throw
}
It "IshSession.TimeoutService set to 40s" {
$ishSession = New-IshSession -WsBaseUrl $webServicesBaseUrl -IshUserName $ishUserName -IshPassword $ishPassword -TimeoutService (New-TimeSpan -Seconds 40)
$ishSession.TimeoutService.TotalMilliseconds | Should Be "40000"
}
<# It "IshSession.TimeoutService set to 1 tickout execution" {
# The request channel timed out attempting to send after 00:00:00.0010000. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout.
{
$ishSession = New-IshSession -WsBaseUrl $webServicesBaseUrl -IshUserName $ishUserName -IshPassword $ishPassword -TimeoutService (New-Object TimeSpan(1))
# Forcing a GetVersion web service call, probably needs a better call because GetVersion can be too fast, so nothing is thrown
$version = $ishSession.ServerVersion
} | Should Throw
} #>
}

Context "New-IshSession IgnoreSslPolicyErrors" {
It "Parameter IgnoreSslPolicyErrors specified positive flow" {
$ishSession = New-IshSession -WsBaseUrl $webServicesBaseUrl -IshUserName $ishUserName -IshPassword $ishPassword -IgnoreSslPolicyErrors
Expand Down Expand Up @@ -229,81 +162,66 @@ Describe "New-IshSession" -Tags "Read" {
$ishSession.Dispose()
} #>
}
Context "New-IshSession ExplicitIssuer" {
It "Parameter WsTrustIssuerUrl and WsTrustIssuerMexUrl are using full hostname" {
$ishSession = New-IshSession -WsBaseUrl $webServicesBaseUrl -WsTrustIssuerUrl $wsTrustIssuerUrl -WsTrustIssuerMexUrl $wsTrustIssuerMexUrl -IshUserName $ishUserName -IshPassword $ishPassword
$ishSession.ServerVersion | Should Not BeNullOrEmpty
$ishSession.ServerVersion.Split(".").Length | Should Be 4
}
It "Parameter WsTrustIssuerUrl and WsTrustIssuerMexUrl are using localhost" -skip {
$ishSession = New-IshSession -WsBaseUrl $localWebServicesBaseUrl -WsTrustIssuerUrl $localWsTrustIssuerUrl -WsTrustIssuerMexUrl $localWsTrustIssuerMexUrl -IshUserName $ishUserName -IshPassword $ishPassword -IgnoreSslPolicyErrors
$ishSession.ServerVersion | Should Not BeNullOrEmpty
$ishSession.ServerVersion.Split(".").Length | Should Be 4
}
}

Context "New-IshSession returns IshSession ServiceReferences" {
$ishSession = New-IshSession -WsBaseUrl $webServicesBaseUrl -IshUserName $ishUserName -IshPassword $ishPassword
It "IshSession.Annotation25" {
if (([Version]$ishSession.ServerVersion).Major -ge 14) { # new service since 14/14.0.0
$ishSession.Annotation25 -ne $null | Should Not BeNullOrEmpty
-not (Get-Member -inputobject $ishSession -Membertype Properties -Name Annotation25) | Should Be $true
}
}
It "IshSession.Application25" {
$ishSession.Application25 -ne $null | Should Not BeNullOrEmpty
-not (Get-Member -inputobject $ishSession -Membertype Properties -Name Application25) | Should Be $true
}
It "IshSession.BackgroundTask25" { # new service since 13SP2/13.0.2
if (([Version]$ishSession.ServerVersion).Major -ge 14 -or (([Version]$ishSession.ServerVersion).Major -ge 13 -and ([Version]$ishSession.ServerVersion).Revision -ge 2)) {
$ishSession.BackgroundTask25 -ne $null | Should Not BeNullOrEmpty
-not (Get-Member -inputobject $ishSession -Membertype Properties -Name BackgroundTask25) | Should Be $true
}
}
It "IshSession.Baseline25" {
$ishSession.Baseline25 -ne $null | Should Not BeNullOrEmpty
-not (Get-Member -inputobject $ishSession -Membertype Properties -Name Baseline25) | Should Be $true
}
It "IshSession.DocumentObj25" {
$ishSession.DocumentObj25 -ne $null | Should Not BeNullOrEmpty
-not (Get-Member -inputobject $ishSession -Membertype Properties -Name DocumentObj25) | Should Be $true
}
It "IshSession.EDT25" {
$ishSession.EDT25 -ne $null | Should Not BeNullOrEmpty
-not (Get-Member -inputobject $ishSession -Membertype Properties -Name EDT25) | Should Be $true
}
It "IshSession.EventMonitor25" {
$ishSession.EventMonitor25 -ne $null | Should Not BeNullOrEmpty
-not (Get-Member -inputobject $ishSession -Membertype Properties -Name EventMonitor25) | Should Be $true
}
It "IshSession.Folder25" {
$ishSession.Folder25 -ne $null | Should Not BeNullOrEmpty
-not (Get-Member -inputobject $ishSession -Membertype Properties -Name Folder25) | Should Be $true
}
It "IshSession.ListOfValues25" {
$ishSession.ListOfValues25 -ne $null | Should Not BeNullOrEmpty
-not (Get-Member -inputobject $ishSession -Membertype Properties -Name ListOfValues25) | Should Be $true
}
It "IshSession.MetadataBinding25" {
$ishSession.MetadataBinding25 -ne $null | Should Not BeNullOrEmpty
-not (Get-Member -inputobject $ishSession -Membertype Properties -Name MetadataBinding25) | Should Be $true
}
It "IshSession.OutputFormat25" {
$ishSession.OutputFormat25 -ne $null | Should Not BeNullOrEmpty
-not (Get-Member -inputobject $ishSession -Membertype Properties -Name OutputFormat25) | Should Be $true
}
It "IshSession.PublicationOutput25" {
$ishSession.PublicationOutput25 -ne $null | Should Not BeNullOrEmpty
-not (Get-Member -inputobject $ishSession -Membertype Properties -Name PublicationOutput25) | Should Be $true
}
It "IshSession.Search25" {
$ishSession.Search25 -ne $null | Should Not BeNullOrEmpty
-not (Get-Member -inputobject $ishSession -Membertype Properties -Name Search25) | Should Be $true
}
It "IshSession.Settings25" {
$ishSession.Settings25 -ne $null | Should Not BeNullOrEmpty
-not (Get-Member -inputobject $ishSession -Membertype Properties -Name Settings25) | Should Be $true
}
It "IshSession.TranslationJob25" {
$ishSession.TranslationJob25 -ne $null | Should Not BeNullOrEmpty
-not (Get-Member -inputobject $ishSession -Membertype Properties -Name TranslationJob25) | Should Be $true
}
It "IshSession.TranslationTemplate25" {
$ishSession.TranslationTemplate25 -ne $null | Should Not BeNullOrEmpty
-not (Get-Member -inputobject $ishSession -Membertype Properties -Name TranslationTemplate25) | Should Be $true
}
It "IshSession.User25" {
$ishSession.User25 -ne $null | Should Not BeNullOrEmpty
-not (Get-Member -inputobject $ishSession -Membertype Properties -Name User25) | Should Be $true
}
It "IshSession.UserGroup25" {
$ishSession.UserGroup25 -ne $null | Should Not BeNullOrEmpty
}
It "IshSession.UserRole25" {
$ishSession.UserRole25 -ne $null | Should Not BeNullOrEmpty
-not (Get-Member -inputobject $ishSession -Membertype Properties -Name UserGroup25) | Should Be $true
}
}
}
Expand Down

0 comments on commit 7735e09

Please sign in to comment.