Skip to content

Commit

Permalink
StepFunction: fix error msg (#7629)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafcio19 committed Apr 27, 2024
1 parent f58a575 commit e51192b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
5 changes: 5 additions & 0 deletions moto/stepfunctions/parser/api.py
Expand Up @@ -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):
Expand Down
Expand Up @@ -6,6 +6,7 @@
import boto3
import pytest
import requests
from botocore.exceptions import ClientError

from moto import mock_aws

Expand Down Expand Up @@ -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,
)

0 comments on commit e51192b

Please sign in to comment.