diff --git a/moto/stepfunctions/parser/api.py b/moto/stepfunctions/parser/api.py index 96fe9859e81..173867900ff 100644 --- a/moto/stepfunctions/parser/api.py +++ b/moto/stepfunctions/parser/api.py @@ -268,8 +268,13 @@ class InvalidOutput(ServiceException): class InvalidToken(ServiceException): code: str = "InvalidToken" + exception_type: str = "UnrecognizedClientException" sender_fault: bool = False status_code: int = 400 + message: str = "The security token included in the request is invalid." + + def __init__(self): + super().__init__(self.message, self.exception_type, self.status_code) class InvalidTracingConfiguration(ServiceException): diff --git a/tests/test_stepfunctions/parser/test_stepfunctions_dynamodb_integration.py b/tests/test_stepfunctions/parser/test_stepfunctions_dynamodb_integration.py index 1fbd708d0cb..33eedf52846 100644 --- a/tests/test_stepfunctions/parser/test_stepfunctions_dynamodb_integration.py +++ b/tests/test_stepfunctions/parser/test_stepfunctions_dynamodb_integration.py @@ -6,6 +6,7 @@ import boto3 import pytest import requests +from botocore.exceptions import ClientError from moto import mock_aws @@ -240,3 +241,54 @@ def _verify_result(client, execution, execution_arn): exec_input=json.dumps(exec_input), sleep_time=sleep_time, ) + + +@aws_verified +@pytest.mark.aws_verified +def test_send_task_failure_invalid_token(table_name=None, sleep_time=0): + dynamodb = boto3.client("dynamodb", "us-east-1") + exec_input = {"TableName": table_name, "Item": {"id": {"S": "id1"}}} + + tmpl_name = "services/dynamodb_task_token" + + def _verify_result(client, execution, execution_arn): + if execution["status"] == "RUNNING": + items = dynamodb.scan(TableName=table_name)["Items"] + if len(items) > 0: + # Execute + with pytest.raises(ClientError) as exc: + client.send_task_failure(taskToken="bad_token", error="test error") + + # Verify + assert ( + exc.value.response["Error"]["Code"] == "UnrecognizedClientException" + ) + assert ( + exc.value.response["Error"]["Message"] + == "The security token included " + "in the request is invalid." + ) + + # Execute + with pytest.raises(ClientError) as exc: + client.send_task_success( + taskToken="bad_token", output="test output" + ) + + # Verify + assert ( + exc.value.response["Error"]["Code"] == "UnrecognizedClientException" + ) + assert ( + exc.value.response["Error"]["Message"] + == "The security token included " + "in the request is invalid." + ) + + verify_execution_result( + _verify_result, + expected_status=None, + tmpl_name=tmpl_name, + exec_input=json.dumps(exec_input), + sleep_time=sleep_time, + )