ansible-playbook -K breaks when passwords have quotes (#79837)

Now only 'unquote' when ini config file is the source
pull/80049/head
Miklos Sagi 3 years ago committed by GitHub
parent 72c59cfd98
commit b7ef2c1589
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- ansible-playbook -K breaks when passwords have quotes (https://github.com/ansible/ansible/issues/79836).

@ -143,13 +143,17 @@ def ensure_type(value, value_type, origin=None):
elif value_type in ('str', 'string'):
if isinstance(value, (string_types, AnsibleVaultEncryptedUnicode, bool, int, float, complex)):
value = unquote(to_text(value, errors='surrogate_or_strict'))
value = to_text(value, errors='surrogate_or_strict')
if origin == 'ini':
value = unquote(value)
else:
errmsg = 'string'
# defaults to string type
elif isinstance(value, (string_types, AnsibleVaultEncryptedUnicode)):
value = unquote(to_text(value, errors='surrogate_or_strict'))
value = to_text(value, errors='surrogate_or_strict')
if origin == 'ini':
value = unquote(value)
if errmsg:
raise ValueError('Invalid type provided for "%s": %s' % (errmsg, to_native(value)))

@ -65,6 +65,15 @@ ensure_test_data = [
('None', 'none', type(None))
]
ensure_unquoting_test_data = [
('"value"', '"value"', 'str', 'env'),
('"value"', '"value"', 'str', 'yaml'),
('"value"', 'value', 'str', 'ini'),
('\'value\'', 'value', 'str', 'ini'),
('\'\'value\'\'', '\'value\'', 'str', 'ini'),
('""value""', '"value"', 'str', 'ini')
]
class TestConfigManager:
@classmethod
@ -79,6 +88,11 @@ class TestConfigManager:
def test_ensure_type(self, value, expected_type, python_type):
assert isinstance(ensure_type(value, expected_type), python_type)
@pytest.mark.parametrize("value, expected_value, value_type, origin", ensure_unquoting_test_data)
def test_ensure_type_unquoting(self, value, expected_value, value_type, origin):
actual_value = ensure_type(value, value_type, origin)
assert actual_value == expected_value
def test_resolve_path(self):
assert os.path.join(curdir, 'test.yml') == resolve_path('./test.yml', cfg_file)

Loading…
Cancel
Save