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

PB-1406: Make cognito authenticated users superuser #508

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 5 additions & 1 deletion app/middleware/api_gateway_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ def authenticate(self, request, remote_user):
if not settings.FEATURE_AUTH_ENABLE_APIGW:
return None

return super().authenticate(request, remote_user)
user = super().authenticate(request, remote_user)
if user:
user.is_superuser = True
user.save()
return user
11 changes: 5 additions & 6 deletions app/tests/tests_09/test_geoadmin_header_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from parameterized import parameterized

from django.contrib.auth import get_user_model
from django.test import Client
from django.test import override_settings

Expand All @@ -15,19 +14,19 @@

@override_settings(FEATURE_AUTH_ENABLE_APIGW=True)
class GeoadminHeadersAuthForPutEndpointTestCase(StacBaseTestCase):
valid_username = "another_test_user"

def setUp(self): # pylint: disable=invalid-name
self.client = Client(enforce_csrf_checks=True)
self.factory = Factory()
self.collection = self.factory.create_collection_sample()
get_user_model().objects.create_superuser(self.valid_username)

@parameterized.expand([
(valid_username, "true", 201),
("another_test_user", "true", 201),
("another_test_user", "false", 401),
("another_test_user", "", 401),
(None, None, 401),
(valid_username, "false", 401),
("wronguser", "true", 403),
(None, "false", 401),
(None, "true", 401),
])
def test_collection_upsert_create_with_geoadmin_header_auth(
self, username_header, authenticated_header, expected_response_code
Expand Down
Loading
Loading