Fix issue when setting an empty pass to no_log param (#62804) - 2.9 (#62814)

* Fix issue when setting an empty pass to no_log param (#62804)

* Fix issue when setting an empty pass to no_log param

* Fix typo

(cherry picked from commit 322e225830)

* Fix up actual get for older versions
pull/64125/head
Jordan Borean 5 years ago committed by Matt Davis
parent 64c52e6021
commit 0d993a6b78

@ -0,0 +1,2 @@
bugfixes:
- Ansible.Basic - Fix issue when setting a ``no_log`` parameter to an empty string - https://github.com/ansible/ansible/issues/62613

@ -700,8 +700,9 @@ namespace Ansible.Basic
if ((bool)v["no_log"])
{
object noLogObject = parameters.Contains(k) ? parameters[k] : null;
if (noLogObject != null)
noLogValues.Add(noLogObject.ToString());
string noLogString = noLogObject == null ? "" : noLogObject.ToString();
if (!String.IsNullOrEmpty(noLogString))
noLogValues.Add(noLogString);
}
object removedInVersion = v["removed_in_version"];

@ -710,6 +710,48 @@ test_no_log - Invoked with:
$actual_event | Assert-DictionaryEquals -Expected $expected_event
}
"No log value with an empty string" = {
$spec = @{
options = @{
password1 = @{type = "str"; no_log = $true}
password2 = @{type = "str"; no_log = $true}
}
}
$complex_args = @{
_ansible_module_name = "test_no_log"
password1 = ""
}
$m = [Ansible.Basic.AnsibleModule]::Create(@(), $spec)
$m.Result.data = $complex_args.dict
# verify params internally aren't masked
$m.Params.password1 | Assert-Equals -Expected ""
$m.Params.password2 | Assert-Equals -Expected $null
$failed = $false
try {
$m.ExitJson()
} catch [System.Management.Automation.RuntimeException] {
$failed = $true
$_.Exception.Message | Assert-Equals -Expected "exit: 0"
$actual = [Ansible.Basic.AnsibleModule]::FromJson($_test_out)
}
$failed | Assert-Equals -Expected $true
$expected = @{
invocation = @{
module_args = @{
password1 = ""
password2 = $null
}
}
changed = $false
data = $complex_args.dict
}
$actual | Assert-DictionaryEquals -Expected $expected
}
"Removed in version" = {
$spec = @{
options = @{

Loading…
Cancel
Save