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

ADObjectPermissionEntry: Fix Exception When the Object Path Does Not Exist #555

Merged
merged 2 commits into from
Feb 5, 2020

Conversation

oliveirt
Copy link
Contributor

@oliveirt oliveirt commented Feb 3, 2020

Pull Request (PR) description

Fixes issue with ADObjectPermissionEntry resource, where unable to run Get-DscConfiguration or Test-DscConfiguration where the object path of the associated AD resource (on which the PermissionEntry is defined) doesn't exist yet.

This Pull Request (PR) fixes the following issues


This change is Reviewable

@X-Guardian
Copy link
Contributor

Hi @oliveirt, this PR still contains the changes for both resources. If you need help setting this up, message me on the PowerShell Slack channel: http://slack.poshcode.org.

@oliveirt
Copy link
Contributor Author

oliveirt commented Feb 4, 2020 via email

@johlju johlju added the needs review The pull request needs a code review. label Feb 4, 2020
Copy link
Contributor

@X-Guardian X-Guardian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 4 files at r1.
Reviewable status: 2 of 4 files reviewed, 2 unresolved discussions (waiting on @oliveirt)


source/DSCResources/MSFT_ADObjectPermissionEntry/MSFT_ADObjectPermissionEntry.psm1, line 95 at r1 (raw file):

    }

    foreach ($access in $acl.Access)

Can we improve this function further by adding an if/else block around this foreachblock to check if the $acl variable is $true, move the ObjectPermissionEntryNotFound verbose message into the else block and then only have one return $returnValue?


Tests/Unit/MSFT_ADObjectPermissionEntry.Tests.ps1, line 160 at r1 (raw file):

                Mock -CommandName 'Get-Acl' -MockWith { throw New-Object System.Management.Automation.ItemNotFoundException }

                It 'Should return a valid result if the AD object path is absent and not throw an exception' {

Can we change this to 'Should return a valid result if the AD object path is absent'? No need to say 'not throw an exception'.

@X-Guardian X-Guardian changed the title ADObjectPermissionEntry: Fixes #552 ADObjectPermissionEntry: Fix Exception When the Object Path Does Not Exist Feb 4, 2020
Copy link
Contributor Author

@oliveirt oliveirt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 2 of 4 files reviewed, 2 unresolved discussions (waiting on @oliveirt and @X-Guardian)


source/DSCResources/MSFT_ADObjectPermissionEntry/MSFT_ADObjectPermissionEntry.psm1, line 95 at r1 (raw file):

ObjectPermissionEntryNotFound
I think it is OK as it is. If the acl is null then will not enter the foreach block. The first return statement on 114 returns the ace if found, whereas the one on 121 returns the absent ace as defined on line 70.

Copy link
Contributor

@X-Guardian X-Guardian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 2 of 4 files reviewed, 2 unresolved discussions (waiting on @oliveirt)


source/DSCResources/MSFT_ADObjectPermissionEntry/MSFT_ADObjectPermissionEntry.psm1, line 95 at r1 (raw file):

Previously, oliveirt (Tony Oliveira) wrote…

ObjectPermissionEntryNotFound
I think it is OK as it is. If the acl is null then will not enter the foreach block. The first return statement on 114 returns the ace if found, whereas the one on 121 returns the absent ace as defined on line 70.

Yes, technically the code works, but performing a Foreach loop on the property of an object that doesn't even exist and having two exit points on the function are not good programming practice, so lets take the opportunity to clean this up.

Copy link
Contributor

@X-Guardian X-Guardian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r2.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved


Tests/Unit/MSFT_ADObjectPermissionEntry.Tests.ps1, line 160 at r1 (raw file):

Previously, X-Guardian (Simon Heather) wrote…

Can we change this to 'Should return a valid result if the AD object path is absent'? No need to say 'not throw an exception'.

Done

@X-Guardian
Copy link
Contributor

Many thanks for this @oliveirt.

If you are in the mood for doing another PR, this resource could really do with some integration tests... #353.

@X-Guardian X-Guardian merged commit 5290f55 into dsccommunity:master Feb 5, 2020
@X-Guardian X-Guardian removed the needs review The pull request needs a code review. label Feb 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ADObjectPermissionEntry: throws an exception when target path does not yet exist
3 participants