|
1 | 1 | import json
|
| 2 | +import logging |
2 | 3 | import os
|
3 | 4 |
|
4 | 5 | import pytest
|
|
163 | 164 | },
|
164 | 165 | }
|
165 | 166 |
|
| 167 | +LOG = logging.getLogger(__name__) |
| 168 | + |
166 | 169 |
|
167 | 170 | @pytest.fixture(scope="module")
|
168 | 171 | def setup_and_tear_down():
|
@@ -200,6 +203,24 @@ def setup_and_tear_down():
|
200 | 203 | testutil.delete_lambda_function(name=TEST_LAMBDA_NAME_5)
|
201 | 204 |
|
202 | 205 |
|
| 206 | +@pytest.fixture |
| 207 | +def create_state_machine(stepfunctions_client): |
| 208 | + machines_arns = [] |
| 209 | + |
| 210 | + def factory(**kwargs): |
| 211 | + result = stepfunctions_client.create_state_machine(**kwargs) |
| 212 | + machines_arns.append(result["stateMachineArn"]) |
| 213 | + return result |
| 214 | + |
| 215 | + yield factory |
| 216 | + |
| 217 | + for machine in machines_arns: |
| 218 | + try: |
| 219 | + stepfunctions_client.delete_state_machine(stateMachineArn=machine) |
| 220 | + except Exception as e: |
| 221 | + LOG.debug("Unable to delete SFN state machine: ", e) |
| 222 | + |
| 223 | + |
203 | 224 | def _assert_machine_instances(expected_instances, sfn_client):
|
204 | 225 | def check():
|
205 | 226 | state_machines_after = sfn_client.list_state_machines()["stateMachines"]
|
@@ -516,6 +537,17 @@ def check_invocations():
|
516 | 537 | },
|
517 | 538 | }
|
518 | 539 |
|
| 540 | +STS_ROLE_POLICY_DOC = { |
| 541 | + "Version": "2012-10-17", |
| 542 | + "Statement": [ |
| 543 | + { |
| 544 | + "Effect": "Allow", |
| 545 | + "Principal": {"Service": ["states.amazonaws.com"]}, |
| 546 | + "Action": "sts:AssumeRole", |
| 547 | + } |
| 548 | + ], |
| 549 | +} |
| 550 | + |
519 | 551 |
|
520 | 552 | @pytest.mark.parametrize("region_name", ("us-east-1", "us-east-2", "eu-west-1", "eu-central-1"))
|
521 | 553 | @pytest.mark.parametrize("statemachine_definition", (TEST_STATE_MACHINE_3,)) # TODO: add sync2 test
|
@@ -570,6 +602,31 @@ def assert_success():
|
570 | 602 | client1.delete_state_machine(stateMachineArn=child_machine_arn)
|
571 | 603 |
|
572 | 604 |
|
| 605 | +@pytest.mark.aws_validated |
| 606 | +def test_default_logging_configuration(iam_client, create_state_machine, stepfunctions_client): |
| 607 | + role_name = f"role_name-{short_uid()}" |
| 608 | + try: |
| 609 | + role_arn = iam_client.create_role( |
| 610 | + RoleName=role_name, |
| 611 | + AssumeRolePolicyDocument=json.dumps(STS_ROLE_POLICY_DOC), |
| 612 | + )["Role"]["Arn"] |
| 613 | + |
| 614 | + definition = clone(TEST_STATE_MACHINE) |
| 615 | + definition = json.dumps(definition) |
| 616 | + |
| 617 | + sm_name = f"sts-logging-{short_uid()}" |
| 618 | + result = create_state_machine(name=sm_name, definition=definition, roleArn=role_arn) |
| 619 | + |
| 620 | + assert result["ResponseMetadata"]["HTTPStatusCode"] == 200 |
| 621 | + result = stepfunctions_client.describe_state_machine( |
| 622 | + stateMachineArn=result["stateMachineArn"] |
| 623 | + ) |
| 624 | + assert result["ResponseMetadata"]["HTTPStatusCode"] == 200 |
| 625 | + assert result["loggingConfiguration"] == {"level": "OFF", "includeExecutionData": False} |
| 626 | + finally: |
| 627 | + iam_client.delete_role(RoleName=role_name) |
| 628 | + |
| 629 | + |
573 | 630 | def test_aws_sdk_task(stepfunctions_client, iam_client, sns_client):
|
574 | 631 | statemachine_definition = {
|
575 | 632 | "StartAt": "CreateTopicTask",
|
|
0 commit comments