Skip to content

Commit 36630ea

Browse files
committed
Bump OpenAPI version
1 parent 8f4ebee commit 36630ea

File tree

6 files changed

+41
-21
lines changed

6 files changed

+41
-21
lines changed

.github/workflows/scripts/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ if [ "$TEST" = "s3" ]; then
105105
sed -i -e '$a s3_test: true\
106106
minio_access_key: "'$MINIO_ACCESS_KEY'"\
107107
minio_secret_key: "'$MINIO_SECRET_KEY'"\
108-
pulp_scenario_settings: {"DISABLED_authentication_backends": "@merge django.contrib.auth.backends.RemoteUserBackend", "DISABLED_authentication_json_header": "HTTP_X_RH_IDENTITY", "DISABLED_authentication_json_header_jq_filter": ".identity.user.username", "DISABLED_authentication_json_header_openapi_security_scheme": {"description": "External OAuth integration", "flows": {"clientCredentials": {"scopes": {"api.console": "grant_access_to_pulp"}, "tokenUrl": "https://your-identity-provider/token/issuer"}}, "type": "oauth2"}, "DISABLED_rest_framework__default_authentication_classes": "@merge pulpcore.app.authentication.JSONHeaderRemoteAuthentication", "domain_enabled": true, "hide_guarded_distributions": true, "rest_framework__default_permission_classes": ["pulpcore.plugin.access_policy.AccessPolicyFromSettings"]}\
108+
pulp_scenario_settings: {"DISABLED_authentication_backends": "@merge django.contrib.auth.backends.RemoteUserBackend", "DISABLED_authentication_json_header": "HTTP_X_RH_IDENTITY", "DISABLED_authentication_json_header_jq_filter": ".identity.user.username", "DISABLED_authentication_json_header_openapi_security_scheme": {"description": "External OAuth integration", "flows": {"clientCredentials": {"scopes": {"api.console": "grant_access_to_pulp"}, "tokenUrl": "https://your-identity-provider/token/issuer"}}, "type": "oauth2"}, "DISABLED_rest_framework__default_authentication_classes": "@merge pulpcore.app.authentication.JSONHeaderRemoteAuthentication", "domain_enabled": true, "hide_guarded_distributions": true, "rest_framework__default_permission_classes": ["pulpcore.plugin.access_policy.AccessPolicyFromSettings"], "spectacular_settings__oas_version": "3.0.3"}\
109109
pulp_scenario_env: {}\
110110
test_storages_compat_layer: true\
111111
' vars/main.yaml

CHANGES/+oasversion.removal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Switch OpenAPI specification to use version 3.1.

pulpcore/app/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@
348348
REMOTE_CONTENT_FETCH_FAILURE_COOLDOWN = 5 * 60 # 5 minutes
349349

350350
SPECTACULAR_SETTINGS = {
351+
"OAS_VERSION": "3.1.1",
351352
"SERVE_URLCONF": ROOT_URLCONF,
352353
"DEFAULT_GENERATOR_CLASS": "pulpcore.openapi.PulpSchemaGenerator",
353354
"DEFAULT_SCHEMA_CLASS": "pulpcore.openapi.PulpAutoSchema",

pulpcore/tests/functional/api/test_auth.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313

1414

1515
@pytest.mark.parallel
16+
@pytest.mark.skipif(
17+
"rest_framework.authentication.BasicAuthentication"
18+
not in settings.REST_FRAMEWORK["DEFAULT_AUTHENTICATION_CLASSES"],
19+
reason="Test can't run unless BasicAuthentication is enabled",
20+
)
1621
def test_base_auth_success(pulpcore_bindings, pulp_admin_user):
1722
"""Perform HTTP basic authentication with valid credentials.
1823
@@ -33,6 +38,11 @@ def test_base_auth_success(pulpcore_bindings, pulp_admin_user):
3338

3439

3540
@pytest.mark.parallel
41+
@pytest.mark.skipif(
42+
"rest_framework.authentication.BasicAuthentication"
43+
not in settings.REST_FRAMEWORK["DEFAULT_AUTHENTICATION_CLASSES"],
44+
reason="Test can't run unless BasicAuthentication is enabled",
45+
)
3646
def test_base_auth_failure(pulpcore_bindings, invalid_user):
3747
"""Perform HTTP basic authentication with invalid credentials.
3848
@@ -50,6 +60,11 @@ def test_base_auth_failure(pulpcore_bindings, invalid_user):
5060

5161

5262
@pytest.mark.parallel
63+
@pytest.mark.skipif(
64+
"rest_framework.authentication.BasicAuthentication"
65+
not in settings.REST_FRAMEWORK["DEFAULT_AUTHENTICATION_CLASSES"],
66+
reason="Test can't run unless BasicAuthentication is enabled",
67+
)
5368
def test_base_auth_required(pulpcore_bindings, anonymous_user):
5469
"""Perform HTTP basic authentication with no credentials.
5570
@@ -69,7 +84,7 @@ def test_base_auth_required(pulpcore_bindings, anonymous_user):
6984
@pytest.mark.parallel
7085
@pytest.mark.skipif(
7186
"django.contrib.auth.backends.RemoteUserBackend" not in settings.AUTHENTICATION_BACKENDS
72-
and "pulpcore.app.authentication.JSONHeaderRemoteAuthentication"
87+
or "pulpcore.app.authentication.JSONHeaderRemoteAuthentication"
7388
not in settings.REST_FRAMEWORK["DEFAULT_AUTHENTICATION_CLASSES"],
7489
reason="Test can't run unless RemoteUserBackend and JSONHeaderRemoteAuthentication are enabled",
7590
)
@@ -98,7 +113,7 @@ def test_jq_header_remote_auth(pulpcore_bindings, anonymous_user):
98113
@pytest.mark.parallel
99114
@pytest.mark.skipif(
100115
"django.contrib.auth.backends.RemoteUserBackend" not in settings.AUTHENTICATION_BACKENDS
101-
and "pulpcore.app.authentication.JSONHeaderRemoteAuthentication"
116+
or "pulpcore.app.authentication.JSONHeaderRemoteAuthentication"
102117
not in settings.REST_FRAMEWORK["DEFAULT_AUTHENTICATION_CLASSES"],
103118
reason="Test can't run unless RemoteUserBackend and JSONHeaderRemoteAuthentication are enabled",
104119
)
@@ -127,7 +142,7 @@ def test_jq_header_remote_auth_denied_by_wrong_header(pulpcore_bindings, anonymo
127142
@pytest.mark.parallel
128143
@pytest.mark.skipif(
129144
"django.contrib.auth.backends.RemoteUserBackend" not in settings.AUTHENTICATION_BACKENDS
130-
and "pulpcore.app.authentication.JSONHeaderRemoteAuthentication"
145+
or "pulpcore.app.authentication.JSONHeaderRemoteAuthentication"
131146
not in settings.REST_FRAMEWORK["DEFAULT_AUTHENTICATION_CLASSES"],
132147
reason="Test can't run unless RemoteUserBackend and JSONHeaderRemoteAuthentication are enabled",
133148
)

pulpcore/tests/functional/api/test_openapi_schema.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,39 @@
22

33
import copy
44
import json
5-
import os
5+
from pathlib import Path
66

77
import pytest
88
import jsonschema
99

1010
from drf_spectacular import validation
1111
from collections import defaultdict
1212

13-
JSON_SCHEMA_SPEC_PATH = os.path.join(
14-
os.path.dirname(validation.__file__), "openapi_3_0_schema.json"
15-
)
16-
1713

1814
@pytest.fixture(scope="session")
19-
def openapi3_schema_spec():
20-
with open(JSON_SCHEMA_SPEC_PATH) as fh:
21-
openapi3_schema_spec = json.load(fh)
22-
23-
return openapi3_schema_spec
15+
def openapi3_schema_spec(pulp_openapi_schema):
16+
schema_version = pulp_openapi_schema["openapi"]
17+
if schema_version.startswith("3.0"):
18+
spec_path = Path(validation.__file__).parent / "openapi_3_0_schema.json"
19+
elif schema_version.startswith("3.1"):
20+
spec_path = Path(validation.__file__).parent / "openapi_3_1_schema.json"
21+
else:
22+
pytest.fail(f"Unknown OpenAPI schema version [{schema_version}].")
23+
return json.loads(spec_path.read_text())
2424

2525

2626
@pytest.fixture(scope="session")
2727
def openapi3_schema_with_modified_safe_chars(openapi3_schema_spec):
28-
openapi3_schema_spec_copy = copy.deepcopy(openapi3_schema_spec) # Don't modify the original
28+
oas_copy = copy.deepcopy(openapi3_schema_spec) # Don't modify the original
2929
# Making OpenAPI validation to accept paths starting with / and {
30-
properties = openapi3_schema_spec_copy["definitions"]["Paths"]["patternProperties"]
31-
properties["^\\/|{"] = properties["^\\/"]
32-
del properties["^\\/"]
33-
34-
return openapi3_schema_spec_copy
30+
if "3.1.x" in oas_copy["description"]:
31+
pattern_properties = oas_copy["$defs"]["paths"]["patternProperties"]
32+
pattern_properties["^/|{"] = pattern_properties.pop("^/")
33+
else:
34+
pattern_properties = oas_copy["definitions"]["Paths"]["patternProperties"]
35+
pattern_properties["^\\/|{"] = pattern_properties.pop("^\\/")
36+
37+
return oas_copy
3538

3639

3740
@pytest.mark.parallel

template_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pulp_settings_s3:
8585
hide_guarded_distributions: true
8686
rest_framework__default_permission_classes:
8787
- pulpcore.plugin.access_policy.AccessPolicyFromSettings
88+
spectacular_settings__oas_version: "3.0.3"
8889
pydocstyle: true
8990
release_email: [email protected]
9091
release_user: pulpbot
@@ -110,4 +111,3 @@ test_reroute: true
110111
test_s3: true
111112
test_storages_compat_layer: true
112113
use_issue_template: true
113-

0 commit comments

Comments
 (0)