Ejemplo n.º 1
0
    def test_extract_port_flags(self):
        port_mappings = PortMappings()
        flags = extract_port_flags('foo -p 1234:1234 bar', port_mappings=port_mappings)
        self.assertEqual('foo  bar', flags)
        mapping_str = port_mappings.to_str()
        self.assertEqual('-p 1234:1234', mapping_str)

        port_mappings = PortMappings()
        flags = extract_port_flags('foo -p 1234:1234 bar -p 80-90:81-91 baz', port_mappings=port_mappings)
        self.assertEqual('foo  bar  baz', flags)
        mapping_str = port_mappings.to_str()
        self.assertIn('-p 1234:1234', mapping_str)
        self.assertIn('-p 80-90:81-91', mapping_str)
Ejemplo n.º 2
0
    def test_extract_port_flags(self):
        port_mappings = PortMappings()
        flags = extract_port_flags("foo -p 1234:1234 bar",
                                   port_mappings=port_mappings)
        self.assertEqual("foo  bar", flags)
        mapping_str = port_mappings.to_str()
        self.assertEqual("-p 1234:1234", mapping_str)

        port_mappings = PortMappings()
        flags = extract_port_flags("foo -p 1234:1234 bar -p 80-90:81-91 baz",
                                   port_mappings=port_mappings)
        self.assertEqual("foo  bar  baz", flags)
        mapping_str = port_mappings.to_str()
        self.assertIn("-p 1234:1234", mapping_str)
        self.assertIn("-p 80-90:81-91", mapping_str)
Ejemplo n.º 3
0
 def test_port_ranges_with_bind_host(self):
     port_mappings = PortMappings(bind_host="0.0.0.0")
     port_mappings.add(5000)
     port_mappings.add(5001)
     port_mappings.add(5003)
     result = port_mappings.to_str()
     self.assertEqual("-p 0.0.0.0:5000-5001:5000-5001 -p 0.0.0.0:5003:5003", result)
Ejemplo n.º 4
0
 def test_overlapping_port_ranges(self):
     port_mappings = PortMappings()
     port_mappings.add(4590)
     port_mappings.add(4591)
     port_mappings.add(4593)
     port_mappings.add(4592)
     port_mappings.add(4593)
     result = port_mappings.to_str()
     # assert that ranges are non-overlapping, i.e., no duplicate ports
     self.assertEqual('-p 4590-4592:4590-4592 -p 4593:4593', result)
Ejemplo n.º 5
0
    def test_port_mappings(self):
        map = PortMappings()
        map.add(123)
        self.assertEqual('-p 123:123', map.to_str())
        map.add(124)
        self.assertEqual('-p 123-124:123-124', map.to_str())
        map.add(234)
        self.assertEqual('-p 123-124:123-124 -p 234:234', map.to_str())
        map.add(345, 346)
        self.assertEqual('-p 123-124:123-124 -p 234:234 -p 345:346',
                         map.to_str())
        map.add([456, 458])
        self.assertEqual(
            '-p 123-124:123-124 -p 234:234 -p 345:346 -p 456-458:456-458',
            map.to_str())

        map = PortMappings()
        map.add([123, 124])
        self.assertEqual('-p 123-124:123-124', map.to_str())
        map.add([234, 237], [345, 348])
        self.assertEqual('-p 123-124:123-124 -p 234-237:345-348', map.to_str())