From 36585ac997d841df1fd4957b6bc3c47b232448d4 Mon Sep 17 00:00:00 2001 From: Akos Murati Date: Fri, 15 Jul 2016 14:14:10 +1200 Subject: [PATCH] Add -IncludeAppSetting switch to all relevant cmdlets --- CHANGELOG.md | 6 +++++ Functions/PSUri/Get-PSUri.ps1 | 28 +++++++++++++++------- Functions/PSWebConfig/Test-PSWebConfig.ps1 | 23 +++++++++++++----- Tests/PSUri/Get-PSUri.tests.ps1 | 18 ++++++++++++-- 4 files changed, 58 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9592101..4f56fa6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,3 +37,9 @@ ## 1.5.2 (Feb 28, 2016) - Refactor Pester tests and Fixtures - Reorganize functions into subfolders + +## 1.6.0 (Jul 15, 2016) +- Enable remote executions with resolving RunspaceIds without specifying -Session parameter +- Add password-masking to Test-PSConnectionString +- Test-PsWebConfig now support -IncludeAppsettings parameters +- Better detailed -Verbose info from all cmdlets diff --git a/Functions/PSUri/Get-PSUri.ps1 b/Functions/PSUri/Get-PSUri.ps1 index f740397..61ca6f9 100644 --- a/Functions/PSUri/Get-PSUri.ps1 +++ b/Functions/PSUri/Get-PSUri.ps1 @@ -9,6 +9,8 @@ .PARAMETER ConfigXml Mandatory - Pipeline input for Configuration XML +.PARAMETER IncludeAppSettings + Optional - Switch to include http/s URIs from appsettings .EXAMPLE Get-PSWebConfig -Path 'C:\inetpub\wwwroot\myapp' | Get-PSUri @@ -19,19 +21,27 @@ function Get-PSUri { [CmdletBinding()] param( [Parameter(Mandatory=$true,ValueFromPipeLine=$true)] - [psobject[]]$ConfigXml + [psobject[]]$ConfigXml, + [switch]$IncludeAppSettings ) process { - # Return all service endpoint addresses + Write-Verbose "Executing Get-PSUri" + + Write-Verbose "Looking for service-endpoint addresses..." Get-PSEndpoint -ConfigXml $configXml - # Return any URL from appSettings as an Address - Get-PSAppSetting -ConfigXml $configXml | - Where-Object value -imatch '^http[s]*:' | - Add-Member -MemberType AliasProperty -Name name -Value key -Force -PassThru | - Add-Member -MemberType AliasProperty -Name address -Value value -Force -PassThru | - Add-Member -MemberType AliasProperty -Name Uri -Value value -Force -PassThru | - Set_Type -TypeName 'PSWebConfig.Uri' + if (-Not $IncludeAppSettings) { + Write-Verbose "Appsettings are not included in URI processing." + return + } else { + Write-Verbose "Looking for any http URLs from appSettings..." + Get-PSAppSetting -ConfigXml $configXml | + Where-Object value -imatch '^http[s]*:' | + Add-Member -MemberType AliasProperty -Name name -Value key -Force -PassThru | + Add-Member -MemberType AliasProperty -Name address -Value value -Force -PassThru | + Add-Member -MemberType AliasProperty -Name Uri -Value value -Force -PassThru | + Set_Type -TypeName 'PSWebConfig.Uri' + } } } diff --git a/Functions/PSWebConfig/Test-PSWebConfig.ps1 b/Functions/PSWebConfig/Test-PSWebConfig.ps1 index 4d9e4e6..99f9e32 100644 --- a/Functions/PSWebConfig/Test-PSWebConfig.ps1 +++ b/Functions/PSWebConfig/Test-PSWebConfig.ps1 @@ -3,8 +3,12 @@ Tests all URI and ConnectionStrings from web or application configuration. .DESCRIPTION - The cmdlet fetches all ConnectionString and URIs for a configuration file - and executes a test against them on a local or remote machine. + The cmdlet fetches all ConnectionString and service endpoint URIs + from a configuration xml and executes a test against them on a + local or remote machine. + + If -IncludeAppSettings switch is defined, it will include any URI or + ConnectionStrings to the tests. .PARAMETER InputObject Mandatory - Parameter to pass a PSWebConfig object @@ -12,6 +16,10 @@ .PARAMETER Session Optional - PSSession to execute configuration test +.PARAMETER IncludeAppSettings + Optional - Switch to include URIs and ConnectionStrings from appSettings + sections + .EXAMPLE Get-PSWebConfig -Path 'c:\intepub\wwwroot\testapp\' | Test-PSWebConfig @@ -25,13 +33,16 @@ function Test-PSWebConfig { [Parameter(ValueFromPipeLine=$true)] [psobject[]]$ConfigXml, + [switch]$IncludeAppSettings, [System.Management.Automation.Runspaces.PSSession]$Session ) process { - Get-PSEndpoint -ConfigXml $ConfigXml | - Test-PSUri -Session $Session + Write-Verbose "Executing Test-PSWebConfig" + + Get-PSUri -ConfigXml $ConfigXml -IncludeAppSettings:$IncludeAppSettings | + Test-PSUri -Session $Session - Get-PSConnectionString -ConfigXml $ConfigXml | - Test-PSConnectionString -Session $Session + Get-PSConnectionString -ConfigXml $ConfigXml -IncludeAppSettings:$IncludeAppSettings | + Test-PSConnectionString -Session $Session } } diff --git a/Tests/PSUri/Get-PSUri.tests.ps1 b/Tests/PSUri/Get-PSUri.tests.ps1 index 19434a0..3d04ba7 100644 --- a/Tests/PSUri/Get-PSUri.tests.ps1 +++ b/Tests/PSUri/Get-PSUri.tests.ps1 @@ -7,9 +7,10 @@ $webConfigFile = Join-Path $script:FixturePath 'web.config' Describe 'Get-PSUri' { Context 'Local web.config' { $config = Get-PSWebConfig -Path $webConfigFile -Verbose:$isVerbose - $addresses = $config | Get-PSUri -Verbose:$isVerbose + $addresses = $config | Get-PSUri -Verbose:$isVerbose -IncludeAppsettings + $endpoints = (Get-PSEndpoint -ConfigXml $config -Verbose:$isVerbose) - It 'should return all addresses' { + It 'should return all addresses with -IncludeAppsettings' { $addresses | Should Not BeNullOrEmpty $addresses.Count | Should Be (2+2) # appSetting + endpoints $addresses | Foreach-Object { @@ -20,5 +21,18 @@ Describe 'Get-PSUri' { $_.Uri | Should Match '^http[s]*:' } } + + It 'should contain all service endpoints' { + $addresses | Should Not BeNullOrEmpty + foreach ($e in $endpoints) { + $addresses -contains $e | Should Be $true + } + } + + It 'should be the same as Get-PSEndpoint without -IncludeAppsettings' { + $addressesWithouAppSettings = $config | Get-PSUri -Verbose:$isVerbose + $addressesWithouAppSettings | Should Not BeNullOrEmpty + $addressesWithouAppSettings | Should Be $endpoints + } } }