Skip to content

Commit 235a06a

Browse files
authored
StepFunctions: Fix Boto Request Encoding (#12035)
1 parent cb66b15 commit 235a06a

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

localstack-core/localstack/services/stepfunctions/asl/component/state/state_execution/state_task/service/state_task_service.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ def _to_boto_request_value(self, request_value: Any, value_shape: Shape) -> Any:
106106
elif isinstance(value_shape, StringShape) and not isinstance(request_value, str):
107107
boto_request_value = to_json_str(request_value)
108108
elif value_shape.type_name == "blob" and not isinstance(boto_request_value, bytes):
109-
if not isinstance(boto_request_value, str):
110-
boto_request_value = to_json_str(request_value, separators=(":", ","))
109+
boto_request_value = to_json_str(request_value, separators=(",", ":"))
111110
boto_request_value = to_bytes(boto_request_value)
112111
return boto_request_value
113112

tests/aws/services/stepfunctions/v2/services/test_aws_sdk_task_service.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
create_and_record_execution,
99
create_state_machine_with_iam_role,
1010
)
11-
from localstack.utils.strings import short_uid
11+
from localstack.utils.strings import short_uid, to_str
1212
from tests.aws.services.stepfunctions.templates.base.base_templates import BaseTemplate as BT
1313
from tests.aws.services.stepfunctions.templates.services.services_templates import (
1414
ServicesTemplates as ST,
@@ -310,13 +310,15 @@ def test_s3_put_object(
310310
sfn_snapshot,
311311
body,
312312
):
313+
file_key = f"file-key-{short_uid()}"
313314
bucket_name = s3_create_bucket()
315+
sfn_snapshot.add_transformer(RegexTransformer(file_key, "file-key"))
314316
sfn_snapshot.add_transformer(RegexTransformer(bucket_name, "bucket-name"))
315317

316318
template = ST.load_sfn_template(ST.AWS_SDK_S3_PUT_OBJECT)
317319
definition = json.dumps(template)
318320

319-
exec_input = json.dumps({"Bucket": bucket_name, "Key": "file-key", "Body": body})
321+
exec_input = json.dumps({"Bucket": bucket_name, "Key": file_key, "Body": body})
320322
create_and_record_execution(
321323
aws_client,
322324
create_state_machine_iam_role,
@@ -325,3 +327,7 @@ def test_s3_put_object(
325327
definition,
326328
exec_input,
327329
)
330+
get_object_response = aws_client.s3.get_object(Bucket=bucket_name, Key=file_key)
331+
body = get_object_response["Body"].read()
332+
body_str = to_str(body)
333+
sfn_snapshot.match("s3-object-content-body", body_str)

tests/aws/services/stepfunctions/v2/services/test_aws_sdk_task_service.snapshot.json

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,7 +2348,7 @@
23482348
}
23492349
},
23502350
"tests/aws/services/stepfunctions/v2/services/test_aws_sdk_task_service.py::TestTaskServiceAwsSdk::test_s3_put_object[str]": {
2351-
"recorded-date": "11-06-2024, 07:42:53",
2351+
"recorded-date": "13-12-2024, 15:20:04",
23522352
"recorded-content": {
23532353
"get_execution_history": {
23542354
"events": [
@@ -2465,11 +2465,12 @@
24652465
"HTTPHeaders": {},
24662466
"HTTPStatusCode": 200
24672467
}
2468-
}
2468+
},
2469+
"s3-object-content-body": "\"text data\""
24692470
}
24702471
},
24712472
"tests/aws/services/stepfunctions/v2/services/test_aws_sdk_task_service.py::TestTaskServiceAwsSdk::test_s3_put_object[dict]": {
2472-
"recorded-date": "11-06-2024, 07:43:09",
2473+
"recorded-date": "13-12-2024, 15:20:52",
24732474
"recorded-content": {
24742475
"get_execution_history": {
24752476
"events": [
@@ -2592,11 +2593,14 @@
25922593
"HTTPHeaders": {},
25932594
"HTTPStatusCode": 200
25942595
}
2596+
},
2597+
"s3-object-content-body": {
2598+
"Dict": "Value"
25952599
}
25962600
}
25972601
},
25982602
"tests/aws/services/stepfunctions/v2/services/test_aws_sdk_task_service.py::TestTaskServiceAwsSdk::test_s3_put_object[list]": {
2599-
"recorded-date": "11-06-2024, 07:43:26",
2603+
"recorded-date": "13-12-2024, 15:21:44",
26002604
"recorded-content": {
26012605
"get_execution_history": {
26022606
"events": [
@@ -2722,11 +2726,12 @@
27222726
"HTTPHeaders": {},
27232727
"HTTPStatusCode": 200
27242728
}
2725-
}
2729+
},
2730+
"s3-object-content-body": "[\"List\",\"Data\"]"
27262731
}
27272732
},
27282733
"tests/aws/services/stepfunctions/v2/services/test_aws_sdk_task_service.py::TestTaskServiceAwsSdk::test_s3_put_object[bool]": {
2729-
"recorded-date": "11-06-2024, 07:43:42",
2734+
"recorded-date": "13-12-2024, 15:22:31",
27302735
"recorded-content": {
27312736
"get_execution_history": {
27322737
"events": [
@@ -2843,11 +2848,12 @@
28432848
"HTTPHeaders": {},
28442849
"HTTPStatusCode": 200
28452850
}
2846-
}
2851+
},
2852+
"s3-object-content-body": "false"
28472853
}
28482854
},
28492855
"tests/aws/services/stepfunctions/v2/services/test_aws_sdk_task_service.py::TestTaskServiceAwsSdk::test_s3_put_object[num]": {
2850-
"recorded-date": "11-06-2024, 07:43:58",
2856+
"recorded-date": "13-12-2024, 15:23:18",
28512857
"recorded-content": {
28522858
"get_execution_history": {
28532859
"events": [
@@ -2964,7 +2970,8 @@
29642970
"HTTPHeaders": {},
29652971
"HTTPStatusCode": 200
29662972
}
2967-
}
2973+
},
2974+
"s3-object-content-body": "0"
29682975
}
29692976
}
29702977
}

tests/aws/services/stepfunctions/v2/services/test_aws_sdk_task_service.validation.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@
2727
"last_validated_date": "2024-05-23T19:11:47+00:00"
2828
},
2929
"tests/aws/services/stepfunctions/v2/services/test_aws_sdk_task_service.py::TestTaskServiceAwsSdk::test_s3_put_object[bool]": {
30-
"last_validated_date": "2024-06-11T07:43:42+00:00"
30+
"last_validated_date": "2024-12-13T15:22:31+00:00"
3131
},
3232
"tests/aws/services/stepfunctions/v2/services/test_aws_sdk_task_service.py::TestTaskServiceAwsSdk::test_s3_put_object[dict]": {
33-
"last_validated_date": "2024-06-11T07:43:09+00:00"
33+
"last_validated_date": "2024-12-13T15:20:52+00:00"
3434
},
3535
"tests/aws/services/stepfunctions/v2/services/test_aws_sdk_task_service.py::TestTaskServiceAwsSdk::test_s3_put_object[list]": {
36-
"last_validated_date": "2024-06-11T07:43:26+00:00"
36+
"last_validated_date": "2024-12-13T15:21:44+00:00"
3737
},
3838
"tests/aws/services/stepfunctions/v2/services/test_aws_sdk_task_service.py::TestTaskServiceAwsSdk::test_s3_put_object[num]": {
39-
"last_validated_date": "2024-06-11T07:43:58+00:00"
39+
"last_validated_date": "2024-12-13T15:23:18+00:00"
4040
},
4141
"tests/aws/services/stepfunctions/v2/services/test_aws_sdk_task_service.py::TestTaskServiceAwsSdk::test_s3_put_object[str]": {
42-
"last_validated_date": "2024-06-11T07:42:53+00:00"
42+
"last_validated_date": "2024-12-13T15:20:04+00:00"
4343
},
4444
"tests/aws/services/stepfunctions/v2/services/test_aws_sdk_task_service.py::TestTaskServiceAwsSdk::test_sfn_send_task_outcome_with_no_such_token[state_machine_template0]": {
4545
"last_validated_date": "2024-04-10T18:55:26+00:00"

0 commit comments

Comments
 (0)