Skip to content

Commit

Permalink
Merge pull request #589 from rohanpm/compression-base64-fix
Browse files Browse the repository at this point in the history
Fix double base64 encoding in config [RHELDST-25461]
  • Loading branch information
rohanpm authored Aug 6, 2024
2 parents a15293a + 7bb1990 commit 6e4c4dc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 1 addition & 2 deletions exodus_lambda/functions/origin_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ def definitions(self):
)
if query_result["Items"]:
item = query_result["Items"][0]
if item_encoded := item["config"].get("B"):
if item_bytes := item["config"].get("B"):
# new-style: config is compressed and stored as bytes
item_bytes = b64decode(item_encoded)
item_json = gzip.decompress(item_bytes).decode()
else:
# old-style, config was stored as JSON string.
Expand Down
6 changes: 3 additions & 3 deletions tests/functions/test_origin_request.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import gzip
import json
import logging
from base64 import b64encode
from urllib.parse import unquote, urlencode

import mock
Expand Down Expand Up @@ -349,13 +348,14 @@ def test_origin_request_invalid_item(
def test_origin_request_definitions(mocked_boto3_client, binary_config: bool):
mocked_defs = mock_definitions()
json_defs = json.dumps(mocked_defs)
config: dict[str, str | bytes] = {}

if binary_config:
# Config in the style exodus-gw writes from late 2024 onwards
config = {"B": b64encode(gzip.compress(json_defs.encode())).decode()}
config["B"] = gzip.compress(json_defs.encode())
else:
# Older-style config
config = {"S": json_defs}
config["S"] = json_defs

mocked_boto3_client().query.return_value = {
"Items": [
Expand Down

0 comments on commit 6e4c4dc

Please sign in to comment.