Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[SFN][TestState] Make roleArn optional#13459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tiurin merged 7 commits intomainfromsfn/feat/test-state-optional-role
Dec 3, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,6 +24,9 @@
from localstack.services.stepfunctions.asl.component.state.state_execution.state_task.service.state_task_service_api_gateway import (
StateTaskServiceApiGateway,
)
from localstack.services.stepfunctions.asl.component.state.state_execution.state_task.state_task import (
StateTask,
)
from localstack.services.stepfunctions.asl.component.state.state_type import StateType
from localstack.services.stepfunctions.asl.component.test_state.program.test_state_program import (
TestStateProgram,
Expand DownExpand Up@@ -58,6 +61,15 @@ def is_state_in_definition(definition: Definition, state_name: StateName) -> boo

return test_program.test_state is not None

@staticmethod
def validate_role_arn_required(
mock_input: MockInput, definition: Definition, state_name: StateName
) -> None:
test_program, _ = TestStateAmazonStateLanguageParser.parse(definition, state_name)
test_state = test_program.test_state
if isinstance(test_state, StateTask) and mock_input is None:
raise ValidationException("RoleArn must be specified when testing a Task state")

@staticmethod
def validate_mock(mock_input: MockInput, definition: Definition, state_name: StateName) -> None:
test_program, _ = TestStateAmazonStateLanguageParser.parse(definition, state_name)
Expand Down
22 changes: 20 additions & 2 deletionslocalstack-core/localstack/services/stepfunctions/provider.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -162,6 +162,7 @@
normalise_max_results,
)
from localstack.state import StateVisitor
from localstack.utils.aws import arns
from localstack.utils.aws.arns import (
ARN_PARTITION_REGEX,
stepfunctions_activity_arn,
Expand DownExpand Up@@ -1543,10 +1544,27 @@ def test_state(
arn = stepfunctions_state_machine_arn(
name=name, account_id=context.account_id, region_name=context.region
)
role_arn = request.get("roleArn")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Do you know if theroleArn param requires any special validations?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I plan to investigate it later, also noticed the lack of validation.

if role_arn is None:
TestStateStaticAnalyser.validate_role_arn_required(
mock_input=mock_input, definition=definition, state_name=state_name
)
# HACK: Added dummy role ARN because it is a required field in Execution.
# To allow optional roleArn for the test state but preserve the mandatory one for regular executions
# we likely need to remove inheritance TestStateExecution(Execution) in favor of composition.
# TestState execution starts to have too many simplifications compared to a regular execution
# which renders the inheritance mechanism harmful.
# TODO make role_arn optional in TestStateExecution
role_arn = arns.iam_role_arn(
role_name=f"RoleFor-{name}",
account_id=context.account_id,
region_name=context.region,
)

state_machine = TestStateMachine(
name=name,
arn=arn,
role_arn=request["roleArn"],
role_arn=role_arn,
definition=request["definition"],
)

Expand All@@ -1561,7 +1579,7 @@ def test_state(

execution = TestStateExecution(
name=exec_name,
role_arn=request["roleArn"],
role_arn=role_arn,
exec_arn=exec_arn,
account_id=context.account_id,
region_name=context.region,
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,9 +32,7 @@ class TestFieldValidationMode:
@pytest.mark.parametrize("result", EVENTBRIDGE_VALIDATION_PASS_FIELDS_NOT_IN_SPEC)
def test_strict_mode_mock_result_field_not_in_api_spec(
self,
aws_client,
aws_client_no_sync_prefix,
create_state_machine_iam_role,
sfn_snapshot,
result,
):
Expand All@@ -55,11 +53,8 @@ def test_strict_mode_mock_result_field_not_in_api_spec(

mock = {"result": json.dumps(result)}

sfn_role_arn = create_state_machine_iam_role(aws_client)

test_case_response = aws_client_no_sync_prefix.stepfunctions.test_state(
definition=definition,
roleArn=sfn_role_arn,
input=exec_input,
inspectionLevel=InspectionLevel.INFO,
mock=mock,
Expand DownExpand Up@@ -96,7 +91,6 @@ def test_strict_mode_eventbridge_task(
self,
aws_client,
aws_client_no_sync_prefix,
create_state_machine_iam_role,
sfn_snapshot,
result,
):
Expand All@@ -114,12 +108,9 @@ def test_strict_mode_eventbridge_task(

mock = {"result": json.dumps(result)}

sfn_role_arn = create_state_machine_iam_role(aws_client)

with pytest.raises(aws_client.stepfunctions.exceptions.ValidationException) as e:
aws_client_no_sync_prefix.stepfunctions.test_state(
definition=definition,
roleArn=sfn_role_arn,
input=exec_input,
inspectionLevel=InspectionLevel.INFO,
mock=mock,
Expand DownExpand Up@@ -151,7 +142,6 @@ def test_strict_mode_sfn_task(
self,
aws_client,
aws_client_no_sync_prefix,
create_state_machine_iam_role,
account_id,
region_name,
sfn_snapshot,
Expand All@@ -176,12 +166,9 @@ def test_strict_mode_sfn_task(

mock = {"result": json.dumps(result)}

sfn_role_arn = create_state_machine_iam_role(aws_client)

with pytest.raises(aws_client.stepfunctions.exceptions.ValidationException) as e:
aws_client_no_sync_prefix.stepfunctions.test_state(
definition=definition,
roleArn=sfn_role_arn,
input=exec_input,
inspectionLevel=InspectionLevel.INFO,
mock=mock,
Expand All@@ -201,9 +188,6 @@ def test_strict_mode_lambda_task(
self,
aws_client,
aws_client_no_sync_prefix,
create_state_machine_iam_role,
account_id,
region_name,
sfn_snapshot,
result,
):
Expand All@@ -213,12 +197,9 @@ def test_strict_mode_lambda_task(

mock = {"result": json.dumps(result)}

sfn_role_arn = create_state_machine_iam_role(aws_client)

with pytest.raises(aws_client.stepfunctions.exceptions.ValidationException) as e:
aws_client_no_sync_prefix.stepfunctions.test_state(
definition=definition,
roleArn=sfn_role_arn,
input=exec_input,
inspectionLevel=InspectionLevel.INFO,
mock=mock,
Expand All@@ -238,9 +219,6 @@ def test_strict_mode_dynamodb_task(
self,
aws_client,
aws_client_no_sync_prefix,
create_state_machine_iam_role,
account_id,
region_name,
sfn_snapshot,
result,
):
Expand All@@ -255,12 +233,9 @@ def test_strict_mode_dynamodb_task(

mock = {"result": json.dumps(result)}

sfn_role_arn = create_state_machine_iam_role(aws_client)

with pytest.raises(aws_client.stepfunctions.exceptions.ValidationException) as e:
aws_client_no_sync_prefix.stepfunctions.test_state(
definition=definition,
roleArn=sfn_role_arn,
input=exec_input,
inspectionLevel=InspectionLevel.INFO,
mock=mock,
Expand All@@ -284,9 +259,6 @@ def test_strict_mode_aws_sdk_s3_task(
self,
aws_client,
aws_client_no_sync_prefix,
create_state_machine_iam_role,
account_id,
region_name,
sfn_snapshot,
result,
):
Expand All@@ -296,12 +268,9 @@ def test_strict_mode_aws_sdk_s3_task(

mock = {"result": json.dumps(result)}

sfn_role_arn = create_state_machine_iam_role(aws_client)

with pytest.raises(aws_client.stepfunctions.exceptions.ValidationException) as e:
aws_client_no_sync_prefix.stepfunctions.test_state(
definition=definition,
roleArn=sfn_role_arn,
input=exec_input,
inspectionLevel=InspectionLevel.INFO,
mock=mock,
Expand DownExpand Up@@ -329,9 +298,6 @@ def test_strict_mode_aws_sdk_kms_task(
self,
aws_client,
aws_client_no_sync_prefix,
create_state_machine_iam_role,
account_id,
region_name,
sfn_snapshot,
result,
):
Expand All@@ -341,12 +307,9 @@ def test_strict_mode_aws_sdk_kms_task(

mock = {"result": json.dumps(result)}

sfn_role_arn = create_state_machine_iam_role(aws_client)

with pytest.raises(aws_client.stepfunctions.exceptions.ValidationException) as e:
aws_client_no_sync_prefix.stepfunctions.test_state(
definition=definition,
roleArn=sfn_role_arn,
input=exec_input,
inspectionLevel=InspectionLevel.INFO,
mock=mock,
Expand All@@ -373,9 +336,6 @@ def test_strict_mode_aws_sdk_lambda_get_function_task(
self,
aws_client,
aws_client_no_sync_prefix,
create_state_machine_iam_role,
account_id,
region_name,
sfn_snapshot,
result,
):
Expand All@@ -385,12 +345,9 @@ def test_strict_mode_aws_sdk_lambda_get_function_task(

mock = {"result": json.dumps(result)}

sfn_role_arn = create_state_machine_iam_role(aws_client)

with pytest.raises(aws_client.stepfunctions.exceptions.ValidationException) as e:
aws_client_no_sync_prefix.stepfunctions.test_state(
definition=definition,
roleArn=sfn_role_arn,
input=exec_input,
inspectionLevel=InspectionLevel.INFO,
mock=mock,
Expand Down
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp