-
Notifications
You must be signed in to change notification settings - Fork 82
Computer: Remove deletion of AD computer object when using PasswordPass and UnsecuredJoin options or JoinReadOnly option #447
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
base: main
Are you sure you want to change the base?
Changes from 7 commits
fad75ab
9004dff
d15afe1
861b24a
1cf12f8
0db4bd1
f1630a9
643f5fb
06fe4cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -262,13 +262,26 @@ function Set-TargetResource | |
| $addComputerParameters.Add("Server", $Server) | ||
| } | ||
|
|
||
| # Check for existing computer objecst using ADSI without ActiveDirectory module | ||
| # Check for existing computer object using ADSI without ActiveDirectory module | ||
| $computerObject = Get-ADSIComputer -Name $Name -DomainName $DomainName -Credential $Credential | ||
|
|
||
| if ($computerObject) | ||
| { | ||
| Remove-ADSIObject -Path $computerObject.Path -Credential $Credential | ||
| Write-Verbose -Message ($script:localizedData.DeletedExistingComputerObject -f $Name, $computerObject.Path) | ||
| # UnsecuredJoin and PasswordPass options or JoinReadOnly option uses an existing machine account | ||
| # to join the computer to the domain and should not be deleted before. | ||
| if ( -not (($Options -contains 'PasswordPass' -and $options -contains 'UnsecuredJoin') -or ($Options -contains 'JoinReadOnly'))) | ||
| { | ||
| Remove-ADSIObject -Path $computerObject.Path -Credential $Credential | ||
| Write-Verbose -Message ($script:localizedData.DeletedExistingComputerObject -f $Name, $computerObject.Path) | ||
| } | ||
| } | ||
| else | ||
| { | ||
| # Check if the computer object exists in the domain when using UnsecuredJoin and PasswordPass options or JoinReadOnly option | ||
| if (($Options -contains 'PasswordPass' -and $options -contains 'UnsecuredJoin') -or ($Options -contains 'JoinReadOnly')) | ||
| { | ||
| $errorMessage = $script:localizedData.ComputerObjectNotFound -f $Name,$DomainName | ||
| New-ObjectNotFoundException -Message $errorMessage | ||
| } | ||
johlju marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
Comment on lines
265
to
285
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainAdd unit tests for both branches (found vs. not found) under the new options. 🏁 Script executed: #!/bin/bash
# Locate tests covering the new behaviors
rg -nC2 -g 'tests/**' -e "ComputerObjectNotFound|JoinReadOnly|UnsecuredJoin|PasswordPass"
# Ensure tests assert deletion behavior paths as expected
rg -nC3 -g 'tests/**' -e "DeletedExistingComputerObject|Remove-ADSIObject"Length of output: 12903 Add missing unit tests for ADSI deletion logic under the new options.
🤖 Prompt for AI AgentsThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @webalexeu can you add a unit test to handle the new code path that throws. I tried to get the AI to add it but that failed big time. 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need a unit test to cover the new code paths. |
||
|
|
||
| if (-not [System.String]::IsNullOrEmpty($Options)) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
Include JoinReadOnly and wrap long line to satisfy MD013.
The code change also covers JoinReadOnly; reflect that in the changelog. Also wrap to ≤80 chars.
📝 Committable suggestion
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
17-17: Line length
Expected: 80; Actual: 108
(MD013, line-length)
🤖 Prompt for AI Agents
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.
@webalexeu can you resolve this?
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.
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.
Rather see this resolved at the same time as a test is commited.