diff options
author | Chris Hambridge <chambrid@redhat.com> | 2021-09-17 21:10:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-17 21:10:10 +0200 |
commit | 1353678f237ee4ceb7345f6e277138aaa2af8db9 (patch) | |
tree | 5f8989b3522f94ba2c90eb31a3a73e4148f8c9c4 /test/units/galaxy | |
parent | Integration test and sanity index generation fixes. (#75731) (diff) | |
download | ansible-1353678f237ee4ceb7345f6e277138aaa2af8db9.tar.xz ansible-1353678f237ee4ceb7345f6e277138aaa2af8db9.zip |
Enable ansible-galaxy to specify client id override with Keycloak Token (#75601)
* Enable ansible-galaxy to specify client id override with Keycloak Token
* Specify ability to provide override of client_id
* Test client_id can be configured for individual servers
* Add issue link to changelog
* Document client_id as a config option and add an example
Co-authored-by: s-hertel <19572925+s-hertel@users.noreply.github.com>
Diffstat (limited to 'test/units/galaxy')
-rw-r--r-- | test/units/galaxy/test_token.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/units/galaxy/test_token.py b/test/units/galaxy/test_token.py index 94449e28e9..13426688e3 100644 --- a/test/units/galaxy/test_token.py +++ b/test/units/galaxy/test_token.py @@ -8,8 +8,10 @@ __metaclass__ = type import os import pytest +from units.compat.mock import MagicMock import ansible.constants as C +from ansible.cli.galaxy import GalaxyCLI, SERVER_DEF from ansible.galaxy.token import GalaxyToken, NoTokenSentinel from ansible.module_utils._text import to_bytes, to_text @@ -32,6 +34,47 @@ def b_token_file(request, tmp_path_factory): C.GALAXY_TOKEN_PATH = orig_token_path +def test_client_id(monkeypatch): + monkeypatch.setattr(C, 'GALAXY_SERVER_LIST', ['server1', 'server2']) + + test_server_config = {option[0]: None for option in SERVER_DEF} + test_server_config.update( + { + 'url': 'http://my_galaxy_ng:8000/api/automation-hub/', + 'auth_url': 'http://my_keycloak:8080/auth/realms/myco/protocol/openid-connect/token', + 'client_id': 'galaxy-ng', + 'token': 'access_token', + } + ) + + test_server_default = {option[0]: None for option in SERVER_DEF} + test_server_default.update( + { + 'url': 'https://cloud.redhat.com/api/automation-hub/', + 'auth_url': 'https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token', + 'token': 'access_token', + } + ) + + get_plugin_options = MagicMock(side_effect=[test_server_config, test_server_default]) + monkeypatch.setattr(C.config, 'get_plugin_options', get_plugin_options) + + cli_args = [ + 'ansible-galaxy', + 'collection', + 'install', + 'namespace.collection:1.0.0', + ] + + 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].token.client_id == 'galaxy-ng' + assert galaxy_cli.api_servers[1].token.client_id == 'cloud-services' + + def test_token_explicit(b_token_file): assert GalaxyToken(token="explicit").get() == "explicit" |