Fix onepassword lookup plugin and onepassword_facts module when a field has no name. (#58308)

* Fix onepassword lookup plugin crashing on fields with no 'name' or 't' property.

* Fix onepassword_facts module crashing on fields with no 'name' or 't' property.

* Add unit test for onepassword lookup plugin failing on entries without a name.

* Add changelog fragment for onepassword lookup plugin and onepassword_facts module fixes on fields without a name.
This commit is contained in:
Olivier Scherler 2019-06-28 18:37:14 +02:00 committed by Sam Doran
parent 1a5ae366f4
commit 7ed7d374e4
4 changed files with 11 additions and 7 deletions

View file

@ -0,0 +1,3 @@
bugfixes:
- onepassword - fix onepassword lookup plugin failing on fields without a name or t property (https://github.com/ansible/ansible/pull/58308)
- onepassword_facts - fix onepassword_facts module failing on fields without a name or t property (https://github.com/ansible/ansible/pull/58308)

View file

@ -206,7 +206,7 @@ class OnePasswordFacts(object):
else:
if section_title is None:
for field_data in data['details'].get('fields', []):
if field_data.get('name').lower() == field_name.lower():
if field_data.get('name', '').lower() == field_name.lower():
return {field_name: field_data.get('value', '')}
# Not found it yet, so now lets see if there are any sections defined
@ -216,7 +216,7 @@ class OnePasswordFacts(object):
if section_title is not None and section_title.lower() != section_data['title'].lower():
continue
for field_data in section_data.get('fields', []):
if field_data.get('t').lower() == field_name.lower():
if field_data.get('t', '').lower() == field_name.lower():
return {field_name: field_data.get('v', '')}
# We will get here if the field could not be found in any section and the item wasn't a document to be downloaded.

View file

@ -203,13 +203,13 @@ class OnePass(object):
data = json.loads(data_json)
if section_title is None:
for field_data in data['details'].get('fields', []):
if field_data.get('name').lower() == field_name.lower():
if field_data.get('name', '').lower() == field_name.lower():
return field_data.get('value', '')
for section_data in data['details'].get('sections', []):
if section_title is not None and section_title.lower() != section_data['title'].lower():
continue
for field_data in section_data.get('fields', []):
if field_data.get('t').lower() == field_name.lower():
if field_data.get('t', '').lower() == field_name.lower():
return field_data.get('v', '')
return ''

View file

@ -95,7 +95,8 @@ MOCK_ENTRIES = [
{
'name': 'password',
'value': 'vauxhall'
}
},
{},
]
}
}
@ -105,8 +106,8 @@ MOCK_ENTRIES = [
def get_mock_query_generator(require_field=None):
def _process_field(field, section_title=None):
field_name = field.get('name', field.get('t'))
field_value = field.get('value', field.get('v'))
field_name = field.get('name', field.get('t', ''))
field_value = field.get('value', field.get('v', ''))
if require_field is None or field_name == require_field:
return entry, query, section_title, field_name, field_value