Skip to content

Commit

Permalink
xWebAppPool: Correctly compare comma-separated String memberships (#439)
Browse files Browse the repository at this point in the history
- Changes to xWebAppPool
  - Fix false `Test-TargetResource` failure for `logEventOnRecycle` if items
    in the Configuration property are specified in a different order than IIS natively
    stores them (issue #434).
  • Loading branch information
mcbobke authored and johlju committed Sep 9, 2019
1 parent 3f3bcc2 commit 36cfa7d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
23 changes: 22 additions & 1 deletion DSCResources/MSFT_xWebAppPool/MSFT_xWebAppPool.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ data PropertyData
)
}

# Properties that are specified as a single comma-separated string containing multiple flags
$script:commaSeparatedStringProperties = @(
'logEventOnRecycle'
)

function Get-TargetResource
{
<#
Expand Down Expand Up @@ -842,7 +847,23 @@ function Test-TargetResource
$propertyPath = $_.Path
$property = Get-Property -Object $appPool -PropertyName $propertyPath

if (
# First check if the property is a single comma-separated string containing multiple flags, split and compare membership if so
if ($propertyName -in $script:commaSeparatedStringProperties)
{
$currentPropertyCollection = $property.Split(',')
$expectedPropertyCollection = $PSBoundParameters[$propertyName].Split(',')

$compareResult = @(Compare-Object -ReferenceObject $currentPropertyCollection -DifferenceObject $expectedPropertyCollection)
if ($compareResult.Length -ne 0)
{
Write-Verbose -Message (
$LocalizedData['VerbosePropertyNotInDesiredState'] -f $propertyName, $Name
)

$inDesiredState = $false
}
}
elseif (
$PSBoundParameters[$propertyName] -ne $property
)
{
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ This resource manages the IIS configuration section locking (overrideMode) to co
* Added ServerAutoStart (controls website autostart) and changed documentation for ServiceAutoStartEnabled (controls application auto-initialization). Fixes #325.
* Fix multiple HTTPS bindings on one xWebsite receiving the first binding's certificate [#332](https://github.com/PowerShell/xWebAdministration/issues/332)
* Added unit regression test
* Changes to xWebAppPool
* Fix false `Test-TargetResource` failure for `logEventOnRecycle` if items in the Configuration property are specified in a different order than IIS natively stores them [#434](https://github.com/PowerShell/xWebAdministration/issues/434)

### 2.7.0.0

Expand Down
5 changes: 5 additions & 0 deletions Tests/Unit/MSFT_xWebAppPool.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1563,6 +1563,11 @@ try
Should Be $true
}

It 'Should return True when the property matches the desired state but items are in a different order' {
Test-TargetResource -Ensure 'Present' -Name $mockAppPool.name -logEventOnRecycle 'IsapiUnhealthy,OnDemand,ConfigChange,PrivateMemory,Time,Requests,Schedule,Memory' |
Should Be $true
}

It 'Should return False when the property does not match the desired state' {
Test-TargetResource -Ensure 'Present' -Name $mockAppPool.name -logEventOnRecycle 'Time,Memory,PrivateMemory' |
Should Be $false
Expand Down

0 comments on commit 36cfa7d

Please sign in to comment.