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
This commit is contained in:
Jordan Borean 2019-09-24 21:45:53 -04:00 committed by GitHub
parent 1b3bf33bdf
commit 322e225830
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 2 deletions

View file

@ -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

View file

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

View file

@ -710,6 +710,48 @@ test_no_log - Invoked with:
$actual_event | Assert-DictionaryEquals -Expected $expected_event $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($_.Exception.InnerException.Output)
}
$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" = { "Removed in version" = {
$spec = @{ $spec = @{
options = @{ options = @{