Repository: qpid-dispatch Updated Branches: refs/heads/crolke-DISPATCH-188-1 b813de1f1 -> 2766ff113
Add HostAddr wildcard support Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/2766ff11 Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/2766ff11 Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/2766ff11 Branch: refs/heads/crolke-DISPATCH-188-1 Commit: 2766ff113ff1b9b218dae1ff4a38d3f3e0510ca3 Parents: b813de1 Author: Chuck Rolke <[email protected]> Authored: Wed Dec 9 15:47:14 2015 -0500 Committer: Chuck Rolke <[email protected]> Committed: Wed Dec 9 15:47:14 2015 -0500 ---------------------------------------------------------------------- .../qpid_dispatch_internal/management/policy.py | 37 +++++++++++++------- tests/policy-1/policy-photoserver.conf | 1 + tests/system_tests_policy.py | 15 ++++++++ 3 files changed, 40 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/2766ff11/python/qpid_dispatch_internal/management/policy.py ---------------------------------------------------------------------- diff --git a/python/qpid_dispatch_internal/management/policy.py b/python/qpid_dispatch_internal/management/policy.py index ffeb2f3..74a3b0d 100644 --- a/python/qpid_dispatch_internal/management/policy.py +++ b/python/qpid_dispatch_internal/management/policy.py @@ -197,21 +197,28 @@ class HostAddr(): """ self.hoststructs = [] - hosts = [x.strip() for x in hostspec.split(",")] - - # hosts must contain one or two host specs - if len(hosts) not in [1, 2]: - raise PolicyError("hostspec must contain 1 or 2 host names") - self.hoststructs.append(HostStruct(hosts[0])) - if len(hosts) > 1: - self.hoststructs.append(HostStruct(hosts[1])) - if not self.hoststructs[0].family == self.hoststructs[1].family: - raise PolicyError("mixed IPv4 and IPv6 host specs in range not allowed") - c0 = self.memcmp(self.hoststructs[0].binary, self.hoststructs[1].binary) - if c0 > 0: - raise PolicyError("host specs in range must have lower numeric address first") + if hostspec == "*": + self.wildcard = True + else: + self.wildcard = False + + hosts = [x.strip() for x in hostspec.split(",")] + + # hosts must contain one or two host specs + if len(hosts) not in [1, 2]: + raise PolicyError("hostspec must contain 1 or 2 host names") + self.hoststructs.append(HostStruct(hosts[0])) + if len(hosts) > 1: + self.hoststructs.append(HostStruct(hosts[1])) + if not self.hoststructs[0].family == self.hoststructs[1].family: + raise PolicyError("mixed IPv4 and IPv6 host specs in range not allowed") + c0 = self.memcmp(self.hoststructs[0].binary, self.hoststructs[1].binary) + if c0 > 0: + raise PolicyError("host specs in range must have lower numeric address first") def __str__(self): + if self.wildcard: + return "*" res = self.hoststructs[0].name if len(self.hoststructs) > 1: res += "," + self.hoststructs[1].name @@ -221,6 +228,8 @@ class HostAddr(): return self.__str__() def dump(self): + if self.wildcard: + return "(*)" res = "(" + self.hoststructs[0].dump() if len(self.hoststructs) > 1: res += "," + self.hoststructs[1].dump() @@ -244,6 +253,8 @@ class HostAddr(): @param[in] cstruct the IP address to be tested @return candidate matches this or not """ + if self.wildcard: + return True try: if not cstruct.family == self.hoststructs[0].family: # sorry, wrong AF_INET family http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/2766ff11/tests/policy-1/policy-photoserver.conf ---------------------------------------------------------------------- diff --git a/tests/policy-1/policy-photoserver.conf b/tests/policy-1/policy-photoserver.conf index 621d417..59a373a 100644 --- a/tests/policy-1/policy-photoserver.conf +++ b/tests/policy-1/policy-photoserver.conf @@ -51,6 +51,7 @@ connectionOrigins: { 'EllensWS': ['72.135.2.9'], 'TheLabs': ['10.48.0.0,10.48.255.255','192.168.100.0,192.168.100.255'], 'Localhost': ['127.0.0.1','::1'], + 'TheWorld': ['*'] } # connectionPolicy is a map. http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/2766ff11/tests/system_tests_policy.py ---------------------------------------------------------------------- diff --git a/tests/system_tests_policy.py b/tests/system_tests_policy.py index 6e2878c..1661d22 100644 --- a/tests/system_tests_policy.py +++ b/tests/system_tests_policy.py @@ -131,6 +131,21 @@ class PolicyHostAddrTest(TestCase): self.check_hostaddr_match(ccc, "ffff:ffff::1", False) self.check_hostaddr_match(ccc, "ffff:ffff:ffff:ffff::ffff", False) + def test_policy_hostaddr_ipv4_wildcard(self): + aaa = HostAddr("*") + self.check_hostaddr_match(aaa,"0.0.0.0") + self.check_hostaddr_match(aaa,"127.0.0.1") + self.check_hostaddr_match(aaa,"255.254.253.252") + + + def test_policy_hostaddr_ipv6_wildcard(self): + if not HostAddr.has_ipv6: + self.skipTest("System IPv6 support is not available") + aaa = HostAddr("*") + self.check_hostaddr_match(aaa,"::0") + self.check_hostaddr_match(aaa,"::1") + self.check_hostaddr_match(aaa,"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff") + def test_policy_malformed_hostaddr_ipv4(self): self.expect_deny( "0.0.0.0.0", "Name or service not known") self.expect_deny( "1.1.1.1,2.2.2.2,3.3.3.3", "arg count") --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
