From e0665d0790d4d1450edc835732bbc840a76446e4 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 22 May 2024 13:35:48 +0200 Subject: [PATCH] adapt auth tests to hub version No-Issue --- galaxy_ng/tests/integration/api/test_auth.py | 28 +++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/galaxy_ng/tests/integration/api/test_auth.py b/galaxy_ng/tests/integration/api/test_auth.py index 1377b0690e..0d01d5fd45 100644 --- a/galaxy_ng/tests/integration/api/test_auth.py +++ b/galaxy_ng/tests/integration/api/test_auth.py @@ -4,11 +4,12 @@ """ import pytest +from pkg_resources import parse_version from galaxykit.utils import GalaxyClientError from urllib.parse import urlparse from ..utils import uuid4 -from ..utils.iqe_utils import is_keycloak +from ..utils.iqe_utils import is_keycloak, get_hub_version from ..utils.iqe_utils import remove_from_cache, aap_gateway pytestmark = pytest.mark.qa # noqa: F821 @@ -18,18 +19,23 @@ @pytest.mark.deployment_standalone @pytest.mark.galaxyapi_smoke @pytest.mark.skip_in_gw -def test_token_auth(profile, galaxy_client): +def test_token_auth(profile, galaxy_client, ansible_config): """Test whether normal auth is required and works to access APIs. Also tests the settings for user profiles used for testing. """ + hub_version = get_hub_version(ansible_config) + expected_status_code = 401 + if parse_version(hub_version) < parse_version('4.10.0dev'): + expected_status_code = 403 + gc = galaxy_client(profile) del gc.headers["Authorization"] remove_from_cache(profile) with pytest.raises(GalaxyClientError) as ctx: gc.get("v3/collections/") - assert ctx.value.response.status_code == 401 + assert ctx.value.response.status_code == expected_status_code gc = galaxy_client(profile, ignore_cache=True) resp = gc.get("") assert "available_versions" in resp @@ -38,29 +44,37 @@ def test_token_auth(profile, galaxy_client): @pytest.mark.deployment_standalone @pytest.mark.galaxyapi_smoke @pytest.mark.skip_in_gw -def test_auth_admin(galaxy_client): +def test_auth_admin(galaxy_client, ansible_config): """Test whether admin can not access collections page using invalid token.""" + hub_version = get_hub_version(ansible_config) + expected_status_code = 401 + if parse_version(hub_version) < parse_version('4.10.0dev'): + expected_status_code = 403 gc = galaxy_client("admin") gc.headers["Authorization"] = f"Bearer {uuid4()}" remove_from_cache("admin") with pytest.raises(GalaxyClientError) as ctx: gc.get("v3/collections/") - assert ctx.value.response.status_code == 401 + assert ctx.value.response.status_code == expected_status_code @pytest.mark.deployment_standalone @pytest.mark.galaxyapi_smoke @pytest.mark.skip_in_gw -def test_auth_exception(galaxy_client): +def test_auth_exception(galaxy_client, ansible_config): """Test whether an HTTP exception when using an invalid token.""" + hub_version = get_hub_version(ansible_config) + expected_status_code = 401 + if parse_version(hub_version) < parse_version('4.10.0dev'): + expected_status_code = 403 gc = galaxy_client("basic_user") gc.headers["Authorization"] = f"Bearer {uuid4()}" remove_from_cache("basic_user") with pytest.raises(GalaxyClientError) as ctx: gc.get("v3/collections/") - assert ctx.value.response.status_code == 401 + assert ctx.value.response.status_code == expected_status_code @pytest.mark.deployment_standalone