diff --git a/CHANGELOG.md b/CHANGELOG.md index 2123d80..92bd538 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- AdfsApplicationPermission + - Fixed issue comparing multiple ScopeNames ([#67](https://github.com/X-Guardian/AdfsDsc/issues/67)]). - AdsfRelyingPartyTrust - Fixed issue when the `AllowedClientTypes` Property had multiple values. diff --git a/Tests/Unit/MSFT_AdfsApplicationPermission.Tests.ps1 b/Tests/Unit/MSFT_AdfsApplicationPermission.Tests.ps1 index dcc43e2..648089c 100644 --- a/Tests/Unit/MSFT_AdfsApplicationPermission.Tests.ps1 +++ b/Tests/Unit/MSFT_AdfsApplicationPermission.Tests.ps1 @@ -51,7 +51,7 @@ try ClientRoleIdentifier = 'NativeApp1' ServerRoleIdentifier = 'https://nativeapp1.contoso.com' Description = "This is the AppPermission1 Description" - ScopeNames = 'openid' + ScopeNames = 'openid', 'profile' Ensure = 'Present' } @@ -65,7 +65,7 @@ try $mockChangedResource = @{ Description = "This is the new AppPermission1 Description" - ScopeNames = 'openid, profile' + ScopeNames = 'openid' } $mockGetTargetResourceResult = @{ @@ -343,7 +343,7 @@ try ClientRoleIdentifier = $mockResource.ClientRoleIdentifier ServerRoleIdentifier = $mockResource.ServerRoleIdentifier Description = $mockResource.Description - ScopeNames = $mockResource.ScopeNames + ScopeNames = $mockResource.ScopeNames | Sort-Object -Descending } $testTargetResourcePresentParameters = $testTargetResourceParameters.Clone() diff --git a/source/DSCResources/MSFT_AdfsApplicationPermission/MSFT_AdfsApplicationPermission.psm1 b/source/DSCResources/MSFT_AdfsApplicationPermission/MSFT_AdfsApplicationPermission.psm1 index 6e39ae7..221ad8d 100644 --- a/source/DSCResources/MSFT_AdfsApplicationPermission/MSFT_AdfsApplicationPermission.psm1 +++ b/source/DSCResources/MSFT_AdfsApplicationPermission/MSFT_AdfsApplicationPermission.psm1 @@ -376,7 +376,8 @@ function Test-TargetResource $propertiesNotInDesiredState = ( Compare-ResourcePropertyState -CurrentValues $targetResource -DesiredValues $PSBoundParameters ` - @commonParms | Where-Object -Property InDesiredState -eq $false) + -UnorderedArrayProperties 'ScopeNames' @commonParms | ` + Where-Object -Property InDesiredState -eq $false) if ($propertiesNotInDesiredState) { diff --git a/source/Modules/AdfsDsc.Common/AdfsDsc.Common.psm1 b/source/Modules/AdfsDsc.Common/AdfsDsc.Common.psm1 index 10e9a82..62118db 100644 --- a/source/Modules/AdfsDsc.Common/AdfsDsc.Common.psm1 +++ b/source/Modules/AdfsDsc.Common/AdfsDsc.Common.psm1 @@ -336,6 +336,10 @@ function Compare-ResourcePropertyState .PARAMETER IgnoreProperties An array of property names, from the keys provided in DesiredValues, that will be ignored. + + .PARAMETER UnorderedArrayProperties + An array of propert names, from the keys provided in Desired Values, that + will be treated as unordered arrays. #> [CmdletBinding()] @@ -356,7 +360,11 @@ function Compare-ResourcePropertyState [Parameter()] [System.String[]] - $IgnoreProperties + $IgnoreProperties, + + [Parameter()] + [System.String[]] + $UnorderedArrayProperties ) if ($PSBoundParameters.ContainsKey('Properties')) @@ -413,11 +421,20 @@ function Compare-ResourcePropertyState Actual = $CurrentValues.$parameterName } + if ($UnorderedArrayProperties -contains $parameterName) + { + $UnorderedArrayProperty = $true + } + else + { + $UnorderedArrayProperty = $false + } + # Check if the parameter is in compliance. $isPropertyInDesiredState = Test-DscPropertyState -Values @{ CurrentValue = $CurrentValues.$parameterName DesiredValue = $DesiredValues.$parameterName - } + } -UnorderedArrayProperty $UnorderedArrayProperty if ($isPropertyInDesiredState) { @@ -450,6 +467,9 @@ function Test-DscPropertyState This is set to a hash table with the current value (the CurrentValue key) and desired value (the DesiredValue key). + .PARAMETER UnorderedArrayProperty + Specifies that the property is an unordered array. + .EXAMPLE Test-DscPropertyState -Values @{ CurrentValue = 'John' @@ -468,7 +488,11 @@ function Test-DscPropertyState ( [Parameter(Mandatory = $true)] [System.Collections.Hashtable] - $Values + $Values, + + [Parameter()] + [System.Boolean] + $UnorderedArrayProperty ) if ([System.String]::IsNullOrEmpty($Values.CurrentValue) -and [System.String]::IsNullOrEmpty($Values.DesiredValue)) @@ -483,9 +507,19 @@ function Test-DscPropertyState } elseif ($Values.DesiredValue.GetType().IsArray -or $Values.CurrentValue.GetType().IsArray) { - $compareObjectParameters = @{ - ReferenceObject = $Values.CurrentValue - DifferenceObject = $Values.DesiredValue + if ($UnorderedArrayProperty) + { + $compareObjectParameters = @{ + ReferenceObject = $Values.CurrentValue | Sort-Object + DifferenceObject = $Values.DesiredValue | Sort-Object + } + } + else + { + $compareObjectParameters = @{ + ReferenceObject = $Values.CurrentValue + DifferenceObject = $Values.DesiredValue + } } $arrayCompare = Compare-Object @compareObjectParameters -SyncWindow 0