mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[PR #7919/6088e2dc backport][stable-7] fixes #7918 - onepassword lookup fails if field name contains uppercase letters and section is specified (#7974)
fixes #7918 - onepassword lookup fails if field name contains uppercase letters and section is specified (#7919)
* fix #7918
* Update plugins/lookup/onepassword.py
Co-authored-by: Sam Doran <github@samdoran.com>
* onepassword lookup: transform field ids to lowercase
* #7918: added unit tests
* #7919: add changelog fragment
* Update changelogs/fragments/7919-onepassword-fieldname-casing.yaml
Co-authored-by: Felix Fontein <felix@fontein.de>
---------
Co-authored-by: Sam Doran <github@samdoran.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 6088e2dc0f
)
Co-authored-by: Benjamin Mitzkus <b.mitzkus@gmx.de>
This commit is contained in:
parent
351eb7292c
commit
84320bacb2
5 changed files with 277 additions and 2 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- onepassword lookup plugin - failed for fields that were in sections and had uppercase letters in the label/ID. Field lookups are now case insensitive in all cases (https://github.com/ansible-collections/community.general/pull/7919).
|
|
@ -512,10 +512,10 @@ class OnePassCLIv2(OnePassCLIBase):
|
||||||
current_section_title = section.get("label", section.get("id", "")).lower()
|
current_section_title = section.get("label", section.get("id", "")).lower()
|
||||||
if section_title == current_section_title:
|
if section_title == current_section_title:
|
||||||
# In the correct section. Check "label" then "id" for the desired field_name
|
# In the correct section. Check "label" then "id" for the desired field_name
|
||||||
if field.get("label") == field_name:
|
if field.get("label", "").lower() == field_name:
|
||||||
return field.get("value", "")
|
return field.get("value", "")
|
||||||
|
|
||||||
if field.get("id") == field_name:
|
if field.get("id", "").lower() == field_name:
|
||||||
return field.get("value", "")
|
return field.get("value", "")
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
|
@ -123,5 +123,173 @@ MOCK_ENTRIES = {
|
||||||
"expected": [""],
|
"expected": [""],
|
||||||
"output": load_file("v2_out_04.json")
|
"output": load_file("v2_out_04.json")
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
# Query item without section by lowercase id (case matching)
|
||||||
|
"vault_name": "Test Vault",
|
||||||
|
"queries": ["LabelCasing"],
|
||||||
|
"kwargs": {
|
||||||
|
"field": "lowercaseid",
|
||||||
|
},
|
||||||
|
"expected": ["lowercaseid"],
|
||||||
|
"output": load_file("v2_out_05.json")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
# Query item without section by lowercase id (case not matching)
|
||||||
|
"vault_name": "Test Vault",
|
||||||
|
"queries": ["LabelCasing"],
|
||||||
|
"kwargs": {
|
||||||
|
"field": "LOWERCASEID",
|
||||||
|
},
|
||||||
|
"expected": ["lowercaseid"],
|
||||||
|
"output": load_file("v2_out_05.json")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
# Query item without section by lowercase label (case matching)
|
||||||
|
"vault_name": "Test Vault",
|
||||||
|
"queries": ["LabelCasing"],
|
||||||
|
"kwargs": {
|
||||||
|
"field": "lowercaselabel",
|
||||||
|
},
|
||||||
|
"expected": ["lowercaselabel"],
|
||||||
|
"output": load_file("v2_out_05.json")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
# Query item without section by lowercase label (case not matching)
|
||||||
|
"vault_name": "Test Vault",
|
||||||
|
"queries": ["LabelCasing"],
|
||||||
|
"kwargs": {
|
||||||
|
"field": "LOWERCASELABEL",
|
||||||
|
},
|
||||||
|
"expected": ["lowercaselabel"],
|
||||||
|
"output": load_file("v2_out_05.json")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
# Query item without section by mixed case id (case matching)
|
||||||
|
"vault_name": "Test Vault",
|
||||||
|
"queries": ["LabelCasing"],
|
||||||
|
"kwargs": {
|
||||||
|
"field": "MiXeDcAsEiD",
|
||||||
|
},
|
||||||
|
"expected": ["mixedcaseid"],
|
||||||
|
"output": load_file("v2_out_05.json")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
# Query item without section by mixed case id (case not matching)
|
||||||
|
"vault_name": "Test Vault",
|
||||||
|
"queries": ["LabelCasing"],
|
||||||
|
"kwargs": {
|
||||||
|
"field": "mixedcaseid",
|
||||||
|
},
|
||||||
|
"expected": ["mixedcaseid"],
|
||||||
|
"output": load_file("v2_out_05.json")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
# Query item without section by mixed case label (case matching)
|
||||||
|
"vault_name": "Test Vault",
|
||||||
|
"queries": ["LabelCasing"],
|
||||||
|
"kwargs": {
|
||||||
|
"field": "MiXeDcAsElAbEl",
|
||||||
|
},
|
||||||
|
"expected": ["mixedcaselabel"],
|
||||||
|
"output": load_file("v2_out_05.json")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
# Query item without section by mixed case label (case not matching)
|
||||||
|
"vault_name": "Test Vault",
|
||||||
|
"queries": ["LabelCasing"],
|
||||||
|
"kwargs": {
|
||||||
|
"field": "mixedcaselabel",
|
||||||
|
},
|
||||||
|
"expected": ["mixedcaselabel"],
|
||||||
|
"output": load_file("v2_out_05.json")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
# Query item with section by lowercase id (case matching)
|
||||||
|
"vault_name": "Test Vault",
|
||||||
|
"queries": ["LabelCasing"],
|
||||||
|
"kwargs": {
|
||||||
|
"field": "sectionlowercaseid",
|
||||||
|
"section": "section-with-values",
|
||||||
|
},
|
||||||
|
"expected": ["sectionlowercaseid"],
|
||||||
|
"output": load_file("v2_out_05.json")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
# Query item with section by lowercase id (case not matching)
|
||||||
|
"vault_name": "Test Vault",
|
||||||
|
"queries": ["LabelCasing"],
|
||||||
|
"kwargs": {
|
||||||
|
"field": "SECTIONLOWERCASEID",
|
||||||
|
"section": "section-with-values",
|
||||||
|
},
|
||||||
|
"expected": ["sectionlowercaseid"],
|
||||||
|
"output": load_file("v2_out_05.json")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
# Query item with section by lowercase label (case matching)
|
||||||
|
"vault_name": "Test Vault",
|
||||||
|
"queries": ["LabelCasing"],
|
||||||
|
"kwargs": {
|
||||||
|
"field": "sectionlowercaselabel",
|
||||||
|
"section": "section-with-values",
|
||||||
|
},
|
||||||
|
"expected": ["sectionlowercaselabel"],
|
||||||
|
"output": load_file("v2_out_05.json")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
# Query item with section by lowercase label (case not matching)
|
||||||
|
"vault_name": "Test Vault",
|
||||||
|
"queries": ["LabelCasing"],
|
||||||
|
"kwargs": {
|
||||||
|
"field": "SECTIONLOWERCASELABEL",
|
||||||
|
"section": "section-with-values",
|
||||||
|
},
|
||||||
|
"expected": ["sectionlowercaselabel"],
|
||||||
|
"output": load_file("v2_out_05.json")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
# Query item with section by lowercase id (case matching)
|
||||||
|
"vault_name": "Test Vault",
|
||||||
|
"queries": ["LabelCasing"],
|
||||||
|
"kwargs": {
|
||||||
|
"field": "SeCtIoNmIxEdCaSeId",
|
||||||
|
"section": "section-with-values",
|
||||||
|
},
|
||||||
|
"expected": ["sectionmixedcaseid"],
|
||||||
|
"output": load_file("v2_out_05.json")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
# Query item with section by lowercase id (case not matching)
|
||||||
|
"vault_name": "Test Vault",
|
||||||
|
"queries": ["LabelCasing"],
|
||||||
|
"kwargs": {
|
||||||
|
"field": "sectionmixedcaseid",
|
||||||
|
"section": "section-with-values",
|
||||||
|
},
|
||||||
|
"expected": ["sectionmixedcaseid"],
|
||||||
|
"output": load_file("v2_out_05.json")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
# Query item with section by lowercase label (case matching)
|
||||||
|
"vault_name": "Test Vault",
|
||||||
|
"queries": ["LabelCasing"],
|
||||||
|
"kwargs": {
|
||||||
|
"field": "SeCtIoNmIxEdCaSeLaBeL",
|
||||||
|
"section": "section-with-values",
|
||||||
|
},
|
||||||
|
"expected": ["sectionmixedcaselabel"],
|
||||||
|
"output": load_file("v2_out_05.json")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
# Query item with section by lowercase label (case not matching)
|
||||||
|
"vault_name": "Test Vault",
|
||||||
|
"queries": ["LabelCasing"],
|
||||||
|
"kwargs": {
|
||||||
|
"field": "sectionmixedcaselabel",
|
||||||
|
"section": "section-with-values",
|
||||||
|
},
|
||||||
|
"expected": ["sectionmixedcaselabel"],
|
||||||
|
"output": load_file("v2_out_05.json")
|
||||||
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
102
tests/unit/plugins/lookup/onepassword_fixtures/v2_out_05.json
Normal file
102
tests/unit/plugins/lookup/onepassword_fixtures/v2_out_05.json
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
{
|
||||||
|
"id": "bgqegp3xcxnpfkb45olwigpkpi",
|
||||||
|
"title": "LabelCasing",
|
||||||
|
"version": 1,
|
||||||
|
"vault": {
|
||||||
|
"id": "stpebbaccrq72xulgouxsk4p7y",
|
||||||
|
"name": "Private"
|
||||||
|
},
|
||||||
|
"category": "LOGIN",
|
||||||
|
"last_edited_by": "WOUTERRUYBH7BFPHMZ2KKGL6AU",
|
||||||
|
"created_at": "2023-09-12T08:30:07Z",
|
||||||
|
"updated_at": "2023-09-12T08:30:07Z",
|
||||||
|
"additional_information": "fluxility",
|
||||||
|
"sections": [
|
||||||
|
{
|
||||||
|
"id": "7osqcvd43i75teocdzbb6d7mie",
|
||||||
|
"label": "section-with-values"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"id": "lowercaseid",
|
||||||
|
"type": "STRING",
|
||||||
|
"purpose": "USERNAME",
|
||||||
|
"label": "label0",
|
||||||
|
"value": "lowercaseid",
|
||||||
|
"reference": "op://Testcase/LabelCasing/lowercase"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "MiXeDcAsEiD",
|
||||||
|
"type": "STRING",
|
||||||
|
"purpose": "USERNAME",
|
||||||
|
"label": "label1",
|
||||||
|
"value": "mixedcaseid",
|
||||||
|
"reference": "op://Testcase/LabelCasing/lowercase"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "id1",
|
||||||
|
"type": "STRING",
|
||||||
|
"purpose": "USERNAME",
|
||||||
|
"label": "lowercaselabel",
|
||||||
|
"value": "lowercaselabel",
|
||||||
|
"reference": "op://Testcase/LabelCasing/lowercase"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "id2",
|
||||||
|
"type": "STRING",
|
||||||
|
"purpose": "USERNAME",
|
||||||
|
"label": "MiXeDcAsElAbEl",
|
||||||
|
"value": "mixedcaselabel",
|
||||||
|
"reference": "op://Testcase/LabelCasing/lowercase"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "sectionlowercaseid",
|
||||||
|
"type": "STRING",
|
||||||
|
"purpose": "USERNAME",
|
||||||
|
"label": "label2",
|
||||||
|
"value": "sectionlowercaseid",
|
||||||
|
"reference": "op://Testcase/LabelCasing/lowercase",
|
||||||
|
"section": {
|
||||||
|
"id": "7osqcvd43i75teocdzbb6d7mie",
|
||||||
|
"label": "section-with-values"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "SeCtIoNmIxEdCaSeId",
|
||||||
|
"type": "STRING",
|
||||||
|
"purpose": "USERNAME",
|
||||||
|
"label": "label3",
|
||||||
|
"value": "sectionmixedcaseid",
|
||||||
|
"reference": "op://Testcase/LabelCasing/lowercase",
|
||||||
|
"section": {
|
||||||
|
"id": "7osqcvd43i75teocdzbb6d7mie",
|
||||||
|
"label": "section-with-values"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "id3",
|
||||||
|
"type": "STRING",
|
||||||
|
"purpose": "USERNAME",
|
||||||
|
"label": "sectionlowercaselabel",
|
||||||
|
"value": "sectionlowercaselabel",
|
||||||
|
"reference": "op://Testcase/LabelCasing/lowercase",
|
||||||
|
"section": {
|
||||||
|
"id": "7osqcvd43i75teocdzbb6d7mie",
|
||||||
|
"label": "section-with-values"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "id2",
|
||||||
|
"type": "STRING",
|
||||||
|
"purpose": "USERNAME",
|
||||||
|
"label": "SeCtIoNmIxEdCaSeLaBeL",
|
||||||
|
"value": "sectionmixedcaselabel",
|
||||||
|
"reference": "op://Testcase/LabelCasing/lowercase",
|
||||||
|
"section": {
|
||||||
|
"id": "7osqcvd43i75teocdzbb6d7mie",
|
||||||
|
"label": "section-with-values"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
SPDX-FileCopyrightText: 2022, Ansible Project
|
Loading…
Reference in a new issue