Skip to content

Commit

Permalink
AdfsApplicationPermission: Fix Issue Comparing Multiple ScopeNames (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
X-Guardian authored Apr 21, 2023
1 parent ddde349 commit 40a666b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 3 additions & 3 deletions Tests/Unit/MSFT_AdfsApplicationPermission.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand All @@ -65,7 +65,7 @@ try

$mockChangedResource = @{
Description = "This is the new AppPermission1 Description"
ScopeNames = 'openid, profile'
ScopeNames = 'openid'
}

$mockGetTargetResourceResult = @{
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
46 changes: 40 additions & 6 deletions source/Modules/AdfsDsc.Common/AdfsDsc.Common.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand All @@ -356,7 +360,11 @@ function Compare-ResourcePropertyState

[Parameter()]
[System.String[]]
$IgnoreProperties
$IgnoreProperties,

[Parameter()]
[System.String[]]
$UnorderedArrayProperties
)

if ($PSBoundParameters.ContainsKey('Properties'))
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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'
Expand All @@ -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))
Expand All @@ -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
Expand Down

0 comments on commit 40a666b

Please sign in to comment.