Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix namespace value with newer requests #310

Merged
merged 3 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/309-stringify-namespace.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- connection options - the ``namespace`` connection option will be forced into a string to ensure cmpatibility with recent ``requests`` versions (https://github.com/ansible-collections/community.hashi_vault/issues/309).
5 changes: 3 additions & 2 deletions plugins/module_utils/_hashi_vault_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ class HashiVaultValueError(ValueError):

class HashiVaultHelper():

STRINGIFY_CANDIDATES = set(
STRINGIFY_CANDIDATES = set([
'token', # Token will end up in a header, requests requires headers to be str or bytes,
# and newer versions of requests stopped converting automatically. Because our
# token could have been passed in from a previous lookup call, it could be one
# of the AnsibleUnsafe types instead, causing a failure. Tokens should always
# be strings, so we will convert them.
)
'namespace', # namespace is also set in a header
])

def __init__(self):
# TODO move hvac checking here?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def option_dict():


@pytest.fixture(params=[AnsibleUnsafeBytes(b'ub_opaque'), AnsibleUnsafeText(u'ut_opaque'), b'b_opaque', u't_opaque'])
def token(request):
def stringy(request):
return request.param


Expand All @@ -39,9 +39,8 @@ def auth_token(adapter, warner, deprecator):


class TestAuthToken(object):

def test_auth_token_unsafes(self, auth_token, client, adapter, token):
adapter.set_option('token', token)
def test_auth_token_unsafes(self, auth_token, client, adapter, stringy):
adapter.set_option('token', stringy)
adapter.set_option('token_validate', False)

wrapper = mock.Mock(wraps=auth_token._stringify)
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/plugins/plugin_utils/test_hashi_vault_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import pytest

from ansible.utils.unsafe_proxy import AnsibleUnsafe, AnsibleUnsafeBytes, AnsibleUnsafeText
from ansible.utils.unsafe_proxy import AnsibleUnsafeBytes, AnsibleUnsafeText

from ansible_collections.community.hashi_vault.tests.unit.compat import mock
from ansible_collections.community.hashi_vault.plugins.module_utils._hashi_vault_common import HashiVaultHelper
Expand All @@ -21,9 +21,10 @@ def hashi_vault_helper():

@pytest.fixture
def expected_stringify_candidates():
return set(
return set([
'token',
)
'namespace',
])


class TestHashiVaultHelper(object):
Expand Down