Exemplo n.º 1
0
def test_agent_aws_wafv2_regional_cloudfront():

    config = AWSConfig('hostname', [], (None, None))

    region = 'region'
    wafv2_limits_regional = WAFV2Limits(None, region, config, 'REGIONAL')
    assert wafv2_limits_regional._region_report == region

    wafv2_limits_regional = WAFV2Limits(None, 'us-east-1', config, 'CLOUDFRONT')
    assert wafv2_limits_regional._region_report == 'CloudFront'

    with pytest.raises(AssertionError):
        WAFV2Limits(None, 'region', config, 'CLOUDFRONT')
        WAFV2Limits(None, 'region', config, 'WRONG')
        WAFV2WebACL(None, 'region', config, False)

    assert len(WAFV2WebACL(None, 'region', config, True)._metric_dimensions) == 3
    assert len(WAFV2WebACL(None, 'us-east-1', config, False)._metric_dimensions) == 2
Exemplo n.º 2
0
def test_agent_aws_wafv2_regional_cloudfront():

    config = AWSConfig("hostname", [], (None, None))

    region = "region"
    wafv2_limits_regional = WAFV2Limits(None, region, config, "REGIONAL")
    assert wafv2_limits_regional._region_report == region

    wafv2_limits_regional = WAFV2Limits(None, "us-east-1", config,
                                        "CLOUDFRONT")
    assert wafv2_limits_regional._region_report == "CloudFront"

    with pytest.raises(AssertionError):
        WAFV2Limits(None, "region", config, "CLOUDFRONT")
        WAFV2Limits(None, "region", config, "WRONG")
        WAFV2WebACL(None, "region", config, False)

    assert len(WAFV2WebACL(None, "region", config,
                           True)._metric_dimensions) == 3
    assert len(
        WAFV2WebACL(None, "us-east-1", config, False)._metric_dimensions) == 2
Exemplo n.º 3
0
def create_sections(names, tags, is_regional):

    if is_regional:
        region = "region"
        scope = "REGIONAL"
    else:
        region = "us-east-1"
        scope = "CLOUDFRONT"

    config = AWSConfig("hostname", [], (None, None))
    config.add_single_service_config("wafv2_names", names)
    config.add_service_tags("wafv2_tags", tags)

    fake_wafv2_client = FakeWAFV2Client()
    fake_cloudwatch_client = FakeCloudwatchClient()

    wafv2_limits_distributor = ResultDistributor()
    wafv2_summary_distributor = ResultDistributor()

    wafv2_limits = WAFV2Limits(fake_wafv2_client,
                               region,
                               config,
                               scope,
                               distributor=wafv2_limits_distributor)
    wafv2_summary = WAFV2Summary(fake_wafv2_client,
                                 region,
                                 config,
                                 scope,
                                 distributor=wafv2_summary_distributor)
    wafv2_web_acl = WAFV2WebACL(fake_cloudwatch_client, region, config,
                                is_regional)

    wafv2_limits_distributor.add(wafv2_summary)
    wafv2_summary_distributor.add(wafv2_web_acl)

    return {
        "wafv2_limits": wafv2_limits,
        "wafv2_summary": wafv2_summary,
        "wafv2_web_acl": wafv2_web_acl,
    }
Exemplo n.º 4
0
def create_sections(names, tags, is_regional):

    if is_regional:
        region = 'region'
        scope = 'REGIONAL'
    else:
        region = 'us-east-1'
        scope = 'CLOUDFRONT'

    config = AWSConfig('hostname', [], (None, None))
    config.add_single_service_config('wafv2_names', names)
    config.add_service_tags('wafv2_tags', tags)

    fake_wafv2_client = FakeWAFV2Client()
    fake_cloudwatch_client = FakeCloudwatchClient()

    wafv2_limits_distributor = ResultDistributor()
    wafv2_summary_distributor = ResultDistributor()

    wafv2_limits = WAFV2Limits(fake_wafv2_client,
                               region,
                               config,
                               scope,
                               distributor=wafv2_limits_distributor)
    wafv2_summary = WAFV2Summary(fake_wafv2_client,
                                 region,
                                 config,
                                 scope,
                                 distributor=wafv2_summary_distributor)
    wafv2_web_acl = WAFV2WebACL(fake_cloudwatch_client, region, config,
                                is_regional)

    wafv2_limits_distributor.add(wafv2_summary)
    wafv2_summary_distributor.add(wafv2_web_acl)

    return {
        'wafv2_limits': wafv2_limits,
        'wafv2_summary': wafv2_summary,
        'wafv2_web_acl': wafv2_web_acl,
    }