Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveDirectoryDsc.Common: Test-DscPropertyState Fails Comparing $Null and Arrays #513

Closed
X-Guardian opened this issue Oct 2, 2019 · 0 comments · Fixed by #514
Closed
Labels
bug The issue is a bug.

Comments

@X-Guardian
Copy link
Contributor

Details of the scenario you tried and the problem that is occurring

The Test-DscPropertyState function in the ActiveDirectoryDsc.Common module raises an exception in the following scenarios:

  • When evaluating an array, but the current value is $null
  • When evaluating an array, when both values are $null

This is because $null does not have a Get-Type() method and Compare-Object can't take $null as an input.

Verbose logs showing the problem

[-] Should return false when evaluating an array, but the desired value is $null 2ms
        RuntimeException: You cannot call a method on a null-valued expression.
        at Test-DscPropertyState, \\nas01\data\users\simon\documents\GitHub\X-Guardian\ActiveDirectoryDsc\Modules\ActiveDirectoryDsc.Common\ActiveDirectoryDsc.Common.psm1: line 1806
[-] Should return true when evaluating an array, when both values are $null 3ms
        RuntimeException: You cannot call a method on a null-valued expression.
        at Test-DscPropertyState, \\nas01\data\users\simon\documents\GitHub\X-Guardian\ActiveDirectoryDsc\Modules\ActiveDirectoryDsc.Common\ActiveDirectoryDsc.Common.psm1: line 1804

Suggested solution to the issue

Add code to Test-DscPropertyState to check $Values.CurrentValue and $Values.DesiredValues against $null.

New Pester Tests Showing the Issues

It 'Should return false when evaluating an array, but the desired value is an empty array' {
    $mockValues = @{
        CurrentValue = @('1','2')
        DesiredValue = @()
    }

    Test-DscPropertyState -Values $mockValues | Should -BeFalse
}

It 'Should return true when evaluating an array, when both values are $null' {
    $mockValues = @{
        CurrentValue = $null
        DesiredValue = $null
    }

    Test-DscPropertyState -Values $mockValues -Verbose | Should -BeTrue
}

The operating system the target node is running

OsName               : Microsoft Windows 10 Pro
OsOperatingSystemSKU : 48
OsArchitecture       : 64-bit
WindowsVersion       : 1903
WindowsBuildLabEx    : 18362.1.amd64fre.19h1_release.190318-1202
OsLanguage           : en-GB
OsMuiLanguages       : {en-GB, en-US, th-TH}

Version and build of PowerShell the target node is running

PSVersion                      5.1.18362.145
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.18362.145
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Version of the DSC module that was used ('dev' if using current dev branch)

dev

@johlju johlju added bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community. labels Oct 5, 2019
johlju pushed a commit that referenced this issue Oct 9, 2019
…paring $Null and Arrays (#514)

- Changes to ActiveDirectoryDsc.Common
  - Fix `Test-DscPropertyState` Failing when Comparing $Null and Arrays (issue #513).
@johlju johlju removed the help wanted The issue is up for grabs for anyone in the community. label Jan 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug.
Projects
None yet
2 participants