コード例 #1
0
    def test_header(self):
        networks = self.random_network_set(self.DEFAULT_NETWORK_COUNT)
        generator = generate_ipset(self.IPTABLES_NAME, networks)
        header = next(generator)

        # create blocklist0 hash:net family inet hashsize 32768 maxelem 65536
        matcher = re.match(r"""
            ^
            create\s+(?P<name>\w+)\s+
            hash:net\s+family\s+inet\s+
            hashsize\s+(?P<hashsize>\d+)\s+
            maxelem\s+(?P<maxelem>\d+)\s*
            $
            """, header, re.VERBOSE)
        assert matcher is not None, header

        elements = matcher.groupdict()
        for element in itervalues(elements):
            assert element is not None, elements
        elements["hashsize"] = int(elements["hashsize"])
        elements["maxelem"] = int(elements["maxelem"])

        assert elements["name"] == self.IPTABLES_NAME, elements
        assert elements["hashsize"] < elements["maxelem"], elements
        # noinspection PyTypeChecker
        assert elements["hashsize"] & (elements["hashsize"] - 1) == 0, elements
        assert elements["maxelem"] == self.DEFAULT_NETWORK_COUNT, elements
コード例 #2
0
    def test_header(self):
        networks = self.random_network_set(self.DEFAULT_NETWORK_COUNT)
        generator = generate_ipset(self.IPTABLES_NAME, networks)
        header = next(generator)

        # create blocklist0 hash:net family inet hashsize 32768 maxelem 65536
        matcher = re.match(
            r"""
            ^
            create\s+(?P<name>\w+)\s+
            hash:net\s+family\s+inet\s+
            hashsize\s+(?P<hashsize>\d+)\s+
            maxelem\s+(?P<maxelem>\d+)\s*
            $
            """, header, re.VERBOSE)
        assert matcher is not None, header

        elements = matcher.groupdict()
        for element in itervalues(elements):
            assert element is not None, elements
        elements["hashsize"] = int(elements["hashsize"])
        elements["maxelem"] = int(elements["maxelem"])

        assert elements["name"] == self.IPTABLES_NAME, elements
        assert elements["hashsize"] < elements["maxelem"], elements
        # noinspection PyTypeChecker
        assert elements["hashsize"] & (elements["hashsize"] - 1) == 0, elements
        assert elements["maxelem"] == self.DEFAULT_NETWORK_COUNT, elements
コード例 #3
0
    def test_content(self):
        networks = self.random_network_set(self.DEFAULT_NETWORK_COUNT)
        generator = generate_ipset(self.IPTABLES_NAME, networks)
        next(generator)

        collected_networks = []
        for line in generator:
            matcher = re.match(r"add\s+(?P<name>\w+)\s+(?P<network>.*)\s*",
                               line)
            assert matcher is not None, line

            elements = matcher.groupdict()
            for element in itervalues(elements):
                assert element is not None, elements
            assert elements["name"] == self.IPTABLES_NAME, line
            assert elements["network"] in networks, line
            collected_networks.append(elements["network"])

        assert len(collected_networks) == len(networks), collected_networks
        assert len(set(collected_networks)) == len(collected_networks), collected_networks
コード例 #4
0
    def test_content(self):
        networks = self.random_network_set(self.DEFAULT_NETWORK_COUNT)
        generator = generate_ipset(self.IPTABLES_NAME, networks)
        next(generator)

        collected_networks = []
        for line in generator:
            matcher = re.match(r"add\s+(?P<name>\w+)\s+(?P<network>.*)\s*",
                               line)
            assert matcher is not None, line

            elements = matcher.groupdict()
            for element in itervalues(elements):
                assert element is not None, elements
            assert elements["name"] == self.IPTABLES_NAME, line
            assert elements["network"] in networks, line
            collected_networks.append(elements["network"])

        assert len(collected_networks) == len(networks), collected_networks
        assert len(set(collected_networks)) == len(
            collected_networks), collected_networks