Skip to content

Commit

Permalink
Add missing migration for help text, fixing tests
Browse files Browse the repository at this point in the history
decode_x_header now returns a None if the header isn't found (rather than a string)
  • Loading branch information
jkachel committed Mar 6, 2024
1 parent f9f7d6b commit 2d2e6bb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.10 on 2024-03-06 20:03

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("authentication", "0002_add_keycloak_user_info_model"),
]

operations = [
migrations.AlterField(
model_name="keycloakadmintoken",
name="authorization_token_expires_in",
field=models.IntegerField(
help_text="Seconds until authentication token expires"
),
),
migrations.AlterField(
model_name="keycloakadmintoken",
name="refresh_token_expires_in",
field=models.IntegerField(
help_text="Seconds until refresh token expires", null=True
),
),
]
6 changes: 4 additions & 2 deletions system_meta/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ def apisix_test_request(request):
response = {
"name": "Response ok!",
"user": request.user.username if request.user is not None else None,
"x_userinfo": decode_x_header(request, "HTTP_X_USERINFO"),
"x_id_token": decode_x_header(request, "HTTP_X_ID_TOKEN"),
"x_userinfo": decode_x_header(request, "HTTP_X_USERINFO")
or "No HTTP_X_USERINFO header",
"x_id_token": decode_x_header(request, "HTTP_X_ID_TOKEN")
or "No HTTP_X_ID_TOKEN header",
}

return Response(response, status=status.HTTP_200_OK)
Expand Down
3 changes: 3 additions & 0 deletions unified_ecommerce/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ def decode_apisix_headers(self, request):
try:
apisix_result = decode_x_header(request, "HTTP_X_USERINFO")
if not apisix_result:
log.debug(
"No APISIX-specific header found",
)
return None
except json.JSONDecodeError:
log.debug(
Expand Down
2 changes: 1 addition & 1 deletion unified_ecommerce/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def decode_x_header(request, header):
x_userinfo = request.META.get(header, False)

if not x_userinfo:
return f"No {header} header"
return None

decoded_x_userinfo = base64.b64decode(x_userinfo)
return json.loads(decoded_x_userinfo)

0 comments on commit 2d2e6bb

Please sign in to comment.