diff options
author | Sloane Hertel <19572925+s-hertel@users.noreply.github.com> | 2022-01-11 20:46:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-11 20:46:45 +0100 |
commit | 76220c4a7bf90c97113fe104ea33957a9881b8a9 (patch) | |
tree | ba8a3a0e37d1e60f4a9aa8cb610a13048fd04f21 /test/units/galaxy/test_collection.py | |
parent | Fix C&P error (#76673) (diff) | |
download | ansible-76220c4a7bf90c97113fe104ea33957a9881b8a9.tar.xz ansible-76220c4a7bf90c97113fe104ea33957a9881b8a9.zip |
ansible-galaxy - fix the --ignore-certs flag for the implicit galaxy server (#76735)
* ansible-galaxy - fix the --ignore-certs flag for the implicit galaxy server
* changelog
* Add a test without the server config
* Fix respecting --ignore-certs for individual --server URLs also
* Update changelogs/fragments/76735-ansible-galaxy-fix-ignore-certs.yaml
Diffstat (limited to 'test/units/galaxy/test_collection.py')
-rw-r--r-- | test/units/galaxy/test_collection.py | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/test/units/galaxy/test_collection.py b/test/units/galaxy/test_collection.py index b8c72a775f..65243df151 100644 --- a/test/units/galaxy/test_collection.py +++ b/test/units/galaxy/test_collection.py @@ -218,7 +218,49 @@ def server_config(monkeypatch): @pytest.mark.parametrize('global_ignore_certs', [True, False]) -def test_validate_certs(global_ignore_certs, server_config, monkeypatch): +def test_validate_certs(global_ignore_certs, monkeypatch): + 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 len(galaxy_cli.api_servers) == 1 + assert galaxy_cli.api_servers[0].validate_certs is not global_ignore_certs + + +@pytest.mark.parametrize('global_ignore_certs', [True, False]) +def test_validate_certs_with_server_url(global_ignore_certs, monkeypatch): + cli_args = [ + 'ansible-galaxy', + 'collection', + 'install', + 'namespace.collection:1.0.0', + '-s', + 'https://galaxy.ansible.com' + ] + 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 len(galaxy_cli.api_servers) == 1 + assert galaxy_cli.api_servers[0].validate_certs is not global_ignore_certs + + +@pytest.mark.parametrize('global_ignore_certs', [True, False]) +def test_validate_certs_with_server_config(global_ignore_certs, server_config, monkeypatch): get_plugin_options = MagicMock(side_effect=server_config) monkeypatch.setattr(C.config, 'get_plugin_options', get_plugin_options) |