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

fix: changed login status to be more accurate #267

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions plugins/modules/login.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ try {
}
if (($null -ne $secPassword) -and ($skip_password_reset -eq $false)) {
$setLoginSplat.add("SecurePassword", $secPassword)
$changed = $true
}

# Login already exists
Expand All @@ -114,10 +113,15 @@ try {
$disabled = $false
$setLoginSplat.add("Enable", $true)
}
# Login needs to be modified
if (($changed -eq $true) -or ($disabled -ne $existingLogin.IsDisabled) -or ($setLoginSplat.ContainsKey("SecurePassword"))) {
if ($disabled -ne $existingLogin.IsDisabled) {
$changed = $true
}
# Login needs to be modified (or password *may* be changed)
if (($changed -eq $true) -or ($setLoginSplat.ContainsKey("SecurePassword"))) {
$output = Set-DbaLogin @setLoginSplat
$module.result.changed = $true
if (($output.PasswordChanged) -eq $true -or ($changed -eq $true)) {
$module.result.changed = $true
}
}
}
# New login
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/targets/login/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- name: Modify login
lowlydba.sqlserver.login:
default_database: "model"
password: "new_password"
enabled: true
register: result
- assert:
Expand All @@ -48,6 +49,21 @@
- result.data.IsDisabled is false
- result.data.Name == "{{ login_name }}"
- result.data.DefaultDatabase == "model"
- result.data.PasswordChanged is true

- name: Don't modify login
lowlydba.sqlserver.login:
default_database: "model"
password: "new_password"
enabled: true
register: result
- assert:
that:
- result is not changed
- result.data.PasswordChanged is false
- result.data.IsDisabled is false
- result.data.Name == "{{ login_name }}"
- result.data.DefaultDatabase == "model"

- name: Skip pwd reset
lowlydba.sqlserver.login:
Expand Down
Loading