Debian Codegraph @

ansible_collections/community/hashi_vault/tests/unit/plugins/lookup/test_vault_login.py

raw
1 # -*- coding: utf-8 -*-
2 # Copyright (c) 2021 Brian Scholer (@briantist)
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)
4 # SPDX-License-Identifier: GPL-3.0-or-later
5
6 from __future__ import (absolute_import, division, print_function)
7 __metaclass__ = type
8
9 import pytest
10
11 from ansible.plugins.loader import lookup_loader
12 from ansible.errors import AnsibleError
13
14 from ansible_collections.community.hashi_vault.tests.unit.compat import mock
15
16 from ansible_collections.community.hashi_vault.plugins.plugin_utils._hashi_vault_lookup_base import HashiVaultLookupBase
17
18 # needs to be a relative import otherwise it breaks test_vault_login_extra_terms.
19 from .....plugins.lookup import vault_login # pylint: disable=unused-import
20
21
22 pytest.importorskip('hvac')
23
24
25 pytestmark = pytest.mark.usefixtures(
26 'patch_authenticator',
27 'patch_get_vault_client',
28 )
29
30
31 @pytest.fixture
32 def vault_login_lookup():
33 return lookup_loader.get('community.hashi_vault.vault_login')
34
35
36 class TestVaultLoginLookup(object):
37
38 def test_vault_login_is_lookup_base(self, vault_login_lookup):
39 assert issubclass(type(vault_login_lookup), HashiVaultLookupBase)
40
41 def test_vault_login_auth_none(self, vault_login_lookup):
42 with pytest.raises(AnsibleError, match=r"The 'none' auth method is not valid for this lookup"):
43 vault_login_lookup.run(terms=[], variables={'ansible_hashi_vault_auth_method': 'none'})
44
45 def test_vault_login_extra_terms(self, vault_login_lookup, authenticator, minimal_vars):
46 with mock.patch('ansible_collections.community.hashi_vault.plugins.lookup.vault_login.display.warning') as warning:
47 with mock.patch.object(vault_login_lookup, 'authenticator', new=authenticator):
48 vault_login_lookup.run(terms=['', ''], variables=minimal_vars)
49 warning.assert_called_once_with("Supplied term strings will be ignored. This lookup does not use term strings.")