Skip to content

Commit 76ede0c

Browse files
committed
Enforce oauth in oauth test scenario
1 parent 77d1701 commit 76ede0c

File tree

4 files changed

+13
-41
lines changed

4 files changed

+13
-41
lines changed

.ci/settings/settings.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,33 @@
44
ANALYTICS = False
55
ALLOWED_CONTENT_CHECKSUMS = ["sha1", "sha256", "sha512"]
66

7-
if os.environ.get("PULP_HTTPS", "false").lower() == "true":
7+
pulp_https = os.environ.get("PULP_HTTPS", "false").lower() == "true"
8+
pulp_oauth2 = os.environ.get("PULP_OAUTH2", "false").lower() == "true"
9+
10+
if pulp_https and not pulp_oauth2:
811
AUTHENTICATION_BACKENDS = "@merge django.contrib.auth.backends.RemoteUserBackend"
912
MIDDLEWARE = "@merge django.contrib.auth.middleware.RemoteUserMiddleware"
1013
REST_FRAMEWORK__DEFAULT_AUTHENTICATION_CLASSES = (
1114
"@merge pulpcore.app.authentication.PulpRemoteUserAuthentication"
1215
)
1316
REMOTE_USER_ENVIRON_NAME = "HTTP_REMOTEUSER"
1417

15-
if os.environ.get("PULP_OAUTH2", "false").lower() == "true":
16-
assert os.environ.get("PULP_HTTPS", "false").lower() == "true"
18+
if pulp_oauth2:
19+
assert pulp_https
1720

1821
def PulpCliFakeOauth2Authentication(*args, **kwargs):
1922
# We need to lazy load this.
2023
# Otherwise views may be instanciated, before this configuration is merged.
2124

22-
from django.contrib.auth import authenticate
25+
from django.contrib.auth import get_user_model
2326
from drf_spectacular.extensions import OpenApiAuthenticationExtension
2427
from rest_framework.authentication import BaseAuthentication
2528

2629
class _PulpCliFakeOauth2Authentication(BaseAuthentication):
2730
def authenticate(self, request):
2831
auth_header = request.META.get("HTTP_AUTHORIZATION")
2932
if auth_header == "Bearer DEADBEEF":
30-
return authenticate(request, remote_user="admin"), None
33+
return get_user_model().objects.get(username="admin"), None
3134
else:
3235
return None
3336

@@ -54,5 +57,5 @@ def get_security_definition(self, auto_schema):
5457
PULP_CLI_FAKE_OAUTH2_AUTHENTICATION = PulpCliFakeOauth2Authentication
5558

5659
REST_FRAMEWORK__DEFAULT_AUTHENTICATION_CLASSES = (
57-
"@merge pulpcore.app.settings.PULP_CLI_FAKE_OAUTH2_AUTHENTICATION"
60+
"pulpcore.app.settings.PULP_CLI_FAKE_OAUTH2_AUTHENTICATION",
5861
)

tests/scripts/pulp_container/test_role.sh

Lines changed: 0 additions & 35 deletions
This file was deleted.

tests/scripts/pulp_file/test_role.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ set -eu
66

77
pulp debug has-plugin --name "file" --specifier ">=1.11.0" || exit 23
88

9+
[ "$(pulp debug openapi security-schemes | jq '.[]|select(.type=="http")|select(.scheme=="basic")|[.]|length')" = "1" ] || exit 23
10+
911
USERPASS="Yeech6ba"
1012

1113
cleanup() {

tests/scripts/pulpcore/test_role.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ set -eu
44
# shellcheck source=tests/scripts/config.source
55
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source
66

7+
[ "$(pulp debug openapi security-schemes | jq '.[]|select(.type=="http")|select(.scheme=="basic")|[.]|length')" = "1" ] || exit 23
8+
79
USERPASS="Yeech6ba"
810

911
cleanup() {

0 commit comments

Comments
 (0)