def setUp(self):
     self.workspace = Workspace()
     self.aws = self.workspace.add_aws(region='eu-west-1')
     self.vpc = self.aws.add_vpc(name='test-vpc')
Ejemplo n.º 2
0
def main(ctx, debug):
    g = {"workspace": Workspace()}
    with open("Touchdownfile") as f:
        code = compile(f.read(), "Touchdownfile", "exec")
        exec(code, g)
    ctx.obj = g['workspace']
class TestNetworkAclRules(unittest.TestCase):

    def setUp(self):
        self.workspace = Workspace()
        self.aws = self.workspace.add_aws(region='eu-west-1')
        self.vpc = self.aws.add_vpc(name='test-vpc')

    def test_simple_rule_with_all_ports(self):
        acl = self.vpc.add_network_acl(
            name='test-acl',
            inbound=[dict(
                network='10.0.0.0/20',
                protocol='tcp',
                port='*',
            )]
        )
        assert acl.inbound[0].port.start == 1
        assert acl.inbound[0].port.end == 65535

    def test_simple_rule_with_single_port(self):
        acl = self.vpc.add_network_acl(
            name='test-acl',
            inbound=[dict(
                network='10.0.0.0/20',
                protocol='tcp',
                port=20,
            )]
        )
        assert acl.inbound[0].port.start == 20
        assert acl.inbound[0].port.end == 20

    def test_simple_rule_with_port_range(self):
        acl = self.vpc.add_network_acl(
            name='test-acl',
            inbound=[dict(
                network='10.0.0.0/20',
                protocol='tcp',
                port__start=20,
                port__end=40,
            )]
        )
        assert acl.inbound[0].port.start == 20
        assert acl.inbound[0].port.end == 40

    def test_mixing_port_and_port__start(self):
        self.assertRaises(
            errors.InvalidParameter,
            self.vpc.add_network_acl,
            name='test-acl',
            inbound=[dict(
                network='10.0.0.0/20',
                protocol='tcp',
                port=20,
                port__start=20,
            )]
        )

    def test_mixing_port_and_port__end(self):
        self.assertRaises(
            errors.InvalidParameter,
            self.vpc.add_network_acl,
            name='test-acl',
            inbound=[dict(
                network='10.0.0.0/20',
                protocol='tcp',
                port=20,
                port__end=20,
            )]
        )