Skip to content

Commit 7d78ed9

Browse files
authored
Added support for comparing generic lists (#156)
1 parent f8242e2 commit 7d78ed9

File tree

6 files changed

+306
-11
lines changed

6 files changed

+306
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- `Format-Path`
1313
- Added parameter `ExpandEnvironmentVariable` fixes [#147](https://github.com/dsccommunity/DscResource.Common/issues/147).
14+
- Added support to `Compare-DscParameterState` for comparing large hashtables
15+
that contain lists of elements.
1416

1517
## [0.22.0] - 2025-04-25
1618

SECURITY.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ If you believe you have found a security vulnerability in any of our repository,
99
**Please do not report security vulnerabilities through public GitHub issues.**
1010

1111
Instead, please report them to one or several maintainers of the repository.
12-
The easiest way to do so is to send us a direct message via twitter or find us
12+
The easiest way to do so is to send us a direct message via twitter or find us
1313
on some other social platform.
1414

1515
You should receive a response within 48 hours. If for some reason you do not, please follow up by other means or to other contributors.
1616

1717
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
1818

19-
* Type of issue
20-
* Full paths of source file(s) related to the manifestation of the issue
21-
* The location of the affected source code (tag/branch/commit or direct URL)
22-
* Any special configuration required to reproduce the issue
23-
* Step-by-step instructions to reproduce the issue
24-
* Proof-of-concept or exploit code (if possible)
25-
* Impact of the issue, including how an attacker might exploit the issue
19+
* Type of issue
20+
* Full paths of source file(s) related to the manifestation of the issue
21+
* The location of the affected source code (tag/branch/commit or direct URL)
22+
* Any special configuration required to reproduce the issue
23+
* Step-by-step instructions to reproduce the issue
24+
* Proof-of-concept or exploit code (if possible)
25+
* Impact of the issue, including how an attacker might exploit the issue
2626

2727
This information will help us triage your report more quickly.
2828

source/Public/Compare-DscParameterState.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@ function Compare-DscParameterState
372372
continue # pass to the next key
373373
}
374374
#endregion
375-
#region Check if desired type is array, ifno Hashtable and currenttype hashtable to
376-
if ($desiredType.IsArray)
375+
#region Check if desired type is array, if no Hashtable and current type hashtable to
376+
if ($desiredType.IsArray -or $desiredType.ImplementedInterfaces -contains [System.Collections.IList])
377377
{
378378
Write-Verbose -Message ($script:localizedData.TestDscParameterCompareMessage -f $key, $desiredType.FullName)
379379
# Check if the currentValues and desiredValue are empty array.
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
PrecedenceBefore:
2+
Precedence: 0
3+
Description: 'contoso Custom; Deployed: 16.11.2023 08:54'
4+
SourceObjectType: user
5+
ScopeFilter:
6+
- ScopeConditionList:
7+
- ComparisonOperator: EQUAL
8+
ComparisonValue: E
9+
Attribute: employeeType
10+
- ComparisonOperator: NOTCONTAINS
11+
ComparisonValue: "False"
12+
Attribute: contosoMSAzureADCloudUser
13+
- ComparisonOperator: ISNOTNULL
14+
ComparisonValue: ""
15+
Attribute: mail
16+
- ScopeConditionList:
17+
- ComparisonOperator: EQUAL
18+
ComparisonValue: P
19+
Attribute: employeeType
20+
- ComparisonOperator: NOTCONTAINS
21+
ComparisonValue: "False"
22+
Attribute: contosoMSAzureADCloudUser
23+
- ScopeConditionList:
24+
- ComparisonOperator: EQUAL
25+
ComparisonValue: R
26+
Attribute: employeeType
27+
- ComparisonOperator: NOTCONTAINS
28+
ComparisonValue: "False"
29+
Attribute: contosoMSAzureADCloudUser
30+
- ScopeConditionList:
31+
- ComparisonOperator: EQUAL
32+
ComparisonValue: RR
33+
Attribute: employeeType
34+
- ComparisonOperator: NOTCONTAINS
35+
ComparisonValue: "False"
36+
Attribute: contosoMSAzureADCloudUser
37+
- ScopeConditionList:
38+
- ComparisonOperator: EQUAL
39+
ComparisonValue: RS
40+
Attribute: employeeType
41+
- ComparisonOperator: NOTCONTAINS
42+
ComparisonValue: "False"
43+
Attribute: contosoMSAzureADCloudUser
44+
- ScopeConditionList:
45+
- ComparisonOperator: EQUAL
46+
ComparisonValue: RE
47+
Attribute: employeeType
48+
- ComparisonOperator: NOTCONTAINS
49+
ComparisonValue: "False"
50+
Attribute: contosoMSAzureADCloudUser
51+
- ScopeConditionList:
52+
- ComparisonOperator: EQUAL
53+
ComparisonValue: XP
54+
Attribute: employeeType
55+
- ComparisonOperator: NOTCONTAINS
56+
ComparisonValue: "False"
57+
Attribute: contosoMSAzureADCloudUser
58+
- ScopeConditionList:
59+
- ComparisonOperator: EQUAL
60+
ComparisonValue: XS
61+
Attribute: employeeType
62+
- ComparisonOperator: NOTCONTAINS
63+
ComparisonValue: "False"
64+
Attribute: contosoMSAzureADCloudUser
65+
- ScopeConditionList:
66+
- ComparisonOperator: EQUAL
67+
ComparisonValue: XT
68+
Attribute: employeeType
69+
- ComparisonOperator: NOTCONTAINS
70+
ComparisonValue: "False"
71+
Attribute: contosoMSAzureADCloudUser
72+
- ScopeConditionList:
73+
- ComparisonOperator: EQUAL
74+
ComparisonValue: X
75+
Attribute: employeeType
76+
- ComparisonOperator: NOTCONTAINS
77+
ComparisonValue: "False"
78+
Attribute: contosoMSAzureADCloudUser
79+
- ScopeConditionList:
80+
- ComparisonOperator: EQUAL
81+
ComparisonValue: S
82+
Attribute: employeeType
83+
- ComparisonOperator: EQUAL
84+
ComparisonValue: VolkswagenGroupDev
85+
Attribute: contosoMSAzureADCloudUser
86+
- ScopeConditionList:
87+
- ComparisonOperator: EQUAL
88+
ComparisonValue: S
89+
Attribute: employeeType
90+
- ComparisonOperator: ISNOTNULL
91+
ComparisonValue: ""
92+
Attribute: mail
93+
- ComparisonOperator: NOTCONTAINS
94+
ComparisonValue: "False"
95+
Attribute: contosoMSAzureADCloudUser
96+
- ScopeConditionList:
97+
- ComparisonOperator: EQUAL
98+
ComparisonValue: XG
99+
Attribute: employeeType
100+
- ComparisonOperator: EQUAL
101+
ComparisonValue: VolkswagenGroupDev
102+
Attribute: contosoMSAzureADCloudUser
103+
Ensure: Present
104+
Disabled: false
105+
JoinFilter:
106+
- JoinConditionList:
107+
- CaseSensitive: false
108+
CSAttribute: objectSid
109+
MVAttribute: objectSid
110+
- JoinConditionList:
111+
- CaseSensitive: false
112+
CSAttribute: msExchMasterAccountSid
113+
MVAttribute: objectSid
114+
- JoinConditionList:
115+
- CaseSensitive: false
116+
CSAttribute: objectSid
117+
MVAttribute: msExchMasterAccountSid
118+
- JoinConditionList:
119+
- CaseSensitive: false
120+
CSAttribute: objectSid
121+
MVAttribute: msRTCSIP-OriginatorSid
122+
- JoinConditionList:
123+
- CaseSensitive: false
124+
CSAttribute: mail
125+
MVAttribute: mail
126+
EnablePasswordSync: false
127+
ImmutableTag:
128+
PrecedenceAfter:
129+
Name: Contoso - Inbound - UserJoin - OldAD
130+
IsLegacyCustomRule: false
131+
LinkType: Provision
132+
ConnectorName: contoso.com
133+
IsStandardRule: false
134+
TargetObjectType: person
135+
AttributeFlowMappings: []
136+
Direction: Inbound
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
PrecedenceBefore:
2+
Precedence: 0
3+
Description: 'contoso Custom; Deployed: 16.11.2023 08:54'
4+
SourceObjectType: user
5+
ScopeFilter:
6+
- ScopeConditionList:
7+
- ComparisonOperator: EQUAL
8+
ComparisonValue: E
9+
Attribute: employeeType
10+
- ComparisonOperator: NOTCONTAINS
11+
ComparisonValue: "False"
12+
Attribute: contosoMSAzureADCloudUser
13+
- ComparisonOperator: ISNOTNULL
14+
ComparisonValue: ""
15+
Attribute: mail
16+
- ScopeConditionList:
17+
- ComparisonOperator: EQUAL
18+
ComparisonValue: P
19+
Attribute: employeeType
20+
- ComparisonOperator: NOTCONTAINS
21+
ComparisonValue: "False"
22+
Attribute: contosoMSAzureADCloudUser
23+
- ScopeConditionList:
24+
- ComparisonOperator: EQUAL
25+
ComparisonValue: R
26+
Attribute: employeeType
27+
- ComparisonOperator: NOTCONTAINS
28+
ComparisonValue: "False"
29+
Attribute: contosoMSAzureADCloudUser
30+
- ScopeConditionList:
31+
- ComparisonOperator: EQUAL
32+
ComparisonValue: RR
33+
Attribute: employeeType
34+
- ComparisonOperator: NOTCONTAINS
35+
ComparisonValue: "False"
36+
Attribute: contosoMSAzureADCloudUser
37+
- ScopeConditionList:
38+
- ComparisonOperator: EQUAL
39+
ComparisonValue: RS
40+
Attribute: employeeType
41+
- ComparisonOperator: NOTCONTAINS
42+
ComparisonValue: "False"
43+
Attribute: contosoMSAzureADCloudUser
44+
- ScopeConditionList:
45+
- ComparisonOperator: EQUAL
46+
ComparisonValue: RE
47+
Attribute: employeeType
48+
- ComparisonOperator: NOTCONTAINS
49+
ComparisonValue: "False"
50+
Attribute: contosoMSAzureADCloudUser
51+
- ScopeConditionList:
52+
- ComparisonOperator: EQUAL
53+
ComparisonValue: XP
54+
Attribute: employeeType
55+
- ComparisonOperator: NOTCONTAINS
56+
ComparisonValue: "False"
57+
Attribute: contosoMSAzureADCloudUser
58+
- ScopeConditionList:
59+
- ComparisonOperator: EQUAL
60+
ComparisonValue: XS
61+
Attribute: employeeType
62+
- ComparisonOperator: NOTCONTAINS
63+
ComparisonValue: "False"
64+
Attribute: contosoMSAzureADCloudUser
65+
- ScopeConditionList:
66+
- ComparisonOperator: EQUAL
67+
ComparisonValue: XT
68+
Attribute: employeeType
69+
- ComparisonOperator: NOTCONTAINS
70+
ComparisonValue: "False"
71+
Attribute: contosoMSAzureADCloudUser
72+
- ScopeConditionList:
73+
- ComparisonOperator: EQUAL
74+
ComparisonValue: X
75+
Attribute: employeeType
76+
- ComparisonOperator: NOTCONTAINS
77+
ComparisonValue: "False"
78+
Attribute: contosoMSAzureADCloudUser
79+
- ScopeConditionList:
80+
- ComparisonOperator: EQUAL
81+
ComparisonValue: S
82+
Attribute: employeeType
83+
- ComparisonOperator: EQUAL
84+
ComparisonValue: VolkswagenGroupDev
85+
Attribute: contosoMSAzureADCloudUser
86+
- ScopeConditionList:
87+
- ComparisonOperator: EQUAL
88+
ComparisonValue: S
89+
Attribute: employeeType
90+
- ComparisonOperator: ISNOTNULL
91+
ComparisonValue: ""
92+
Attribute: mail
93+
- ComparisonOperator: NOTCONTAINS
94+
ComparisonValue: "False"
95+
Attribute: contosoMSAzureADCloudUser
96+
- ScopeConditionList:
97+
- ComparisonOperator: EQUAL
98+
ComparisonValue: XG
99+
Attribute: employeeType
100+
- ComparisonOperator: EQUAL
101+
ComparisonValue: VolkswagenGroupDev
102+
Attribute: contosoMSAzureADCloudUser
103+
Ensure: Present
104+
Disabled: false
105+
JoinFilter:
106+
- JoinConditionList:
107+
- CaseSensitive: false
108+
CSAttribute: objectSid
109+
MVAttribute: objectSid
110+
- JoinConditionList:
111+
- CaseSensitive: false
112+
CSAttribute: msExchMasterAccountSid
113+
MVAttribute: objectSid
114+
- JoinConditionList:
115+
- CaseSensitive: false
116+
CSAttribute: objectSid
117+
MVAttribute: msExchMasterAccountSid
118+
- JoinConditionList:
119+
- CaseSensitive: false
120+
CSAttribute: objectSid
121+
MVAttribute: msRTCSIP-OriginatorSid
122+
- JoinConditionList:
123+
- CaseSensitive: false
124+
CSAttribute: mail
125+
MVAttribute: mail
126+
EnablePasswordSync: false
127+
ImmutableTag:
128+
PrecedenceAfter:
129+
Name: Contoso - Inbound - UserJoin - OldAD
130+
IsLegacyCustomRule: false
131+
LinkType: Provision
132+
ConnectorName: contoso.com
133+
IsStandardRule: false
134+
TargetObjectType: person
135+
AttributeFlowMappings: []
136+
Direction: Inbound

tests/Unit/Public/Compare-DscParameterState.Tests.ps1

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,32 @@ AfterAll {
4646
Remove-Module -Name $script:moduleName
4747
}
4848

49-
Describe 'ComputerManagementDsc.Common\Compare-DscParameterState' {
49+
Describe 'DscResource.Common\Compare-DscParameterState' {
5050
BeforeAll {
5151
$verbose = $false
5252
}
5353

54+
Context 'When comparing large hashtables' {
55+
BeforeAll {
56+
$currentValues = Get-Content -Path "$PSScriptRoot/Assets/CurrentState.yml" -Raw | ConvertFrom-Yaml
57+
$desiredValues = Get-Content -Path "$PSScriptRoot/Assets/DesiredState.yml" -Raw | ConvertFrom-Yaml
58+
}
59+
60+
Context 'When all values match' {
61+
62+
It 'Should not throw exception' {
63+
{
64+
$script:result = Compare-DscParameterState -CurrentValues $currentValues -DesiredValues $desiredValues -Verbose:$verbose
65+
} | Should -Not -Throw
66+
}
67+
68+
It 'Should return null' {
69+
$script:result | Should -BeNullOrEmpty
70+
}
71+
}
72+
}
73+
74+
5475
Context 'When testing single values' {
5576
BeforeAll {
5677
$currentValues = @{

0 commit comments

Comments
 (0)