mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +00:00
Support nested JSON decoding in AnsibleJSONDecoder (#45924)
* Support nested JSON decoding in AnsibleJSONDecoder * Add tests for vault portion of AnsibleJSONDecoder
This commit is contained in:
19
test/units/parsing/fixtures/ajson.json
Normal file
19
test/units/parsing/fixtures/ajson.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"password": {
|
||||
"__ansible_vault": "$ANSIBLE_VAULT;1.1;AES256\n34646264306632313333393636316562356435376162633631326264383934326565333633366238\n3863373264326461623132613931346165636465346337310a326434313830316337393263616439\n64653937313463396366633861363266633465663730303633323534363331316164623237363831\n3536333561393238370a313330316263373938326162386433313336613532653538376662306435\n3339\n"
|
||||
},
|
||||
"bar": {
|
||||
"baz": [
|
||||
{
|
||||
"password": {
|
||||
"__ansible_vault": "$ANSIBLE_VAULT;1.1;AES256\n34646264306632313333393636316562356435376162633631326264383934326565333633366238\n3863373264326461623132613931346165636465346337310a326434313830316337393263616439\n64653937313463396366633861363266633465663730303633323534363331316164623237363831\n3536333561393238370a313330316263373938326162386433313336613532653538376662306435\n3339\n"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"foo": {
|
||||
"password": {
|
||||
"__ansible_vault": "$ANSIBLE_VAULT;1.1;AES256\n34646264306632313333393636316562356435376162633631326264383934326565333633366238\n3863373264326461623132613931346165636465346337310a326434313830316337393263616439\n64653937313463396366633861363266633465663730303633323534363331316164623237363831\n3536333561393238370a313330316263373938326162386433313336613532653538376662306435\n3339\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
22
test/units/parsing/test_ajson.py
Normal file
22
test/units/parsing/test_ajson.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# Copyright 2018, Matt Martz <matt@sivel.net>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
from ansible.parsing.ajson import AnsibleJSONDecoder
|
||||
from ansible.parsing.yaml.objects import AnsibleVaultEncryptedUnicode
|
||||
|
||||
|
||||
def test_AnsibleJSONDecoder_vault():
|
||||
with open(os.path.join(os.path.dirname(__file__), 'fixtures/ajson.json')) as f:
|
||||
data = json.load(f, cls=AnsibleJSONDecoder)
|
||||
|
||||
assert isinstance(data['password'], AnsibleVaultEncryptedUnicode)
|
||||
assert isinstance(data['bar']['baz'][0]['password'], AnsibleVaultEncryptedUnicode)
|
||||
assert isinstance(data['foo']['password'], AnsibleVaultEncryptedUnicode)
|
||||
Reference in New Issue
Block a user