Esempio n. 1
0
def test_EventBatch_create_events():
    # setup playbook
    iam_client = boto3.client("iam", region_name="us-east-1")
    sts_client = boto3.client("sts", region_name="us-east-1")
    iam_role_name = "new-user"
    iam_role_arn = iam_client.role_arn = iam_client.create_role(
        RoleName=iam_role_name,
        AssumeRolePolicyDocument=json.dumps(iam_trust_policy_document),
    )["Role"]["Arn"]

    client = boto3.client("stepfunctions")
    sm = client.create_state_machine(name="ParamsToStateMachineTester",
                                     definition=str(playbook_definition),
                                     roleArn=iam_role_arn)

    batched_event = EventBatch(MOCK_EVENT_BATCH, MockLambdaContext())

    result = batched_event.create_events()

    #! FIX: result['status'] is always true, message is a list of individual
    #! playbook responses that may be true or false (error) responses
    assert result['status'] == True

    assert result['message'][0]['status'] == True
    assert result['message'][1]['status'] == True
Esempio n. 2
0
def test_EventBatch_execute_playbook_failure():
    edited_event = deepcopy(MOCK_EVENT_BATCH)
    edited_event['playbook'] = 'bad_playbook'

    batched_event = EventBatch(edited_event, MockLambdaContext())
    result = batched_event.execute_playbook(
        convert_empty_strings_to_none(MOCK_EVENT))

    assert result['status'] == False
Esempio n. 3
0
def test_EventBatch_missing_details():
    bad_mock_event_batch = deepcopy(MOCK_EVENT_BATCH)
    del bad_mock_event_batch['details']
    del bad_mock_event_batch['playbook']

    batched_event = EventBatch(bad_mock_event_batch, MockLambdaContext())

    assert batched_event.playbook == ""
    assert batched_event.details == [{}]
Esempio n. 4
0
def test_EventBatch():
    batched_event = EventBatch(MOCK_EVENT_BATCH, MockLambdaContext())

    assert batched_event.event_type == MOCK_EVENT_BATCH['event_type']
    assert batched_event.created_at == None  # created_at not supplied in mock
    assert batched_event.details == MOCK_EVENT_BATCH['details']
    assert batched_event.data_types == {}  # created_at not supplied in mock
    assert batched_event.dedup_keys == MOCK_EVENT_BATCH['dedup_keys']
    assert batched_event.event_meta == {}
    assert batched_event.playbook == MOCK_EVENT_BATCH['playbook']
Esempio n. 5
0
def test_EventBatch_execute_playbook():
    # setup playbook
    iam_client = boto3.client("iam", region_name="us-east-1")
    sts_client = boto3.client("sts", region_name="us-east-1")
    iam_role_name = "new-user"
    iam_role_arn = iam_client.role_arn = iam_client.create_role(
        RoleName=iam_role_name,
        AssumeRolePolicyDocument=json.dumps(iam_trust_policy_document),
    )["Role"]["Arn"]

    client = boto3.client("stepfunctions")
    sm = client.create_state_machine(name="ParamsToStateMachineTester",
                                     definition=str(playbook_definition),
                                     roleArn=iam_role_arn)

    batched_event = EventBatch(MOCK_EVENT_BATCH, MockLambdaContext())
    result = batched_event.execute_playbook(
        convert_empty_strings_to_none(MOCK_EVENT))

    assert result['status'] == True
    assert isinstance(result['message']['execution_id'], str)
    assert isinstance(result['message']['investigation_id'], str)
Esempio n. 6
0
def test_EventBatch_fails_on_invalid_type_for_dedup_keys():
    bad_mock_event_batch = deepcopy(MOCK_EVENT_BATCH)
    bad_mock_event_batch['dedup_keys'] = 'bad_arg_type'

    with pytest.raises(Exception):
        batched_event = EventBatch(bad_mock_event_batch, MockLambdaContext())
Esempio n. 7
0
def test_EventBatch_invalid_playbook_type():
    bad_mock_event_batch = deepcopy(MOCK_EVENT_BATCH)
    bad_mock_event_batch['playbook'] = ['bad_arg']

    with pytest.raises(Exception):
        batched_event = EventBatch(bad_mock_event_batch, MockLambdaContext())
Esempio n. 8
0
def test_EventBatch_invalid_details_type():
    bad_mock_event_batch = deepcopy(MOCK_EVENT_BATCH)
    bad_mock_event_batch['details'] = 'bad_arg'

    with pytest.raises(Exception):
        batched_event = EventBatch(bad_mock_event_batch, MockLambdaContext())