How to use the pycfmodel.core.parse function in pycfmodel

To help you get started, we’ve selected a few pycfmodel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Skyscanner / cfripper / tests / test_rules_security_group_open_to_world.py View on Github external
def test_valid_security_group_not_slash0(self):
        role_props = {
            "AWSTemplateFormatVersion": "2010-09-09",
            "Resources": {
                "RootRole": {
                    "Type": "AWS::EC2::SecurityGroup",
                    "Properties": {"SecurityGroupIngress": [{"CidrIp": "10.0.0.0/8", "FromPort": 22, "ToPort": 22}]},
                }
            },
        }

        result = Result()
        rule = SecurityGroupOpenToWorldRule(None, result)
        resources = parse(role_props).resources
        rule.invoke(resources, [])

        assert result.valid
        assert len(result.failed_rules) == 0
github Skyscanner / cfripper / tests / test_rules_security_group_open_to_world.py View on Github external
role_props = {
            "AWSTemplateFormatVersion": "2010-09-09",
            "Resources": {
                "RootRole": {
                    "Type": "AWS::EC2::SecurityGroup",
                    "Properties": {
                        "SecurityGroupIngress": [{"CidrIp": {"Ref": "MyParam"}, "FromPort": 22, "ToPort": 22}]
                    },
                }
            },
        }

        result = Result()
        rule = SecurityGroupOpenToWorldRule(None, result)
        resources = parse(role_props).resources
        rule.invoke(resources, [])

        assert result.valid
        assert len(result.failed_rules) == 0
github Skyscanner / cfripper / tests / test_rules_security_group_open_to_world.py View on Github external
def test_valid_security_group_port80(self):
        role_props = {
            "AWSTemplateFormatVersion": "2010-09-09",
            "Resources": {
                "RootRole": {
                    "Type": "AWS::EC2::SecurityGroup",
                    "Properties": {"SecurityGroupIngress": [{"CidrIp": "0.0.0.0/0", "FromPort": 80, "ToPort": 80}]},
                }
            },
        }

        result = Result()
        rule = SecurityGroupOpenToWorldRule(None, result)
        resources = parse(role_props).resources
        rule.invoke(resources, [])

        assert result.valid
        assert len(result.failed_rules) == 0
github Skyscanner / cfripper / tests / test_rules_security_group_open_to_world.py View on Github external
"Resources": {
                "RootRole": {
                    "Type": "AWS::EC2::SecurityGroup",
                    "Properties": {
                        "SecurityGroupIngress": [
                            {"CidrIp": "10.0.0.0/8", "FromPort": 22, "ToPort": 22},
                            {"CidrIp": "0.0.0.0/0", "FromPort": 9090, "ToPort": 9090},
                        ]
                    },
                }
            },
        }

        result = Result()
        rule = SecurityGroupOpenToWorldRule(None, result)
        resources = parse(role_props).resources
        rule.invoke(resources, [])

        assert result.failed_rules[0].reason == 'Port 9090 open to the world in security group "RootRole"'
        assert result.failed_rules[0].rule == "SecurityGroupOpenToWorldRule"
github Skyscanner / cfripper / tests / test_rules_security_group_open_to_world.py View on Github external
def test_invalid_security_group_range(self):
        role_props = {
            "AWSTemplateFormatVersion": "2010-09-09",
            "Resources": {
                "RootRole": {
                    "Type": "AWS::EC2::SecurityGroup",
                    "Properties": {"SecurityGroupIngress": [{"CidrIp": "0.0.0.0/0", "FromPort": 0, "ToPort": 100}]},
                }
            },
        }

        result = Result()
        rule = SecurityGroupOpenToWorldRule(None, result)
        resources = parse(role_props).resources
        rule.invoke(resources, [])

        assert result.failed_rules[0].reason == "Ports 0 - 100 open in Security Group RootRole"
        assert result.failed_rules[0].rule == "SecurityGroupOpenToWorldRule"
github Skyscanner / cfripper / tests / test_rules_security_group_open_to_world.py View on Github external
def test_valid_security_group_port443(self):
        role_props = {
            "AWSTemplateFormatVersion": "2010-09-09",
            "Resources": {
                "RootRole": {
                    "Type": "AWS::EC2::SecurityGroup",
                    "Properties": {"SecurityGroupIngress": [{"CidrIp": "0.0.0.0/0", "FromPort": 443, "ToPort": 443}]},
                }
            },
        }

        result = Result()
        rule = SecurityGroupOpenToWorldRule(None, result)
        resources = parse(role_props).resources
        rule.invoke(resources, [])

        assert result.valid
        assert len(result.failed_rules) == 0
github Skyscanner / cfripper / tests / test_rules_security_group_open_to_world.py View on Github external
def test_security_group_type_slash0(self):
        role_props = {
            "AWSTemplateFormatVersion": "2010-09-09",
            "Resources": {
                "RootRole": {
                    "Type": "AWS::EC2::SecurityGroup",
                    "Properties": {"SecurityGroupIngress": [{"CidrIp": "0.0.0.0/0", "FromPort": 22, "ToPort": 22}]},
                }
            },
        }

        result = Result()
        rule = SecurityGroupOpenToWorldRule(None, result)
        resources = parse(role_props).resources
        rule.invoke(resources, [])

        assert not result.valid
        assert result.failed_rules[0].reason == 'Port 22 open to the world in security group "RootRole"'
        assert result.failed_rules[0].rule == "SecurityGroupOpenToWorldRule"
github Skyscanner / cfripper / tests / test_rules_security_group_open_to_world.py View on Github external
def test_invalid_security_group_cidripv6(self):
        role_props = {
            "AWSTemplateFormatVersion": "2010-09-09",
            "Resources": {
                "RootRole": {
                    "Type": "AWS::EC2::SecurityGroup",
                    "Properties": {"SecurityGroupIngress": [{"CidrIpv6": "::/0", "FromPort": 22, "ToPort": 22}]},
                }
            },
        }

        result = Result()
        rule = SecurityGroupOpenToWorldRule(None, result)
        resources = parse(role_props).resources
        rule.invoke(resources, [])

        assert result.failed_rules[0].reason == 'Port 22 open to the world in security group "RootRole"'
        assert result.failed_rules[0].rule == "SecurityGroupOpenToWorldRule"