Skip to content

xADObjectPermissionEntry: Fix failure when applied in the same configuration as xADDomain #299

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

Merged
merged 14 commits into from
May 31, 2019
Merged

xADObjectPermissionEntry: Fix failure when applied in the same configuration as xADDomain #299

merged 14 commits into from
May 31, 2019

Conversation

X-Guardian
Copy link
Contributor

@X-Guardian X-Guardian commented May 28, 2019

Pull Request (PR) description

This PR fixes the failure when an xADObjectPermissionEntry resource is applied in the same configuration as a new xADDomain resource is created. This is achieved using a new common function Assert-ADPSDrive which checks if an AD PSDrive exists, and creates one if it is missing.

The verbose messages have also been localized and improved and the synopsis text standardized to use permission instead of access.

Old verbose messages:

VERBOSE: [DCTEST02]: LCM:  [ Start  Resource ]  [[xADObjectPermissionEntry]Permission]
VERBOSE: [DCTEST02]: LCM:  [ Start  Test     ]  [[xADObjectPermissionEntry]Permission]
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has not been found
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Target ace has been found
VERBOSE: [DCTEST02]: LCM:  [ End    Test     ]  [[xADObjectPermissionEntry]Permission]  in 0.8440 seconds.
VERBOSE: [DCTEST02]: LCM:  [ Skip   Set      ]  [[xADObjectPermissionEntry]Permission]
VERBOSE: [DCTEST02]: LCM:  [ End    Resource ]  [[xADObjectPermissionEntry]Permission]

New verbose messages:

VERBOSE: [DCTEST02]: LCM:  [ Start  Resource ]  [[xADObjectPermissionEntry]Permission]
VERBOSE: [DCTEST02]: LCM:  [ Start  Test     ]  [[xADObjectPermissionEntry]Permission]
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Object permission entry not found on object 'DC=contoso,DC=com'. (OPE0002)
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Object permission entry on object 'DC=contoso,DC=com' is not in the desired state. (OPE0006)
VERBOSE: [DCTEST02]: LCM:  [ End    Test     ]  [[xADObjectPermissionEntry]Permission]  in 0.2340 seconds.
VERBOSE: [DCTEST02]: LCM:  [ Start  Set      ]  [[xADObjectPermissionEntry]Permission]
VERBOSE: [DCTEST02]:                            [[xADObjectPermissionEntry]Permission] Adding object permission entry to object 'DC=contoso,DC=com'. (OPE0003)
VERBOSE: [DCTEST02]: LCM:  [ End    Set      ]  [[xADObjectPermissionEntry]Permission]  in 0.2810 seconds.
VERBOSE: [DCTEST02]: LCM:  [ End    Resource ]  [[xADObjectPermissionEntry]Permission]

This Pull Request (PR) fixes the following issues

Task list

  • Added an entry under the Unreleased section in the CHANGELOG.md.
    Entry should say what was changed, and how that affects users (if applicable).
  • Resource documentation added/updated in README.md.
  • Resource parameter descriptions added/updated in README.md, schema.mof
    and comment-based help.
  • Comment-based help added/updated.
  • Localization strings added/updated in all localization files as appropriate.
  • Examples appropriately added/updated.
  • Unit tests added/updated. See DSC Resource Testing Guidelines.
  • Integration tests added/updated (where possible). See DSC Resource Testing Guidelines.
  • New/changed code adheres to DSC Resource Style Guidelines and Best Practices.

This change is Reviewable

X-Guardian and others added 3 commits May 28, 2019 22:29
- Import MSFT_xADCommon module
- Localize and improve verbose messages
- standardise synopsis permission text
- Add Assert-ADSPDrive function calls
@codecov-io
Copy link

codecov-io commented May 28, 2019

Codecov Report

Merging #299 into dev will increase coverage by <1%.
The diff coverage is 100%.

Impacted file tree graph

@@         Coverage Diff          @@
##            dev   #299    +/-   ##
====================================
+ Coverage    90%    90%   +<1%     
====================================
  Files        20     20            
  Lines      2224   2238    +14     
  Branches     10     10            
====================================
+ Hits       2011   2026    +15     
+ Misses      203    202     -1     
  Partials     10     10

- Add Assert-ADPSDrive function mocks
- Add Assert-ADPSDrive MockCalled tests
- Fix context name typo
@johlju johlju added the waiting for author response The pull request is waiting for the author to respond to comments in the pull request. label May 30, 2019
@johlju
Copy link
Member

johlju commented May 30, 2019

@X-Guardian Thanks for sending this in and fixing the verbose messages!

Waiting for more input in the issue #296 to make sure that we actually need to assert that AD drive is present, but instead that the RSAT-AD-PowerShell should be required.

I will review after we come to a conclusion there.

@X-Guardian X-Guardian changed the title [WIP] xADObjectPermissionEntry: Fix failure when applied in the same configuration as xADDomain xADObjectPermissionEntry: Fix failure when applied in the same configuration as xADDomain May 30, 2019
@johlju johlju added needs review The pull request needs a code review. and removed waiting for author response The pull request is waiting for the author to respond to comments in the pull request. labels May 31, 2019
Copy link
Member

@johlju johlju left a comment

Choose a reason for hiding this comment

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

Great work on this! Just minor review comments. 😃

Reviewed 3 of 3 files at r1, 2 of 2 files at r3, 1 of 1 files at r4, 1 of 1 files at r5.
Reviewable status: all files reviewed, 10 unresolved discussions (waiting on @X-Guardian)


DSCResources/MSFT_xADCommon/MSFT_xADCommon.psm1, line 1325 at r4 (raw file):

Function

function (lower-case 'f')


DSCResources/MSFT_xADCommon/MSFT_xADCommon.psm1, line 1339 at r4 (raw file):

Get-PSDrive -Name AD -ErrorAction Stop | Out-Null

Instead evaluate this with a try-catch block, could we evaluate this with an if-block instead?

$activeDirectoryPSDrive = Get-PSDrive -Name 'AD' -ErrorAction 'SilentlyContinue'

if ($null -eq $activeDirectoryPSDrive)
{
    # New-PSDrive...
}

I think it's more intuitive to use an if-block here instead of a try-catch block. I think we should use try-catch block when want the throw an error to the user (there are exceptions though, but not seeing this one as those).


DSCResources/MSFT_xADCommon/MSFT_xADCommon.psm1, line 1341 at r4 (raw file):

Catch

catch (lower-case 'c'). Throughout.


DSCResources/MSFT_xADCommon/MSFT_xADCommon.psm1, line 1344 at r4 (raw file):

Try

try (lower-case 't'). Throughout.


Tests/Unit/MSFT_xADCommon.Tests.ps1, line 1450 at r4 (raw file):

-MockWith { }

We can remove this when there a no code to mock. Throughout (thoughout as in you only have to fix the code you added 🙂 We can clean up the rest of the test in another PR).


Tests/Unit/MSFT_xADCommon.Tests.ps1, line 1453 at r4 (raw file):

Throw

throw (lower-case 't')


Tests/Unit/MSFT_xADCommon.Tests.ps1, line 1476 at r4 (raw file):

Mock -CommandName New-InvalidOperationException -MockWith { }

We should not need this mock, see next comment.


Tests/Unit/MSFT_xADCommon.Tests.ps1, line 1478 at r4 (raw file):

{ Assert-ADPSDrive } | Should Not Throw

We should assert that it actually throws the correct error inside an It-block.

It 'Should throw the correct error' {
    { Assert-ADPSDrive } | Should -Throw $script:localizedString.CreatingNewADPSDriveError
}

The $script:localizedString.CreatingNewADPSDriveError will (should) be available automatically once the test runs (because we run the test inside`InModuelScope').


Tests/Unit/MSFT_xADCommon.Tests.ps1, line 1494 at r4 (raw file):

Quoted 4 lines of code…
                It 'Should call New-InvalidOperationException once' {

                    Assert-MockCalled -CommandName New-InvalidOperationException -Exactly -Times 1 -Scope Context
                }

Should not be needed, see comment above.


Tests/Unit/MSFT_xADCommon.Tests.ps1, line 1502 at r4 (raw file):

Assert-ADPSDrive

We should have this inside an It-block to so Pester can correctly handle unexpected errors.

                It 'Should not throw' {
                    { Assert-ADPSDrive } | Should -Not -Throw
                }

@johlju johlju added waiting for code fix A review left open comments, and the pull request is waiting for changes to be pushed by the author. and removed needs review The pull request needs a code review. labels May 31, 2019
Copy link
Contributor Author

@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: all files reviewed, 10 unresolved discussions (waiting on @johlju)


DSCResources/MSFT_xADCommon/MSFT_xADCommon.psm1, line 1325 at r4 (raw file):

Previously, johlju (Johan Ljunggren) wrote…
Function

function (lower-case 'f')

Done.


DSCResources/MSFT_xADCommon/MSFT_xADCommon.psm1, line 1339 at r4 (raw file):

Previously, johlju (Johan Ljunggren) wrote…
Get-PSDrive -Name AD -ErrorAction Stop | Out-Null

Instead evaluate this with a try-catch block, could we evaluate this with an if-block instead?

$activeDirectoryPSDrive = Get-PSDrive -Name 'AD' -ErrorAction 'SilentlyContinue'

if ($null -eq $activeDirectoryPSDrive)
{
    # New-PSDrive...
}

I think it's more intuitive to use an if-block here instead of a try-catch block. I think we should use try-catch block when want the throw an error to the user (there are exceptions though, but not seeing this one as those).

Done.


DSCResources/MSFT_xADCommon/MSFT_xADCommon.psm1, line 1341 at r4 (raw file):

Previously, johlju (Johan Ljunggren) wrote…
Catch

catch (lower-case 'c'). Throughout.

Done.


DSCResources/MSFT_xADCommon/MSFT_xADCommon.psm1, line 1344 at r4 (raw file):

Previously, johlju (Johan Ljunggren) wrote…
Try

try (lower-case 't'). Throughout.

Done.


Tests/Unit/MSFT_xADCommon.Tests.ps1, line 1450 at r4 (raw file):

Previously, johlju (Johan Ljunggren) wrote…
-MockWith { }

We can remove this when there a no code to mock. Throughout (thoughout as in you only have to fix the code you added 🙂 We can clean up the rest of the test in another PR).

Done.


Tests/Unit/MSFT_xADCommon.Tests.ps1, line 1453 at r4 (raw file):

Previously, johlju (Johan Ljunggren) wrote…
Throw

throw (lower-case 't')

Done.


Tests/Unit/MSFT_xADCommon.Tests.ps1, line 1476 at r4 (raw file):

Previously, johlju (Johan Ljunggren) wrote…
Mock -CommandName New-InvalidOperationException -MockWith { }

We should not need this mock, see next comment.

Done.


Tests/Unit/MSFT_xADCommon.Tests.ps1, line 1478 at r4 (raw file):

Previously, johlju (Johan Ljunggren) wrote…
{ Assert-ADPSDrive } | Should Not Throw

We should assert that it actually throws the correct error inside an It-block.

It 'Should throw the correct error' {
    { Assert-ADPSDrive } | Should -Throw $script:localizedString.CreatingNewADPSDriveError
}

The $script:localizedString.CreatingNewADPSDriveError will (should) be available automatically once the test runs (because we run the test inside`InModuelScope').

Done. (I didn't know you could do this. Very good!)


Tests/Unit/MSFT_xADCommon.Tests.ps1, line 1494 at r4 (raw file):

Previously, johlju (Johan Ljunggren) wrote…
                It 'Should call New-InvalidOperationException once' {

                    Assert-MockCalled -CommandName New-InvalidOperationException -Exactly -Times 1 -Scope Context
                }

Should not be needed, see comment above.

Done.


Tests/Unit/MSFT_xADCommon.Tests.ps1, line 1502 at r4 (raw file):

Previously, johlju (Johan Ljunggren) wrote…
Assert-ADPSDrive

We should have this inside an It-block to so Pester can correctly handle unexpected errors.

                It 'Should not throw' {
                    { Assert-ADPSDrive } | Should -Not -Throw
                }

Done.

@johlju johlju added needs review The pull request needs a code review. and removed waiting for code fix A review left open comments, and the pull request is waiting for changes to be pushed by the author. labels May 31, 2019
Copy link
Member

@johlju johlju left a comment

Choose a reason for hiding this comment

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

:lgtm:

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


Tests/Unit/MSFT_xADCommon.Tests.ps1, line 1478 at r4 (raw file):

Previously, X-Guardian (Simon Heather) wrote…

Done. (I didn't know you could do this. Very good!)

One never stops learning. Happy I could teach something. 😄 It's the most fun with this work! 🙂

@johlju johlju merged commit f90bd1d into dsccommunity:dev May 31, 2019
@johlju johlju removed the needs review The pull request needs a code review. label May 31, 2019
@johlju
Copy link
Member

johlju commented May 31, 2019

Merged! Thank you @X-Guardian! 🙂

@X-Guardian X-Guardian deleted the xADObjectPermissionEntry-ADDrive-Fix branch May 31, 2019 15:50
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.

xADObjectPermissionEntry: Fails when applied in the same configuration as xADDomain
3 participants