Skip to content

Commit

Permalink
Merge pull request #2437 from William-Francillette/fix#2436
Browse files Browse the repository at this point in the history
Fixes #2436
  • Loading branch information
NikCharlebois authored Oct 26, 2022
2 parents 36056f2 + 63d9d47 commit f8b87d9
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,11 @@ function Test-TargetResource
$ValuesToCheck.Remove('TenantId') | Out-Null
$ValuesToCheck.Remove('ApplicationSecret') | Out-Null

if($CurrentValues.Ensure -ne $PSBoundParameters.Ensure)
{
Write-Verbose -Message "Test-TargetResource returned $false"
return $false
}
#region Assignments
$testResult=$true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,11 @@ function Test-TargetResource
$ValuesToCheck.Remove('CertificateThumbprint') | Out-Null
$ValuesToCheck.Remove('ManagedIdentity') | Out-Null

if($CurrentValues.Ensure -ne $PSBoundParameters.Ensure)
{
Write-Verbose -Message "Test-TargetResource returned $false"
return $false
}
#region Assignments
$testResult=$true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,11 @@ function Test-TargetResource
$ValuesToCheck.Remove('TenantId') | Out-Null
$ValuesToCheck.Remove('ApplicationSecret') | Out-Null

if($CurrentValues.Ensure -ne $PSBoundParameters.Ensure)
{
Write-Verbose -Message "Test-TargetResource returned $false"
return $false
}
#region Assignments
$testResult=$true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@ function Set-TargetResource

$ConnectionMode = New-M365DSCConnection -Workload 'MicrosoftGraph' `
-InboundParameters $PSBoundParameters -ProfileName beta

#Ensure the proper dependencies are installed in the current environment.
Confirm-M365DSCDependencies

Expand Down Expand Up @@ -422,6 +421,8 @@ function Set-TargetResource
Write-Verbose -Message "Creating new Intune Device Compliance MacOS Policy {$DisplayName}"
$PSBoundParameters.Remove('DisplayName') | Out-Null
$PSBoundParameters.Remove('Description') | Out-Null
$PSBoundParameters.Remove('Assignments') | Out-Null

$AdditionalProperties = Get-M365DSCIntuneDeviceCompliancePolicyMacOSAdditionalProperties -Properties ([System.Collections.Hashtable]$PSBoundParameters)
$policy=New-MgDeviceManagementDeviceCompliancePolicy -DisplayName $DisplayName `
-Description $Description `
Expand Down Expand Up @@ -640,16 +641,22 @@ function Test-TargetResource
$ValuesToCheck.Remove('TenantId') | Out-Null
$ValuesToCheck.Remove('ApplicationSecret') | Out-Null


if($CurrentValues.Ensure -ne $PSBoundParameters.Ensure)
{
Write-Verbose -Message "Test-TargetResource returned $false"
return $false
}
#region Assignments
$testResult=$true

if((-not $CurrentValues.Assignments) -xor (-not $ValuesToCheck.Assignments))
if(($null -ne $CurrentValues.Assignments) -xor ($null -ne $ValuesToCheck.Assignments))
{
Write-Verbose -Message "Configuration drift: one the assignment is null"
return $false
}

if($CurrentValues.Assignments)
if($null -ne $CurrentValues.Assignments)
{
if($CurrentValues.Assignments.count -ne $ValuesToCheck.Assignments.count)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,11 @@ function Test-TargetResource
$ValuesToCheck.Remove('TenantId') | Out-Null
$ValuesToCheck.Remove('ApplicationSecret') | Out-Null

if($CurrentValues.Ensure -ne $PSBoundParameters.Ensure)
{
Write-Verbose -Message "Test-TargetResource returned $false"
return $false
}
$testResult = $true
if (([Array]$Assignments).count -ne $CurrentValues.Assignments.count)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ function Test-TargetResource
$ValuesToCheck.Remove('ApplicationSecret') | Out-Null

#region Assignments
if($CurrentValues.Ensure -eq "Absent")
if($CurrentValues.Ensure -ne $PSBoundParameters.Ensure)
{
Write-Verbose -Message "Test-TargetResource returned $false"
return $false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ function Test-TargetResource
$CurrentValues = Get-TargetResource @PSBoundParameters
$ValuesToCheck = ([Hashtable]$PSBoundParameters).clone()

if ($CurrentValues.Ensure -eq 'Absent')
if($CurrentValues.Ensure -ne $PSBoundParameters.Ensure)
{
Write-Verbose -Message "Test-TargetResource returned $false"
return $false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ function Test-TargetResource
$CurrentValues = Get-TargetResource @PSBoundParameters
$ValuesToCheck = ([Hashtable]$PSBoundParameters).clone()

if ($CurrentValues.Ensure -eq 'Absent')
if($CurrentValues.Ensure -ne $PSBoundParameters.Ensure)
{
Write-Verbose -Message "Test-TargetResource returned $false"
return $false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,11 @@ function Test-TargetResource
$ValuesToCheck.Remove('TenantId') | Out-Null
$ValuesToCheck.Remove('ApplicationSecret') | Out-Null

if($CurrentValues.Ensure -ne $PSBoundParameters.Ensure)
{
Write-Verbose -Message "Test-TargetResource returned $false"
return $false
}
#region Assignments
$testResult=$true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ function Test-TargetResource
$CurrentValues = Get-TargetResource @PSBoundParameters
$ValuesToCheck = ([Hashtable]$PSBoundParameters).clone()

if ($CurrentValues.Ensure -eq 'Absent')
if($CurrentValues.Ensure -ne $PSBoundParameters.Ensure)
{
Write-Verbose -Message "Test-TargetResource returned $false"
return $false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3045,6 +3045,11 @@ function Test-TargetResource
}
$ValuesToCheck.Remove("DefenderDetectedMalwareActions") | Out-Null

if($CurrentValues.Ensure -ne $PSBoundParameters.Ensure)
{
Write-Verbose -Message "Test-TargetResource returned $false"
return $false
}
#region Assignments
$testResult=$true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2890,7 +2890,7 @@ function Test-TargetResource
$CurrentValues = Get-TargetResource @PSBoundParameters
$ValuesToCheck = ([Hashtable]$PSBoundParameters).clone()

if($CurrentValues.Ensure -eq "Absent")
if($CurrentValues.Ensure -ne $PSBoundParameters.Ensure)
{
Write-Verbose -Message "Test-TargetResource returned $false"
return $false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
FirewallEnabled = $False
FirewallBlockAllIncoming = $False
FirewallEnableStealthMode = $False
Assignments = @()
Ensure = 'Present'
Credential = $Credential
}
Expand Down Expand Up @@ -218,10 +219,12 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
FirewallEnabled = $False
FirewallBlockAllIncoming = $False
FirewallEnableStealthMode = $False
RoleScopeTagIds = "0"
}
}
}
Mock -CommandName Get-MgDeviceManagementDeviceCompliancePolicyAssignment -MockWith {
return @()
}
}

It "Should return true from the Test method" {
Expand Down

0 comments on commit f8b87d9

Please sign in to comment.