-
Notifications
You must be signed in to change notification settings - Fork 141
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
xADUser: Fix CN/Path Concurrent Change and Empty String Property on Creation Exceptions #412
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #412 +/- ##
====================================
+ Coverage 92% 92% +<1%
====================================
Files 20 20
Lines 2541 2549 +8
Branches 10 10
====================================
+ Hits 2348 2356 +8
Misses 183 183
Partials 10 10 |
Was testing GitHub review tool again, just to see how far it gotten with the latest changes... sadly still to far away from Reviewable in my opinion. But I like the suggestion thing, see above. Maybe that works in reviewable to since it is just a code block with I will review in Reviewable now 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r1, 1 of 1 files at r2.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @X-Guardian)
DSCResources/MSFT_xADUser/MSFT_xADUser.psm1, line 1546 at r2 (raw file):
Quoted 9 lines of code…
elseif (([System.String]::IsNullOrEmpty($PSBoundParameters.$parameter)) -and ([System.String]::IsNullOrEmpty($targetResource.$parameter))) { # Both values are null/empty and therefore we are compliant } # Use Compare-Object to allow comparison of string and array parameters elseif (($null -ne $PSBoundParameters.$parameter -and $null -eq $targetResource.$parameter) -or ($null -eq $PSBoundParameters.$parameter -and $null -ne $targetResource.$parameter) -or (Compare-Object -ReferenceObject $PSBoundParameters.$parameter -DifferenceObject $targetResource.$parameter)) {
Instead of an empty elseif-block could we put these two evaluation together? Or maybe make a helper function to make such a comaprision? Would the helper function Test-DscPropertyState
work - or extended to work without breaking anything else? 🤔
DSCResources/MSFT_xADUser/MSFT_xADUser.psm1, line 1621 at r2 (raw file):
Quoted 5 lines of code…
# Cannot move users by updating the DistinguishedName property $adCommonParameters = Get-ADCommonParameters @PSBoundParameters # Using the SamAccountName for identity with Move-ADObject does not work, use the DN instead $adCommonParameters['Identity'] = $targetResource.DistinguishedName
These are duplicate below, could we add an if-block around these two if-blocks so we only need to specify these rows once?
Code block below is an example what I thought of, but also a test to use suggestion
to see what happens in GitHub.
if ($moveUserRequired -or $renameUserRequired)
{
# Cannot move users by updating the DistinguishedName property
$adCommonParameters = Get-ADCommonParameters @PSBoundParameters
# Using the SamAccountName for identity with Move-ADObject does not work, use the DN instead
$adCommonParameters['Identity'] = $targetResource.DistinguishedName
if ($moveUserRequired)
{
Write-Verbose -Message ($script:localizedData.MovingADUser -f $targetResource.Path, $PSBoundParameters.Path)
Move-ADObject @adCommonParameters -TargetPath $PSBoundParameters.Path
# Set new target resource DN in case a rename is also required
$targetResource.DistinguishedName = "cn=$($targetResource.CommonName),$($PSBoundParameters.Path)"
}
if ($renameUserRequired)
{
Write-Verbose -Message ($script:localizedData.RenamingADUser -f $targetResource.CommonName, $PSBoundParameters.CommonName)
Rename-ADObject @adCommonParameters -NewName $PSBoundParameters.CommonName
}
}
There was a problem hiding this 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, 3 unresolved discussions (waiting on @johlju)
DSCResources/MSFT_xADUser/MSFT_xADUser.psm1, line 1504 at r2 (raw file):
Previously, johlju (Johan Ljunggren) wrote…
$moveUserRequired = $true
Done.
DSCResources/MSFT_xADUser/MSFT_xADUser.psm1, line 1546 at r2 (raw file):
Previously, johlju (Johan Ljunggren) wrote…
elseif (([System.String]::IsNullOrEmpty($PSBoundParameters.$parameter)) -and ([System.String]::IsNullOrEmpty($targetResource.$parameter))) { # Both values are null/empty and therefore we are compliant } # Use Compare-Object to allow comparison of string and array parameters elseif (($null -ne $PSBoundParameters.$parameter -and $null -eq $targetResource.$parameter) -or ($null -eq $PSBoundParameters.$parameter -and $null -ne $targetResource.$parameter) -or (Compare-Object -ReferenceObject $PSBoundParameters.$parameter -DifferenceObject $targetResource.$parameter)) {
Instead of an empty elseif-block could we put these two evaluation together? Or maybe make a helper function to make such a comaprision? Would the helper function
Test-DscPropertyState
work - or extended to work without breaking anything else? 🤔
No, that's the problem. The Compare-Object
function can't take a Null value for its Reference or Difference objects. I looked at that helper function and it has the same problem, it would break given a Null array parameter. There is so much other code in it too, I don't want to touch it.
This is now the same code pattern as is in Test-TargetResource
.
DSCResources/MSFT_xADUser/MSFT_xADUser.psm1, line 1621 at r2 (raw file):
Previously, johlju (Johan Ljunggren) wrote…
# Cannot move users by updating the DistinguishedName property $adCommonParameters = Get-ADCommonParameters @PSBoundParameters # Using the SamAccountName for identity with Move-ADObject does not work, use the DN instead $adCommonParameters['Identity'] = $targetResource.DistinguishedName
These are duplicate below, could we add an if-block around these two if-blocks so we only need to specify these rows once?
Code block below is an example what I thought of, but also a test to use
suggestion
to see what happens in GitHub.if ($moveUserRequired -or $renameUserRequired) { # Cannot move users by updating the DistinguishedName property $adCommonParameters = Get-ADCommonParameters @PSBoundParameters # Using the SamAccountName for identity with Move-ADObject does not work, use the DN instead $adCommonParameters['Identity'] = $targetResource.DistinguishedName if ($moveUserRequired) { Write-Verbose -Message ($script:localizedData.MovingADUser -f $targetResource.Path, $PSBoundParameters.Path) Move-ADObject @adCommonParameters -TargetPath $PSBoundParameters.Path # Set new target resource DN in case a rename is also required $targetResource.DistinguishedName = "cn=$($targetResource.CommonName),$($PSBoundParameters.Path)" } if ($renameUserRequired) { Write-Verbose -Message ($script:localizedData.RenamingADUser -f $targetResource.CommonName, $PSBoundParameters.CommonName) Rename-ADObject @adCommonParameters -NewName $PSBoundParameters.CommonName } }
These are parameter sets being built to call two different functions, so shouldn't be shared. I've adjusted the variable names to make that clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r3, 1 of 1 files at r4.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @X-Guardian)
DSCResources/MSFT_xADUser/MSFT_xADUser.psm1, line 1546 at r2 (raw file):
Previously, X-Guardian (Simon Heather) wrote…
No, that's the problem. The
Compare-Object
function can't take a Null value for its Reference or Difference objects. I looked at that helper function and it has the same problem, it would break given a Null array parameter. There is so much other code in it too, I don't want to touch it.
This is now the same code pattern as is inTest-TargetResource
.
I understand. Could we add this to the comment to better explain the design choice?
There was a problem hiding this 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, 1 unresolved discussion (waiting on @johlju)
DSCResources/MSFT_xADUser/MSFT_xADUser.psm1, line 1546 at r2 (raw file):
Previously, johlju (Johan Ljunggren) wrote…
I understand. Could we add this to the comment to better explain the design choice?
Done. Added to the comments in both the Test-TargetResource
and Set-TargetResource
functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r5.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @X-Guardian)
DSCResources/MSFT_xADUser/MSFT_xADUser.psm1, line 1067 at r5 (raw file):
{ # Both values are null/empty and therefore we are compliant # Must catch this scenario separately, as Compare-Object can't compare Null objects
Can we both rows to a comment block? Same at the line 1545.
<#
Text...
#>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 1 of 2 files reviewed, 1 unresolved discussion (waiting on @johlju)
DSCResources/MSFT_xADUser/MSFT_xADUser.psm1, line 1067 at r5 (raw file):
Previously, johlju (Johan Ljunggren) wrote…
Can we both rows to a comment block? Same at the line 1545.
<# Text... #>
Done.
There was a problem hiding this 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 r6.
Reviewable status: complete! all files reviewed, all discussions resolved
Pull Request (PR) description
This PR makes the following changes to the
xADUser
resource:Set-ADUser
code and performs theMove-ADObject
before theRename-ADObject
to prevent the exception when updating CommonName and Path at the same time.This Pull Request (PR) fixes the following issues
Task list
Entry should say what was changed, and how that affects users (if applicable).
and comment-based help.
This change is