Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adapt auth tests to hub version #2146

Merged
merged 1 commit into from
May 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading