def test_is_valid_no_proxy(self): proxy0 = 'a' * 63 + '.' + '0' * 63 + '.c.' + 'd' * 61 + '.' + 'e' * 61 proxy1 = 'A' * 63 + '.' + '0' * 63 + '.C.' + 'D' * 61 + '.' + 'E' * 61 proxy2 = ('A' * 64 + '.' + '0' * 63 + '.C.' + 'D' * 61 + '.' + 'E' * 61) # too long (> 253) proxy3 = 'a' * 100 proxy4 = 'a..com' proxy5 = ('.' + 'a' * 62 + '.' + '0' * 62 + '.c.' + 'd' * 61 + '.' + 'e' * 61) proxy6 = ('.' + 'a' * 63 + '.' + '0' * 62 + '.c.' + 'd' * 61 + '.' + 'e' * 61) # too long (> 251 after deleting .) proxy7 = ('*.' + 'a' * 60 + '.' + '0' * 60 + '.c.' + 'd' * 61 + '.' + 'e' * 61) # starts with *. proxy8 = 'c.-a.com' proxy9 = 'c.a-.com' proxy10 = ',,example.com:3128,' valid_with_whitespaces = ' , '.join([proxy0, proxy1, proxy5, proxy10]) all_valid = ','.join([proxy0, proxy1, proxy5, proxy10]) self.assertTrue(utils.is_valid_no_proxy(all_valid)) self.assertTrue(utils.is_valid_no_proxy(valid_with_whitespaces)) self.assertFalse(utils.is_valid_no_proxy(proxy2)) self.assertFalse(utils.is_valid_no_proxy(proxy3)) self.assertFalse(utils.is_valid_no_proxy(proxy4)) self.assertFalse(utils.is_valid_no_proxy(proxy6)) self.assertFalse(utils.is_valid_no_proxy(proxy7)) self.assertFalse(utils.is_valid_no_proxy(proxy8)) self.assertFalse(utils.is_valid_no_proxy(proxy9))
def test_is_valid_no_proxy(self): proxy0 = 'a' * 63 + '.' + '0' * 63 + '.c.' + 'd' * 61 + '.' + 'e' * 61 proxy1 = 'A' * 63 + '.' + '0' * 63 + '.C.' + 'D' * 61 + '.' + 'E' * 61 proxy2 = ('A' * 64 + '.' + '0' * 63 + '.C.' + 'D' * 61 + '.' + 'E' * 61 ) # too long (> 253) proxy3 = 'a' * 100 proxy4 = 'a..com' proxy5 = ('.' + 'a' * 62 + '.' + '0' * 62 + '.c.' + 'd' * 61 + '.' + 'e' * 61) proxy6 = ('.' + 'a' * 63 + '.' + '0' * 62 + '.c.' + 'd' * 61 + '.' + 'e' * 61) # too long (> 251 after deleting .) proxy7 = ('*.' + 'a' * 60 + '.' + '0' * 60 + '.c.' + 'd' * 61 + '.' + 'e' * 61) # starts with *. proxy8 = 'c.-a.com' proxy9 = 'c.a-.com' proxy10 = ',,example.com:3128,' valid_with_whitespaces = ' , '.join([proxy0, proxy1, proxy5, proxy10]) all_valid = ','.join([proxy0, proxy1, proxy5, proxy10]) self.assertTrue(utils.is_valid_no_proxy(all_valid)) self.assertTrue(utils.is_valid_no_proxy(valid_with_whitespaces)) self.assertFalse(utils.is_valid_no_proxy(proxy2)) self.assertFalse(utils.is_valid_no_proxy(proxy3)) self.assertFalse(utils.is_valid_no_proxy(proxy4)) self.assertFalse(utils.is_valid_no_proxy(proxy6)) self.assertFalse(utils.is_valid_no_proxy(proxy7)) self.assertFalse(utils.is_valid_no_proxy(proxy8)) self.assertFalse(utils.is_valid_no_proxy(proxy9))
def validate_image_proxies(node): """Check that the provided proxy parameters are valid. :param node: an Ironic node. :raises: InvalidParameterValue if any of the provided proxy parameters are incorrect. """ invalid_proxies = {} for scheme in ('http', 'https'): proxy_param = 'image_%s_proxy' % scheme proxy = node.driver_info.get(proxy_param) if proxy: chunks = urlparse.urlparse(proxy) # NOTE(vdrok) If no scheme specified, this is still a valid # proxy address. It is also possible for a proxy to have a # scheme different from the one specified in the image URL, # e.g. it is possible to use https:// proxy for downloading # http:// image. if chunks.scheme not in ('', 'http', 'https'): invalid_proxies[proxy_param] = proxy msg = '' if invalid_proxies: msg += _("Proxy URL should either have HTTP(S) scheme " "or no scheme at all, the following URLs are " "invalid: %s.") % invalid_proxies no_proxy = node.driver_info.get('image_no_proxy') if no_proxy is not None and not utils.is_valid_no_proxy(no_proxy): msg += _( "image_no_proxy should be a list of host names, IP addresses " "or domain names to exclude from proxying, the specified list " "%s is incorrect. To denote a domain name, prefix it with a dot " "(instead of e.g. '.*').") % no_proxy if msg: raise exception.InvalidParameterValue(msg)
def test_is_valid_no_proxy(self): # Valid values for 'no_proxy' valid_no_proxy = [ ('a' * 63 + '.' + '0' * 63 + '.c.' + 'd' * 61 + '.' + 'e' * 61), ('A' * 63 + '.' + '0' * 63 + '.C.' + 'D' * 61 + '.' + 'E' * 61), ('.' + 'a' * 62 + '.' + '0' * 62 + '.c.' + 'd' * 61 + '.' + 'e' * 61), ',,example.com:3128,', '192.168.1.1', # IP should be valid ] # Test each one individually, so if failure easier to determine which # one failed. for no_proxy in valid_no_proxy: self.assertTrue( utils.is_valid_no_proxy(no_proxy), msg="'no_proxy' value should be valid: {}".format(no_proxy)) # Test valid when joined together self.assertTrue(utils.is_valid_no_proxy(','.join(valid_no_proxy))) # Test valid when joined together with whitespace self.assertTrue(utils.is_valid_no_proxy(' , '.join(valid_no_proxy))) # empty string should also be valid self.assertTrue(utils.is_valid_no_proxy('')) # Invalid values for 'no_proxy' invalid_no_proxy = [ ('A' * 64 + '.' + '0' * 63 + '.C.' + 'D' * 61 + '.' + 'E' * 61), # too long (> 253) ('a' * 100), 'a..com', ('.' + 'a' * 63 + '.' + '0' * 62 + '.c.' + 'd' * 61 + '.' + 'e' * 61), # too long (> 251 after deleting .) ('*.' + 'a' * 60 + '.' + '0' * 60 + '.c.' + 'd' * 61 + '.' + 'e' * 61), # starts with *. 'c.-a.com', 'c.a-.com', ] for no_proxy in invalid_no_proxy: self.assertFalse( utils.is_valid_no_proxy(no_proxy), msg="'no_proxy' value should be invalid: {}".format(no_proxy))
def test_is_valid_no_proxy(self): # Valid values for 'no_proxy' valid_no_proxy = [ ("a" * 63 + "." + "0" * 63 + ".c." + "d" * 61 + "." + "e" * 61), ("A" * 63 + "." + "0" * 63 + ".C." + "D" * 61 + "." + "E" * 61), ("." + "a" * 62 + "." + "0" * 62 + ".c." + "d" * 61 + "." + "e" * 61), ",,example.com:3128,", "192.168.1.1", # IP should be valid ] # Test each one individually, so if failure easier to determine which # one failed. for no_proxy in valid_no_proxy: self.assertTrue( utils.is_valid_no_proxy(no_proxy), msg="'no_proxy' value should be valid: {}".format(no_proxy) ) # Test valid when joined together self.assertTrue(utils.is_valid_no_proxy(",".join(valid_no_proxy))) # Test valid when joined together with whitespace self.assertTrue(utils.is_valid_no_proxy(" , ".join(valid_no_proxy))) # empty string should also be valid self.assertTrue(utils.is_valid_no_proxy("")) # Invalid values for 'no_proxy' invalid_no_proxy = [ ("A" * 64 + "." + "0" * 63 + ".C." + "D" * 61 + "." + "E" * 61), # too long (> 253) ("a" * 100), "a..com", ("." + "a" * 63 + "." + "0" * 62 + ".c." + "d" * 61 + "." + "e" * 61), # too long (> 251 after deleting .) ("*." + "a" * 60 + "." + "0" * 60 + ".c." + "d" * 61 + "." + "e" * 61), # starts with *. "c.-a.com", "c.a-.com", ] for no_proxy in invalid_no_proxy: self.assertFalse( utils.is_valid_no_proxy(no_proxy), msg="'no_proxy' value should be invalid: {}".format(no_proxy) )