diff options
author | Sloane Hertel <19572925+s-hertel@users.noreply.github.com> | 2021-09-16 19:54:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-16 19:54:52 +0200 |
commit | 72ba2bdc82944f904245a044a9c917a3bfad4c78 (patch) | |
tree | e67dd533dac2e4720d0be3697fc3983712325b4b /test/units/galaxy/test_collection.py | |
parent | Fix git submodules path issue (#75655) (diff) | |
download | ansible-72ba2bdc82944f904245a044a9c917a3bfad4c78.tar.xz ansible-72ba2bdc82944f904245a044a9c917a3bfad4c78.zip |
ansible-galaxy - add a per-server validate_certs option (#75710)
* Add a validate_certs option to galaxy server configuration
* Add a unit test for cert validation
* changelog
Diffstat (limited to 'test/units/galaxy/test_collection.py')
-rw-r--r-- | test/units/galaxy/test_collection.py | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/test/units/galaxy/test_collection.py b/test/units/galaxy/test_collection.py index 8575a55c17..3de2e89a0a 100644 --- a/test/units/galaxy/test_collection.py +++ b/test/units/galaxy/test_collection.py @@ -17,8 +17,9 @@ from hashlib import sha256 from io import BytesIO from units.compat.mock import MagicMock, mock_open, patch +import ansible.constants as C from ansible import context -from ansible.cli.galaxy import GalaxyCLI +from ansible.cli.galaxy import GalaxyCLI, SERVER_DEF from ansible.errors import AnsibleError from ansible.galaxy import api, collection, token from ansible.module_utils._text import to_bytes, to_native, to_text @@ -198,6 +199,48 @@ def manifest(manifest_info): yield fake_file, sha256(b_data).hexdigest() +@pytest.fixture() +def server_config(monkeypatch): + monkeypatch.setattr(C, 'GALAXY_SERVER_LIST', ['server1', 'server2', 'server3']) + + default_options = dict((k, None) for k, v in SERVER_DEF) + + server1 = dict(default_options) + server1.update({'url': 'https://galaxy.ansible.com/api/', 'validate_certs': False}) + + server2 = dict(default_options) + server2.update({'url': 'https://galaxy.ansible.com/api/', 'validate_certs': True}) + + server3 = dict(default_options) + server3.update({'url': 'https://galaxy.ansible.com/api/'}) + + return server1, server2, server3 + + +@pytest.mark.parametrize('global_ignore_certs', [True, False]) +def test_validate_certs(global_ignore_certs, server_config, monkeypatch): + get_plugin_options = MagicMock(side_effect=server_config) + monkeypatch.setattr(C.config, 'get_plugin_options', get_plugin_options) + + cli_args = [ + 'ansible-galaxy', + 'collection', + 'install', + 'namespace.collection:1.0.0', + ] + if global_ignore_certs: + cli_args.append('--ignore-certs') + + galaxy_cli = GalaxyCLI(args=cli_args) + mock_execute_install = MagicMock() + monkeypatch.setattr(galaxy_cli, '_execute_install_collection', mock_execute_install) + galaxy_cli.run() + + assert galaxy_cli.api_servers[0].validate_certs is False + assert galaxy_cli.api_servers[1].validate_certs is True + assert galaxy_cli.api_servers[2].validate_certs is not global_ignore_certs + + def test_build_collection_no_galaxy_yaml(): fake_path = u'/fake/ÅÑŚÌβŁÈ/path' expected = to_native("The collection galaxy.yml path '%s/galaxy.yml' does not exist." % fake_path) |