Exemple #1
0
    def test_bad_ip_ranges(self):
        doc = models.Library(None, "/libraries/foo")

        def test_ranges(test, expect):
            result = doc.find_bad_ip_ranges(test)
            assert result == expect

        test_ranges("", [])
        test_ranges("1.2.3.4", [])
        test_ranges("1.1.1.1\n2.2.2.2", [])
        test_ranges("1.1.1.1-2.2.2.2", [])
        test_ranges("1.1.1.1 # comment \n2.2.2.2", [])
        test_ranges("1.1.1.1\n # comment \n2.2.2.2", [])
        test_ranges("1.2.3.0/24", [])
        test_ranges("1.2.3.*", [])
        test_ranges("1.2.*.*", [])
        test_ranges("1.*.*.*", [])
        test_ranges("*", ["*"])
        test_ranges("*.1", ["*.1"])
        test_ranges("1.2.3-10.*", [])
        test_ranges("1.2.3.", [])
        test_ranges("1.1.", ['1.1.'])
        test_ranges("1.2.3.1-254", [])
        test_ranges("216.63.14.0/24\n207.193.121.0/24\n207.193.118.0/24", [])
        test_ranges("1.2.3.4,2.3.4.5", ["1.2.3.4,2.3.4.5"])
        test_ranges("1.2-3.*", ["1.2-3.*"])
Exemple #2
0
    def test_parse_ip_ranges(self):
        doc = models.Library(None, "/libraries/foo")

        def compare_ranges(test, expect):
            result = list(doc.parse_ip_ranges(test))
            assert result == expect

        compare_ranges("", [])
        compare_ranges("1.2.3.4", ["1.2.3.4"])
        compare_ranges("1.2.3.4", ["1.2.3.4"])
        compare_ranges("1.1.1.1\n2.2.2.2", ["1.1.1.1", "2.2.2.2"])
        compare_ranges("1.1.1.1-2.2.2.2", [("1.1.1.1", "2.2.2.2")])
        compare_ranges("1.1.1.1 # comment \n2.2.2.2", ["1.1.1.1", "2.2.2.2"])
        compare_ranges("1.1.1.1\n # comment \n2.2.2.2", ["1.1.1.1", "2.2.2.2"])
        compare_ranges("1.2.3.0/24", ["1.2.3.0/24"])
        compare_ranges("1.2.3.*", ["1.2.3.0/24"])
        compare_ranges("1.2.*.*", ["1.2.0.0/16"])
        compare_ranges("1.*.*.*", ["1.0.0.0/8"])
        compare_ranges("*", [])
        compare_ranges("*.1", [])
        compare_ranges("1.2.3-10.*", [("1.2.3.0", "1.2.10.255")])
        compare_ranges("1.2.3.", [("1.2.3.0", "1.2.3.255")])
        compare_ranges("1.1.", [])
        compare_ranges("1.2.3.1-254", [("1.2.3.1", "1.2.3.254")])
        compare_ranges(
            "216.63.14.0/24\n207.193.121.0/24\n207.193.118.0/24",
            ["216.63.14.0/24", "207.193.121.0/24", "207.193.118.0/24"])
        compare_ranges("208.70.20-30.", [])