Skip to content

Commit

Permalink
#115 Merged cmdlets and tests of Session (with PesterV5, 132)... Brok…
Browse files Browse the repository at this point in the history
…e compatiblity regarding ParameterSets based on Issuer, TimeoutIssue, TimeoutService and PSCredential... Tests are working...
  • Loading branch information
ddemeyer committed Sep 15, 2021
1 parent cd0dad0 commit 19ef488
Show file tree
Hide file tree
Showing 8 changed files with 319 additions and 145 deletions.
5 changes: 4 additions & 1 deletion Doc/TheExecution-ISHRemote-7.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,23 @@ Publishing problem perhaps, as copying %USER%\.nuget\packages\system.servicemode
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. Main branch ISHRemote v0.14 had all Pester tests refactored to Pester 5.3.0 (see #132)... still conditional/skip flags required to distuingish between WCF/ASMX/OpenAPI
6. `TrisoftCmdlet.cs` says `[assembly: ComVisible(false)]` ... brrr? Why? Removed
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.
2. Aligned Session, so `New-IshSession` and `Test-IshSession` with upcoming 0.14 (#132) including PesterV5 tests.
## Next
1. `New-IshSession -WsBaseUrl .../ISHWS/ -IshUserName ... -IshPassword -Protocol [AsmxAuthenticationContext (default) | OpenApiBasicAuthentication | OpenApiOpenConnectId]` so Protocol as a parameter to use in Switch-cases in every cmdlet on how to route the code
7. Migrate `*-IshFolder` cmdlets as you need them for almost all tests anyway. Easy to do performance runs on Add-IshFolder and Remove-IshFolder.
7. Migrate `*-IshFolder` cmdlets as you need them for almost all tests anyway. Easy to do performance runs on Add-IshFolder and Remove-IshFolder. Later we have the following API25 to API30 mapping
1. Folder25.Create -> API30.Create (ready)
2. Folder25.RetrieveMetadataByIshFolderRefs -> API30.GetFolderList (NotImplemented planned for PI20.4)
3. Folder25.Delete -> API30.DeleteFolder (ready)
4. Folder25.GetMetadataByIshFolderRef -> API30.GetFolder (ready)
5. Folder25.GetMetadata -> API30.GetFolderByFolderPath, perhaps GetRootFolderList (NotPlanned)
6. Folder25.GetSubFoldersByIshFolderRef -> API30.GetFolderObjectList (ready)
1. Next is add all SoapClient proxies
8. 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)
9. 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.
10. 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.
11. ISHRemote 0.x branch replace bad quote `“` with proper quote `"` in `*.Tests.ps1`, for example NewIshSession.Tests.ps1
# Performance
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
BeforeAll {
Write-Host ("`r`nLoading ISHRemote.PesterSetup.ps1 for MyCommand[" + $MyInvocation.MyCommand + "]...")
Write-Host BeforeAll loading the extra script
$cmdletName = "New-IshSession"
Write-Host ("`r`nLoading ISHRemote.PesterSetup.ps1 over BeforeAll-block for MyCommand[" + $cmdletName + "]...")
. (Join-Path (Split-Path -Parent $PSCommandPath) "\..\..\ISHRemote.PesterSetup.ps1")

Write-Host "Initializing Test Data and Variables"

Write-Host ("Running "+$cmdletName+" Test Data and Variables initialization")
$ishSession = $null # Resetting generic $ishSession
}

Describe "New-IshSession" -Tags "Read" {

Context "New-IshSession ISHDeploy::Enable-ISHIntegrationSTSInternalAuthentication/Prepare-SupportAccess.ps1" {
It "Parameter WsBaseUrl contains 'SDL' (legacy script)" -skip {
$ishSession = New-IshSession -WsBaseUrl https://example.com/ISHWS/SDL/ -IshUserName x -IshPassword y
$ishSession.ServerVersion | Should -Not BeNullOrEmpty
$ishSession.ServerVersion | Should -Not -BeNullOrEmpty
}
It "Parameter WsBaseUrl contains 'Internal' (ISHDeploy)" -skip {
$ishSession = New-IshSession -WsBaseUrl https://example.com/ISHWS/Internal/ -IshUserName x -IshPassword y
$ishSession.ServerVersion | Should -Not BeNullOrEmpty
$ishSession.ServerVersion | Should -Not -BeNullOrEmpty
}
}

Expand Down Expand Up @@ -90,8 +90,8 @@ Describe "New-IshSession" -Tags "Read" {
It "IshSession.ServerVersion contains 4 dot-seperated parts" {
$ishSession.ServerVersion.Split(".").Length | Should -Be 4
}
It "IshSession.Timeout defaults to 20s" {
$ishSession.Timeout.TotalMilliseconds -eq 20000 | Should -Be $true
It "IshSession.Timeout defaults to 30m" {
$ishSession.Timeout.TotalMinutes -eq 30 | Should -Be $true
}
It "IshSession.StrictMetadataPreference" {
$ishSession.StrictMetadataPreference | Should -Be "Continue"
Expand All @@ -111,7 +111,7 @@ Describe "New-IshSession" -Tags "Read" {
It "WsBaseUrl without ending slash" {
# .NET throws unhandy "Reference to undeclared entity 'raquo'." error
$webServicesBaseUrlWithoutEndingSlash = $webServicesBaseUrl.Substring(0,$webServicesBaseUrl.Length-1)
{ New-IshSession -WsBaseUrl $webServicesBaseUrlWithoutEndingSlash -IshUserName $ishUserName -IshPassword $ishPassword } | Should -Not -Throw
{ $ishSession = New-IshSession -WsBaseUrl $webServicesBaseUrlWithoutEndingSlash -IshUserName $ishUserName -IshPassword $ishPassword } | Should -Not -Throw
}
}

Expand All @@ -120,7 +120,7 @@ Describe "New-IshSession" -Tags "Read" {
{ $ishSession = New-IshSession -WsBaseUrl $webServicesBaseUrl -IshUserName $ishUserName -IshPassword $ishPassword -Timeout "INVALIDTIMEOUT" } | Should -Throw
}
It "IshSession.Timeout set to 30s" {
$ishSession = New-IshSession -WsBaseUrl $webServicesBaseUrl -IshUserName $ishUserName -IshPassword $ishPassword -Timeout (New-TimeSpan -Seconds 60)
$ishSession = New-IshSession -WsBaseUrl $webServicesBaseUrl -IshUserName $ishUserName -IshPassword $ishPassword -Timeout (New-TimeSpan -Seconds 60) -WarningAction Ignore -ErrorAction Ignore
$ishSession.Timeout.TotalMilliseconds | Should -Be "60000"
}
It "IshSession.Timeout on INVALID url set to 1ms execution" {
Expand All @@ -134,11 +134,11 @@ Describe "New-IshSession" -Tags "Read" {

Context "New-IshSession IgnoreSslPolicyErrors" {
It "Parameter IgnoreSslPolicyErrors specified positive flow" {
$ishSession = New-IshSession -WsBaseUrl $webServicesBaseUrl -IshUserName $ishUserName -IshPassword $ishPassword -IgnoreSslPolicyErrors
$ishSession = New-IshSession -WsBaseUrl $webServicesBaseUrl -IshUserName $ishUserName -IshPassword $ishPassword -IgnoreSslPolicyErrors -WarningAction Ignore
$ishSession.ServerVersion | Should -Not -BeNullOrEmpty
$ishSession.ServerVersion.Split(".").Length | Should -Be 4
}
It "Parameter IgnoreSslPolicyErrors specified negative flow (segment-one-url)" -skip {
It "Parameter IgnoreSslPolicyErrors specified negative flow (segment-one-url)" -Skip {
# replace hostname like machinename.somedomain.com to machinename only, marked as skipped for non-development machines
$slash1Position = $webServicesBaseUrl.IndexOf("/")
$slash2Position = $webServicesBaseUrl.IndexOf("/",$slash1Position+1)
Expand All @@ -147,11 +147,11 @@ Describe "New-IshSession" -Tags "Read" {
$computername = $hostname.Substring(0,$hostname.IndexOf("."))
$webServicesBaseUrlToComputerName = $webServicesBaseUrl.Replace($hostname,$computername)
$ishSession = New-IshSession -WsBaseUrl $webServicesBaseUrlToComputerName -IshUserName $ishUserName -IshPassword $ishPassword -IgnoreSslPolicyErrors
$ishSession.ServerVersion | Should -Not BeNullOrEmpty
$ishSession.ServerVersion | Should -Not -BeNullOrEmpty
$ishSession.ServerVersion.Split(".").Length | Should -Be 4
$ishSession.Dispose()
}
<# It "Parameter IgnoreSslPolicyErrors specified negative flow (Resolve-DnsName)" -skip {
<# It "Parameter IgnoreSslPolicyErrors specified negative flow (Resolve-DnsName)" -Skip {
# replace hostname like example.com with ip-address
$slash1Position = $webServicesBaseUrl.IndexOf("/")
$slash2Position = $webServicesBaseUrl.IndexOf("/",$slash1Position+1)
Expand All @@ -160,8 +160,8 @@ Describe "New-IshSession" -Tags "Read" {
$ipAddress = Resolve-DnsName –Name $hostname # only available on Windows Server 2012 R2 and Windows 8.1
$webServicesBaseUrlToIpAddress = $webServicesBaseUrl.Replace($hostname,$ipAddress)
$ishSession = New-IshSession -WsBaseUrl $webServicesBaseUrlToIpAddress -IshUserName $ishUserName -IshPassword $ishPassword -IgnoreSslPolicyErrors
$ishSession.ServerVersion | Should Not BeNullOrEmpty
$ishSession.ServerVersion.Split(".").Length | Should Be 4
$ishSession.ServerVersion | Should -Not -BeNullOrEmpty
$ishSession.ServerVersion.Split(".").Length | Should -Be 4
$ishSession.Dispose()
} #>
}
Expand Down Expand Up @@ -228,5 +228,12 @@ Describe "New-IshSession" -Tags "Read" {
It "IshSession.UserGroup25" {
-not (Get-Member -inputobject $ishSession -Membertype Properties -Name UserGroup25) | Should -Be $true
}
It "IshSession.UserRole25" {
-not (Get-Member -inputobject $ishSession -Membertype Properties -Name UserRole25) | Should -Be $true
}
}
}

AfterAll {
Write-Host ("Running "+$cmdletName+" Test Data and Variables cleanup")
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ namespace Trisoft.ISHRemote.Cmdlets.Session
/// </example>
/// <example>
/// <code>
/// $ishSession = New-IshSession -WsBaseUrl "https://example.com/ISHWS/"
/// </code>
/// <para>Building a session for the chosen service based on Active Directory authentication. An implicit NetworkCredential object will be passed for authentication to the service.</para>
/// </example>
/// <example>
/// <code>
/// $ishSession = New-IshSession -WsBaseUrl "https://example.com/ISHWS/" -PSCredential "Admin"
/// </code>
/// <para>Iteratively the New-IshSession line with PSCredential parameter holding a string representation will prompt you for a password.</para>
Expand All @@ -59,23 +53,14 @@ namespace Trisoft.ISHRemote.Cmdlets.Session
public sealed class NewIshSession : SessionCmdlet
{
/// <summary>
/// <para type="description">SDL Tridion Docs Content Manager web services main URL. Note that the URL is case-sensitive and should end with an ending slash! For example: "https://example.com/ISHWS/"</para>
/// <para type="description">Tridion Docs Content Manager web services main URL. Note that the URL is case-sensitive and should end with an ending slash! For example: "https://example.com/ISHWS/"</para>
/// </summary>
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "UserNamePassword")]
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "PSCredential")]
[ValidateNotNullOrEmpty]
public string WsBaseUrl { get; set; }

/// <summary>
/// <para type="description">Standard PowerShell Credential class</para>
/// </summary>
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "PSCredential")]
[ValidateNotNullOrEmpty]
[Credential]
public PSCredential PSCredential { get; set; }

/// <summary>
/// <para type="description">Username to login into SDL Tridion Docs Content Manager. When left empty, fall back to ActiveDirectory.</para>
/// <para type="description">Username to login into Tridion Docs Content Manager. When left empty, fall back to ActiveDirectory.</para>
/// </summary>
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "UserNamePassword")]
[ValidateNotNullOrEmpty]
Expand All @@ -86,7 +71,7 @@ public string IshUserName
}

/// <summary>
/// <para type="description">Password to login into SDL Tridion Docs Content Manager</para>
/// <para type="description">Password to login into Tridion Docs Content Manager</para>
/// </summary>
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "UserNamePassword")]
[AllowEmptyString]
Expand All @@ -97,9 +82,9 @@ public string IshPassword
}

/// <summary>
/// <para type="description">Timeout value expressed as TimeSpan, that controls Send/Receive timeouts of HttpClient when downloading content like connectionconfiguration.xml Defaults to 20 seconds.</para>
/// <para type="description">Timeout value expressed as TimeSpan, that controls Send/Receive timeouts of HttpClient when processing ASMX services or downloading content like connectionconfiguration.xml Defaults to 30 minutes.</para>
/// </summary>
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false)]
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "UserNamePassword")]
public TimeSpan Timeout
{
get { return _timeout; }
Expand All @@ -109,7 +94,7 @@ public TimeSpan Timeout
/// <summary>
/// <para type="description">IgnoreSslPolicyErrors presence indicates that a custom callback will be assigned to ServicePointManager.ServerCertificateValidationCallback. Defaults false of course, as this is creates security holes! But very handy for Fiddler usage though.</para>
/// </summary>
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false)]
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "UserNamePassword")]
public SwitchParameter IgnoreSslPolicyErrors
{
get { return _ignoreSslPolicyErrors; }
Expand All @@ -119,7 +104,7 @@ public SwitchParameter IgnoreSslPolicyErrors
#region Private fields
private string _ishUserName = null;
private string _ishPassword = null;
private TimeSpan _timeout = new TimeSpan(0, 0, 20); // up to 15s for a DNS lookup according to https://msdn.microsoft.com/en-us/library/system.net.http.httpclient.timeout%28v=vs.110%29.aspx
private TimeSpan _timeout = new TimeSpan(0, 30, 0); // up to 15s for a DNS lookup according to https://msdn.microsoft.com/en-us/library/system.net.http.httpclient.timeout%28v=vs.110%29.aspx
private bool _ignoreSslPolicyErrors = false;

#endregion
Expand All @@ -128,13 +113,6 @@ protected override void ProcessRecord()
try
{
int ishPasswordLength = _ishPassword == null ? 0 : _ishPassword.Length;
if (PSCredential != null)
{
_ishUserName = PSCredential.UserName;
WriteWarning($"PSCredential.Password conversion might be wrong because of Windows only cryptography!");
_ishPassword = PSCredential.Password.ToString();
}

WriteVerbose($"Connecting to WsBaseUrl[{WsBaseUrl}] IshUserName[{_ishUserName}] IshPassword[" + new string('*', ishPasswordLength) + "]");
WriteDebug($"Connecting to WsBaseUrl[{WsBaseUrl}] IshUserName[{_ishUserName}] IshPassword[" + new string('*', ishPasswordLength) + $"] Timeout[{_timeout}] IgnoreSslPolicyErrors[{_ignoreSslPolicyErrors}]");
IshSession ishSession = new IshSession(Logger, WsBaseUrl, _ishUserName, _ishPassword, _timeout, _ignoreSslPolicyErrors);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
BeforeAll {
$cmdletName = "Test-IshSession"
Write-Host ("`r`nLoading ISHRemote.PesterSetup.ps1 over BeforeAll-block for MyCommand[" + $cmdletName + "]...")
. (Join-Path (Split-Path -Parent $PSCommandPath) "\..\..\ISHRemote.PesterSetup.ps1")

Write-Host ("Running "+$cmdletName+" Test Data and Variables initialization")
}

Describe "Test-IshSession" -Tags "Read" {
Context "Test-IshSession ISHDeploy::Enable-ISHIntegrationSTSInternalAuthentication/Prepare-SupportAccess.ps1" {
It "Parameter WsBaseUrl contains 'SDL' (legacy script)" -Skip {
Test-IshSession -WsBaseUrl https://example.com/ISHWS/SDL/ -IshUserName x -IshPassword y | Should -Be $true
}
It "Parameter WsBaseUrl contains 'Internal' (ISHDeploy)" -Skip {
Test-IshSession -WsBaseUrl https://example.com/ISHWS/Internal/ -IshUserName x -IshPassword y | Should -Be $true
}
}

Context "Test-IshSession UserNamePassword" {
It "Parameter WsBaseUrl invalid" {
Test-IshSession -WsBaseUrl "http:///INVALIDWSBASEURL" -IshUserName "INVALIDISHUSERNAME" -IshPassword "INVALIDISHPASSWORD" | Should -Be $false
}
It "Parameter IshUserName invalid" {
Test-IshSession -WsBaseUrl $webServicesBaseUrl -IshUserName "INVALIDISHUSERNAME" -IshPassword "INVALIDISHPASSWORD" | Should -Be $false
}
It "Parameter IshPassword specified" {
Test-IshSession -WsBaseUrl $webServicesBaseUrl -IshUserName $ishUserName -IshPassword "INVALIDISHPASSWORD" | Should -Be $false
}
}

Context "Test-IshSession returns bool" {
BeforeAll {
$ishSessionResult = Test-IshSession -WsBaseUrl $webServicesBaseUrl -IshUserName $ishUserName -IshPassword $ishPassword
}
It "GetType()" {
$ishSessionResult.GetType().Name | Should -BeExactly "Boolean"
}
}

Context "Test-IshSession WsBaseUrl without ending slash" {
It "WsBaseUrl without ending slash" {
# .NET throws unhandy "Reference to undeclared entity 'raquo'." error
$webServicesBaseUrlWithoutEndingSlash = $webServicesBaseUrl.Substring(0,$webServicesBaseUrl.Length-1)
Test-IshSession -WsBaseUrl $webServicesBaseUrlWithoutEndingSlash -IshUserName $ishUserName -IshPassword $ishPassword | Should -Be $true
}
}

Context "Test-IshSession Timeout" {
It "Parameter Timeout Invalid" {
{ Test-IshSession -WsBaseUrl $webServicesBaseUrl -IshUserName $ishUserName -IshPassword $ishPassword -Timeout "INVALIDTIMEOUT" } | Should -Throw
}
It "IshSession.Timeout on INVALID url set to 1ms execution" {
# TaskCanceledException: A task was canceled.
$invalidWebServicesBaseUrl = $webServicesBaseUrl -replace "://", "://INVALID"
Test-IshSession -WsBaseUrl $invalidWebServicesBaseUrl -IshUserName $ishUserName -IshPassword $ishPassword -Timeout (New-Object TimeSpan(0,0,0,0,1)) | Should -Be $false
}
}

Context "Test-IshSession IgnoreSslPolicyErrors" {
It "Parameter IgnoreSslPolicyErrors specified negative flow (segment-one-url)" -Skip {
# replace hostname like machinename.somedomain.com to machinename only, marked as skipped for non-development machines
$slash1Position = $webServicesBaseUrl.IndexOf("/")
$slash2Position = $webServicesBaseUrl.IndexOf("/",$slash1Position+1)
$slash3Position = $webServicesBaseUrl.IndexOf("/",$slash2Position+1)
$hostname = $webServicesBaseUrl.Substring($slash2Position+1,$slash3Position-$slash2Position-1)
$computername = $hostname.Substring(0,$hostname.IndexOf("."))
$webServicesBaseUrlToComputerName = $webServicesBaseUrl.Replace($hostname,$computername)
Test-IshSession -WsBaseUrl $webServicesBaseUrlToComputerName -IshUserName $ishUserName -IshPassword $ishPassword -IgnoreSslPolicyErrors -WarningAction Ignore | Should -Be $true
}
}
}

AfterAll {
Write-Host ("Running "+$cmdletName+" Test Data and Variables cleanup")
}
Loading

0 comments on commit 19ef488

Please sign in to comment.