Skip to content

Commit

Permalink
Lookup plugin: fix false positive unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
john-odonnell committed May 23, 2024
1 parent 7a7e57f commit 261de1d
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions tests/unit/plugins/lookup/test_conjur_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,11 @@ def test_run_bad_config(self, mock_merge_dictionaries):
kwargs = {'as_file': False, 'conf_file': 'conf_file', 'validate_certs': True}
with self.assertRaises(AnsibleError) as context:
self.lookup.run(terms, **kwargs)
self.assertEqual(
context.exception.message,
"Configuration file on the controlling host must define `account` and `appliance_url` entries or they should be environment variables"
)

self.assertIn(
"Configuration must define options `conjur_account` and `conjur_appliance_url`",
context.exception.message,
)

# Withhold 'id' and 'api_key' fields
mock_merge_dictionaries.side_effect = [
Expand All @@ -145,11 +146,11 @@ def test_run_bad_config(self, mock_merge_dictionaries):

with self.assertRaises(AnsibleError) as context:
self.lookup.run(terms, **kwargs)
self.assertEqual(
context.exception.message,
("Identity file on the controlling host must contain `login` and `password` "
"entries for Conjur appliance URL or they should be environment variables")
)

self.assertIn(
"Configuration must define options `conjur_authn_login` and `conjur_authn_api_key`",
context.exception.message,
)

@patch('ansible_collections.cyberark.conjur.plugins.lookup.conjur_variable._merge_dictionaries')
def test_run_bad_cert_path(self, mock_merge_dictionaries):
Expand All @@ -168,11 +169,13 @@ def test_run_no_variable_path(self):

with self.assertRaises(AnsibleError) as context:
self.lookup.run([], **kwargs)
self.assertEqual(context.exception.message, "Invalid secret path: no secret path provided.")

self.assertEqual(context.exception.message, "Invalid secret path: no secret path provided.")

with self.assertRaises(AnsibleError) as context:
self.lookup.run([''], **kwargs)
self.assertEqual(context.exception.message, "Invalid secret path: empty secret path not accepted.")

self.assertEqual(context.exception.message, "Invalid secret path: empty secret path not accepted.")

@patch('ansible_collections.cyberark.conjur.plugins.lookup.conjur_variable._fetch_conjur_variable')
@patch('ansible_collections.cyberark.conjur.plugins.lookup.conjur_variable._fetch_conjur_token')
Expand Down

0 comments on commit 261de1d

Please sign in to comment.