Skip to content

Commit

Permalink
adapt auth tests to hub version (#2146)
Browse files Browse the repository at this point in the history
No-Issue
  • Loading branch information
chr-stian authored May 23, 2024
1 parent a0ec76c commit c52e9b4
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions galaxy_ng/tests/integration/api/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c52e9b4

Please sign in to comment.