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

Fix: Broken Swagger when Remote User enabled #9960

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion dojo/remote_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,13 @@ class RemoteUserScheme(OpenApiAuthenticationExtension):
priority = 1

def get_security_definition(self, auto_schema):
return settings.SWAGGER_SETTINGS['SECURITY_DEFINITIONS']['remoteUserAuth']
header_name = settings.AUTH_REMOTEUSER_USERNAME_HEADER
if header_name.startswith('HTTP_'):
header_name = header_name[5:]
header_name = header_name.replace('_', '-').capitalize()

return {
'type': 'apiKey',
'in': 'header',
'name': header_name,
}
13 changes: 13 additions & 0 deletions unittests/test_remote_user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.test import Client, override_settings
from netaddr import IPSet
from dojo.models import User, Dojo_Group, Dojo_Group_Member
from dojo.remote_user import RemoteUserScheme
from .dojo_test_case import DojoTestCase


Expand Down Expand Up @@ -193,3 +194,15 @@ def test_untrusted_proxy(self):
)
self.assertEqual(resp.status_code, 302)
self.assertIn('Requested came from untrusted proxy', cm.output[0])

@override_settings(
AUTH_REMOTEUSER_ENABLED=True,
AUTH_REMOTEUSER_USERNAME_HEADER="HTTP_OUR_REMOTE_USER",
)
def test_api_schema(self):
security_definition = RemoteUserScheme.get_security_definition(None, None)
self.assertEqual(security_definition, {
"type": "apiKey",
"in": "header",
"name": "Our-remote-user",
})
Loading