4
4
5
5
"""
6
6
import pytest
7
+ from pkg_resources import parse_version
7
8
8
9
from galaxykit .utils import GalaxyClientError
9
10
from urllib .parse import urlparse
10
11
from ..utils import uuid4
11
- from ..utils .iqe_utils import is_keycloak
12
+ from ..utils .iqe_utils import is_keycloak , get_hub_version
12
13
from ..utils .iqe_utils import remove_from_cache , aap_gateway
13
14
14
15
pytestmark = pytest .mark .qa # noqa: F821
18
19
@pytest .mark .deployment_standalone
19
20
@pytest .mark .galaxyapi_smoke
20
21
@pytest .mark .skip_in_gw
21
- def test_token_auth (profile , galaxy_client ):
22
+ def test_token_auth (profile , galaxy_client , ansible_config ):
22
23
"""Test whether normal auth is required and works to access APIs.
23
24
24
25
Also tests the settings for user profiles used for testing.
25
26
"""
27
+ hub_version = get_hub_version (ansible_config )
28
+ expected_status_code = 401
29
+ if parse_version (hub_version ) < parse_version ('4.10.0dev' ):
30
+ expected_status_code = 403
31
+
26
32
gc = galaxy_client (profile )
27
33
del gc .headers ["Authorization" ]
28
34
remove_from_cache (profile )
29
35
30
36
with pytest .raises (GalaxyClientError ) as ctx :
31
37
gc .get ("v3/collections/" )
32
- assert ctx .value .response .status_code == 401
38
+ assert ctx .value .response .status_code == expected_status_code
33
39
gc = galaxy_client (profile , ignore_cache = True )
34
40
resp = gc .get ("" )
35
41
assert "available_versions" in resp
@@ -38,29 +44,37 @@ def test_token_auth(profile, galaxy_client):
38
44
@pytest .mark .deployment_standalone
39
45
@pytest .mark .galaxyapi_smoke
40
46
@pytest .mark .skip_in_gw
41
- def test_auth_admin (galaxy_client ):
47
+ def test_auth_admin (galaxy_client , ansible_config ):
42
48
"""Test whether admin can not access collections page using invalid token."""
49
+ hub_version = get_hub_version (ansible_config )
50
+ expected_status_code = 401
51
+ if parse_version (hub_version ) < parse_version ('4.10.0dev' ):
52
+ expected_status_code = 403
43
53
44
54
gc = galaxy_client ("admin" )
45
55
gc .headers ["Authorization" ] = f"Bearer { uuid4 ()} "
46
56
remove_from_cache ("admin" )
47
57
with pytest .raises (GalaxyClientError ) as ctx :
48
58
gc .get ("v3/collections/" )
49
- assert ctx .value .response .status_code == 401
59
+ assert ctx .value .response .status_code == expected_status_code
50
60
51
61
52
62
@pytest .mark .deployment_standalone
53
63
@pytest .mark .galaxyapi_smoke
54
64
@pytest .mark .skip_in_gw
55
- def test_auth_exception (galaxy_client ):
65
+ def test_auth_exception (galaxy_client , ansible_config ):
56
66
"""Test whether an HTTP exception when using an invalid token."""
67
+ hub_version = get_hub_version (ansible_config )
68
+ expected_status_code = 401
69
+ if parse_version (hub_version ) < parse_version ('4.10.0dev' ):
70
+ expected_status_code = 403
57
71
58
72
gc = galaxy_client ("basic_user" )
59
73
gc .headers ["Authorization" ] = f"Bearer { uuid4 ()} "
60
74
remove_from_cache ("basic_user" )
61
75
with pytest .raises (GalaxyClientError ) as ctx :
62
76
gc .get ("v3/collections/" )
63
- assert ctx .value .response .status_code == 401
77
+ assert ctx .value .response .status_code == expected_status_code
64
78
65
79
66
80
@pytest .mark .deployment_standalone
0 commit comments