Exemplo n.º 1
0
def test_lite_bucket_schema_for_events(historical_table, bucket_event):
    old_fields = CONFIG.exclude_fields
    CONFIG.exclude_fields = "Name,_version,Grants,LifecycleRules,Logging,Policy,Tags,Versioning,Website,Cors," \
                            "Notifications,Acceleration,Replication,CreationDate,AnalyticsConfigurations," \
                            "MetricsConfigurations,InventoryConfigurations".split(",")

    all_buckets = CurrentS3Model.scan()
    generated_report = S3ReportSchema(strict=True).dump({"all_buckets": all_buckets}).data

    generated_report["all_buckets"] = []
    process_dynamodb_record(bucket_event["Records"][0], generated_report)

    lite_report = S3ReportSchema(strict=True).dump(generated_report).data

    assert lite_report["generated_date"]
    assert lite_report["s3_report_version"] == CONFIG.s3_reports_version
    assert not lite_report.get("all_buckets")

    assert lite_report["buckets"]["testbucketNEWBUCKET"]
    assert len(lite_report["buckets"]) == 11

    for bucket in lite_report["buckets"].values():
        keys = bucket.keys()
        for excluded in CONFIG.exclude_fields:
            assert excluded not in keys

        assert bucket["AccountId"] == "123456789012"
        assert bucket["Region"] == "us-east-1"

    # Clean-up:
    CONFIG.exclude_fields = old_fields
Exemplo n.º 2
0
def test_process_dynamodb_record(bucket_event, generated_report, change_type):
    bucket_event["Records"][0]["eventName"] = change_type
    generated_report["all_buckets"] = []

    process_dynamodb_record(bucket_event["Records"][0], generated_report)

    assert len(generated_report["all_buckets"]) == 1
    assert generated_report["all_buckets"][0].region == "us-east-1"
Exemplo n.º 3
0
def test_process_dynamodb_record_ttl(ttl_event, generated_report):
    generated_report["all_buckets"] = []
    process_dynamodb_record(ttl_event["Records"][0], generated_report)

    # Should not do anything -- since not present in the list:
    assert not generated_report["all_buckets"]

    generated_report["buckets"]["testbucketNEWBUCKET"] = {"some configuration": "this should be deleted"}
    process_dynamodb_record(ttl_event["Records"][0], generated_report)
    assert not generated_report["buckets"].get("testbucketNEWBUCKET")
Exemplo n.º 4
0
def test_bucket_schema_for_events(historical_table, generated_report, bucket_event):
    generated_report["all_buckets"] = []
    process_dynamodb_record(bucket_event["Records"][0], generated_report)

    full_report = S3ReportSchema(strict=True).dump(generated_report).data

    assert full_report["generated_date"]
    assert full_report["s3_report_version"] == CONFIG.s3_reports_version
    assert not full_report.get("all_buckets")

    assert full_report["buckets"]["testbucketNEWBUCKET"]
    assert len(full_report["buckets"]) == 11

    for name, value in full_report["buckets"].items():
        assert value["AccountId"] == "123456789012"
        assert value["Region"] == "us-east-1"
        assert value["Tags"]["theBucketName"] == name
        assert not value.get("_version")
        assert not value.get("Name")
Exemplo n.º 5
0
def test_process_dynamodb_record_deletion(delete_bucket_event, generated_report):
    generated_report["all_buckets"] = []
    process_dynamodb_record(delete_bucket_event["Records"][0], generated_report)

    # Should not do anything -- since not present in the list:
    assert not generated_report["all_buckets"]

    # Check if removal logic works:
    generated_report["buckets"]["testbucketNEWBUCKET"] = {"some configuration": "this should be deleted"}

    # If we receive a removal event that is NOT from a TTL, that should not have any effect:
    delete_bucket_event["Records"][0]["eventName"] = "REMOVE"
    process_dynamodb_record(delete_bucket_event["Records"][0], generated_report)
    assert generated_report["buckets"]["testbucketNEWBUCKET"]

    # Standard "MODIFY" for deletion:
    delete_bucket_event["Records"][0]["eventName"] = "MODIFY"
    process_dynamodb_record(delete_bucket_event["Records"][0], generated_report)
    assert not generated_report["buckets"].get("testbucketNEWBUCKET")