def test_hostname_with_scheme(self): # this is the default, so test it here local_url = "https://subscription.rhsm.redhat.com/subscription" (username, password, hostname, port, prefix) = parse_url(local_url) self.assertEquals("subscription.rhsm.redhat.com", hostname) self.assertEquals(None, port) self.assertEquals("/subscription", prefix)
def test_hostname_with_scheme(self): # this is the default, so test it here local_url = "https://subscription.rhsm.redhat.com/subscription" (username, password, hostname, port, prefix) = parse_url(local_url) self.assertEqual("subscription.rhsm.redhat.com", hostname) self.assertEqual(None, port) self.assertEqual("/subscription", prefix)
def _get_connection_info(self): url_parse_error = os.EX_USAGE try: if self.options.destination_url is None: url_parse_error = os.EX_CONFIG hostname = self.rhsmcfg['server']['hostname'] port = self.rhsmcfg['server'].get_int('port') prefix = self.rhsmcfg['server']['prefix'] else: (_user, _password, hostname, port, prefix) = parse_url(self.options.destination_url, default_port=443) except ServerUrlParseError as e: system_exit(url_parse_error, _("Error parsing server URL: %s") % e.msg) connection_info = { 'host': hostname, 'ssl_port': int(port), 'handler': prefix } if not self.options.noproxy: connection_info['proxy_hostname_arg'] = self.proxy_host connection_info['proxy_port_arg'] = self.proxy_port and int( self.proxy_port) connection_info['proxy_user_arg'] = self.proxy_user connection_info['proxy_password_arg'] = self.proxy_pass return connection_info
def parse_baseurl_info(local_server_entry): return parse_url( local_server_entry, DEFAULT_CDN_HOSTNAME, DEFAULT_CDN_PORT, DEFAULT_CDN_PREFIX, )[2:]
def test_no_userinfo_with_at(self): local_url = "http://@hostname:1111/prefix" (username, password, hostname, port, prefix) = parse_url(local_url) self.assertEquals(None, username) self.assertEquals(None, password) self.assertEquals("hostname", hostname) self.assertEquals("1111", port) self.assertEquals("/prefix", prefix)
def test_hostname_just_slash_with_defaults(self): local_url = "/" (username, password, hostname, port, prefix) = parse_url(local_url, default_hostname=DEFAULT_HOSTNAME, default_port=DEFAULT_PORT) self.assertEquals(DEFAULT_HOSTNAME, hostname) self.assertEquals(DEFAULT_PORT, port) self.assertEquals("/", prefix)
def test_username_password(self): local_url = "http://*****:*****@hostname:1111/prefix" (username, password, hostname, port, prefix) = parse_url(local_url) self.assertEqual("user", username) self.assertEqual("pass", password) self.assertEqual("hostname", hostname) self.assertEqual("1111", port) self.assertEqual("/prefix", prefix)
def test_no_userinfo_with_at(self): local_url = "http://@hostname:1111/prefix" (username, password, hostname, port, prefix) = parse_url(local_url) self.assertEqual(None, username) self.assertEqual(None, password) self.assertEqual("hostname", hostname) self.assertEqual("1111", port) self.assertEqual("/prefix", prefix)
def test_username_password(self): local_url = "http://*****:*****@hostname:1111/prefix" (username, password, hostname, port, prefix) = parse_url(local_url) self.assertEquals("user", username) self.assertEquals("pass", password) self.assertEquals("hostname", hostname) self.assertEquals("1111", port) self.assertEquals("/prefix", prefix)
def test_short_name(self): # could argue anything could be a local hostname, and we should # use default port and path. You could also argue it should # throw an error, especially if it's not a valid hostname local_url = "a" (username, password, hostname, port, prefix) = parse_url(local_url, default_port=DEFAULT_PORT, default_prefix=DEFAULT_PREFIX) self.assertEquals("a", hostname) self.assertEquals(DEFAULT_PORT, port) self.assertEquals(DEFAULT_PREFIX, prefix)
def _get_connection_info(self): try: if self.options.destination_url is None: hostname = self.rhsmcfg.get('server', 'hostname') port = self.rhsmcfg.get_int('server', 'port') prefix = self.rhsmcfg.get('server', 'prefix') else: (_user, _password, hostname, port, prefix) = parse_url(self.options.destination_url, default_port=443) except ServerUrlParseError, e: system_exit(-1, _("Error parsing server URL: %s") % e.msg)
def parse_server_info(local_server_entry, config=None): hostname = '' port = '' prefix = '' if config is not None: hostname = config["server"]["hostname"] port = config["server"]["port"] prefix = config["server"]["prefix"] return parse_url(local_server_entry, hostname or DEFAULT_HOSTNAME, port or DEFAULT_PORT, prefix or DEFAULT_PREFIX)[2:]
def parse_server_info(local_server_entry, config=None): hostname = "" port = "" prefix = "" if config is not None: hostname = config.get("server", "hostname") port = config.get("server", "port") prefix = config.get("server", "prefix") return parse_url(local_server_entry, hostname or DEFAULT_HOSTNAME, port or DEFAULT_PORT, prefix or DEFAULT_PREFIX)[ 2: ]
def _get_connection_info(self): url_parse_error = os.EX_USAGE try: if self.options.destination_url is None: url_parse_error = os.EX_CONFIG hostname = self.rhsmcfg.get('server', 'hostname') port = self.rhsmcfg.get_int('server', 'port') prefix = self.rhsmcfg.get('server', 'prefix') else: (_user, _password, hostname, port, prefix) = parse_url(self.options.destination_url, default_port=443) except ServerUrlParseError, e: system_exit(url_parse_error, _("Error parsing server URL: %s") % e.msg)
def parse_proxy_entry(self, proxy_url): proxy_url = remove_scheme(proxy_url) proxy_host = None proxy_port = None try: proxy_info = parse_url(proxy_url, default_port=rhsm.config.DEFAULT_PROXY_PORT) proxy_host = proxy_info[2] proxy_port = proxy_info[3] except rhsm.utils.ServerUrlParseErrorPort, e: proxy_host = proxy_url.split(':')[0] proxy_port = rhsm.config.DEFAULT_PROXY_PORT
def _get_connection_info(self): url_parse_error = os.EX_USAGE try: if self.options.destination_url is None: url_parse_error = os.EX_CONFIG hostname = self.rhsmcfg['server']['hostname'] port = self.rhsmcfg['server'].get_int('port') prefix = self.rhsmcfg['server']['prefix'] else: (_user, _password, hostname, port, prefix) = parse_url(self.options.destination_url, default_port=443) except ServerUrlParseError as e: system_exit(url_parse_error, _("Error parsing server URL: %s") % e.msg) connection_info = {'host': hostname, 'ssl_port': int(port), 'handler': prefix} if not self.options.noproxy: connection_info['proxy_hostname_arg'] = self.proxy_host connection_info['proxy_port_arg'] = self.proxy_port and int(self.proxy_port) connection_info['proxy_user_arg'] = self.proxy_user connection_info['proxy_password_arg'] = self.proxy_pass return connection_info
def test_hostname_with_scheme_no_prefix(self): local_url = "https://myhost.example.com" (username, password, hostname, port, prefix) = parse_url(local_url) self.assertEqual("myhost.example.com", hostname) self.assertEqual(None, port) self.assertEqual(None, prefix)
def test_hostname_nested_prefix(self): local_url = "myhost.example.com/myapp/subapp" (username, password, hostname, port, prefix) = parse_url(local_url) self.assertEqual("myhost.example.com", hostname) self.assertEqual(None, port) self.assertEqual("/myapp/subapp", prefix)
def test_host_named_http(self): local_url = "http://http/prefix" (username, password, hostname, port, prefix) = parse_url(local_url) self.assertEquals("http", hostname) self.assertEquals(None, port) self.assertEquals('/prefix', prefix)
def test_hostname_slash_no_prefix(self): local_url = "http://myhost.example.com/" (username, password, hostname, port, prefix) = parse_url(local_url) self.assertEqual("myhost.example.com", hostname) self.assertEqual(None, port) self.assertEqual("/", prefix)
def test_hostname_just_slash(self): local_url = "/" (username, password, hostname, port, prefix) = parse_url(local_url) self.assertEqual(None, hostname) self.assertEqual(None, port) self.assertEqual("/", prefix)
def test_hostname_with_scheme_no_prefix(self): local_url = "https://myhost.example.com" (username, password, hostname, port, prefix) = parse_url(local_url) self.assertEquals("myhost.example.com", hostname) self.assertEquals(None, port) self.assertEquals(None, prefix)
def test_hostname_port(self): local_url = "myhost.example.com:500" (username, password, hostname, port, prefix) = parse_url(local_url) self.assertEqual("myhost.example.com", hostname) self.assertEqual("500", port) self.assertEqual(None, prefix)
def test_hostname_nested_prefix(self): local_url = "myhost.example.com/myapp/subapp" (username, password, hostname, port, prefix) = parse_url(local_url) self.assertEquals("myhost.example.com", hostname) self.assertEquals(None, port) self.assertEquals("/myapp/subapp", prefix)
def test_host_named_http_port_prefix(self): local_url = "https://https:8000/prefix" (username, password, hostname, port, prefix) = parse_url(local_url) self.assertEquals("https", hostname) self.assertEquals("8000", port) self.assertEquals('/prefix', prefix)
def test_host_named_http(self): local_url = "http://http/prefix" (username, password, hostname, port, prefix) = parse_url(local_url) self.assertEqual("http", hostname) self.assertEqual(None, port) self.assertEqual("/prefix", prefix)
def parse_baseurl_info(local_server_entry): return parse_url(local_server_entry, DEFAULT_CDN_HOSTNAME, DEFAULT_CDN_PORT, DEFAULT_CDN_PREFIX)[2:]
def test_just_prefix(self): local_url = "/myapp" (username, password, hostname, port, prefix) = parse_url(local_url) self.assertEqual(None, hostname) self.assertEqual(None, port) self.assertEqual("/myapp", prefix)
def test_hostname_no_scheme_port_no_prefix(self): local_url = "myhost.example.com:8443" (username, password, hostname, port, prefix) = parse_url(local_url) self.assertEqual("myhost.example.com", hostname) self.assertEqual("8443", port) self.assertEqual(None, prefix)
def test_hostname_just_slash(self): local_url = "/" (username, password, hostname, port, prefix) = parse_url(local_url) self.assertEquals(None, hostname) self.assertEquals(None, port) self.assertEquals("/", prefix)
def parse_server_info(local_server_entry): return parse_url(local_server_entry, DEFAULT_HOSTNAME, DEFAULT_PORT, DEFAULT_PREFIX)[2:]
def test_host_named_http_port_prefix(self): local_url = "https://https:8000/prefix" (username, password, hostname, port, prefix) = parse_url(local_url) self.assertEqual("https", hostname) self.assertEqual("8000", port) self.assertEqual("/prefix", prefix)
def test_fully_specified(self): local_url = "myhost.example.com:900/myapp" (username, password, hostname, port, prefix) = parse_url(local_url) self.assertEquals("myhost.example.com", hostname) self.assertEquals("900", port) self.assertEquals("/myapp", prefix)
def test_fully_specified(self): local_url = "myhost.example.com:900/myapp" (username, password, hostname, port, prefix) = parse_url(local_url) self.assertEqual("myhost.example.com", hostname) self.assertEqual("900", port) self.assertEqual("/myapp", prefix)
def test_just_prefix(self): local_url = "/myapp" (username, password, hostname, port, prefix) = parse_url(local_url) self.assertEquals(None, hostname) self.assertEquals(None, port) self.assertEquals("/myapp", prefix)
def test_hostname_no_scheme_port_no_prefix(self): local_url = "myhost.example.com:8443" (username, password, hostname, port, prefix) = parse_url(local_url) self.assertEquals("myhost.example.com", hostname) self.assertEquals("8443", port) self.assertEquals(None, prefix)
def test_hostname_port(self): local_url = "myhost.example.com:500" (username, password, hostname, port, prefix) = parse_url(local_url) self.assertEquals("myhost.example.com", hostname) self.assertEquals("500", port) self.assertEquals(None, prefix)