コード例 #1
0
ファイル: test_urllib.py プロジェクト: Kelauni22/Meeple
 def test_getproxies_environment_keep_no_proxies(self):
     self.env.set('NO_PROXY', 'localhost')
     proxies = urllib.getproxies_environment()
     # getproxies_environment use lowered case truncated (no '_proxy') keys
     self.assertEqual('localhost', proxies['no'])
     # List of no_proxies with space.
     self.env.set('NO_PROXY', 'localhost, anotherdomain.com, newdomain.com:1234')
     self.assertTrue(urllib.proxy_bypass_environment('anotherdomain.com'))
     self.assertTrue(urllib.proxy_bypass_environment('anotherdomain.com:8888'))
     self.assertTrue(urllib.proxy_bypass_environment('newdomain.com:1234'))
コード例 #2
0
 def test_getproxies_environment_keep_no_proxies(self):
     self.env.set('NO_PROXY', 'localhost')
     proxies = urllib.getproxies_environment()
     # getproxies_environment use lowered case truncated (no '_proxy') keys
     self.assertEqual('localhost', proxies['no'])
     # List of no_proxies with space.
     self.env.set('NO_PROXY', 'localhost, anotherdomain.com, newdomain.com:1234')
     self.assertTrue(urllib.proxy_bypass_environment('anotherdomain.com'))
     self.assertTrue(urllib.proxy_bypass_environment('anotherdomain.com:8888'))
     self.assertTrue(urllib.proxy_bypass_environment('newdomain.com:1234'))
コード例 #3
0
ファイル: test_urllib.py プロジェクト: plirof/minibloq_v0.83
 def test_getproxies_environment_keep_no_proxies(self):
     self.env.set("NO_PROXY", "localhost")
     proxies = urllib.getproxies_environment()
     # getproxies_environment use lowered case truncated (no '_proxy') keys
     self.assertEqual("localhost", proxies["no"])
     # List of no_proxies with space.
     self.env.set("NO_PROXY", "localhost, anotherdomain.com, newdomain.com")
     self.assertTrue(urllib.proxy_bypass_environment("anotherdomain.com"))
コード例 #4
0
ファイル: connection.py プロジェクト: vritant/python-rhsm
    def __init__(self, host, ssl_port=None,
                 username=None, password=None,
                 proxy_hostname=None, proxy_port=None,
                 proxy_user=None, proxy_password=None,
                 ca_dir=None, insecure=False,
                 ssl_verify_depth=1):

        log.debug("ContectConnection")
        # FIXME
        self.ent_dir = "/etc/pki/entitlement"
        self.handler = "/"
        self.ssl_verify_depth = ssl_verify_depth

        self.host = host or config.get('server', 'hostname')
        self.ssl_port = ssl_port or safe_int(config.get('server', 'port'))
        self.ca_dir = ca_dir
        self.insecure = insecure
        self.username = username
        self.password = password
        self.ssl_verify_depth = ssl_verify_depth

        self.timeout_altered = False

        # get the proxy information from the environment variable
        # if available and host is not in no_proxy
        if urllib.proxy_bypass_environment(self.host):
            info = {'proxy_username': '',
                   'proxy_hostname': '',
                   'proxy_port': '',
                   'proxy_password': ''}
        else:
            info = get_env_proxy_info()

        self.proxy_hostname = proxy_hostname or config.get('server', 'proxy_hostname') or info['proxy_hostname']
        self.proxy_port = proxy_port or config.get('server', 'proxy_port') or info['proxy_port']
        self.proxy_user = proxy_user or config.get('server', 'proxy_user') or info['proxy_username']
        self.proxy_password = proxy_password or config.get('server', 'proxy_password') or info['proxy_password']
コード例 #5
0
    def __init__(self, host, ssl_port=None,
                 username=None, password=None,
                 proxy_hostname=None, proxy_port=None,
                 proxy_user=None, proxy_password=None,
                 ca_dir=None, insecure=False,
                 ssl_verify_depth=1):

        log.debug("ContectConnection")
        # FIXME
        self.ent_dir = "/etc/pki/entitlement"
        self.handler = "/"
        self.ssl_verify_depth = ssl_verify_depth

        self.host = host or config.get('server', 'hostname')
        self.ssl_port = ssl_port or safe_int(config.get('server', 'port'))
        self.ca_dir = ca_dir
        self.insecure = insecure
        self.username = username
        self.password = password
        self.ssl_verify_depth = ssl_verify_depth
        self.timeout_altered = False

        # get the proxy information from the environment variable
        # if available and host is not in no_proxy
        if urllib.proxy_bypass_environment(self.host):
            info = {'proxy_username': '',
                   'proxy_hostname': '',
                   'proxy_port': '',
                   'proxy_password': ''}
        else:
            info = utils.get_env_proxy_info()

        self.proxy_hostname = proxy_hostname or config.get('server', 'proxy_hostname') or info['proxy_hostname']
        self.proxy_port = proxy_port or config.get('server', 'proxy_port') or info['proxy_port']
        self.proxy_user = proxy_user or config.get('server', 'proxy_user') or info['proxy_username']
        self.proxy_password = proxy_password or config.get('server', 'proxy_password') or info['proxy_password']
コード例 #6
0
 def test_getproxies_environment_prefer_lowercase(self):
     # Test lowercase preference with removal
     os.environ['no_proxy'] = ''
     os.environ['No_Proxy'] = 'localhost'
     self.assertFalse(urllib.proxy_bypass_environment('localhost'))
     self.assertFalse(urllib.proxy_bypass_environment('arbitrary'))
     os.environ['http_proxy'] = ''
     os.environ['HTTP_PROXY'] = 'http://somewhere:3128'
     proxies = urllib.getproxies_environment()
     self.assertEqual({}, proxies)
     # Test lowercase preference of proxy bypass and correct matching including ports
     os.environ['no_proxy'] = 'localhost, noproxy.com, my.proxy:1234'
     os.environ['No_Proxy'] = 'xyz.com'
     self.assertTrue(urllib.proxy_bypass_environment('localhost'))
     self.assertTrue(urllib.proxy_bypass_environment('noproxy.com:5678'))
     self.assertTrue(urllib.proxy_bypass_environment('my.proxy:1234'))
     self.assertFalse(urllib.proxy_bypass_environment('my.proxy'))
     self.assertFalse(urllib.proxy_bypass_environment('arbitrary'))
     # Test lowercase preference with replacement
     os.environ['http_proxy'] = 'http://somewhere:3128'
     os.environ['Http_Proxy'] = 'http://somewhereelse:3128'
     proxies = urllib.getproxies_environment()
     self.assertEqual('http://somewhere:3128', proxies['http'])
コード例 #7
0
ファイル: test_urllib.py プロジェクト: Kelauni22/Meeple
 def test_getproxies_environment_prefer_lowercase(self):
     # Test lowercase preference with removal
     os.environ['no_proxy'] = ''
     os.environ['No_Proxy'] = 'localhost'
     self.assertFalse(urllib.proxy_bypass_environment('localhost'))
     self.assertFalse(urllib.proxy_bypass_environment('arbitrary'))
     os.environ['http_proxy'] = ''
     os.environ['HTTP_PROXY'] = 'http://somewhere:3128'
     proxies = urllib.getproxies_environment()
     self.assertEqual({}, proxies)
     # Test lowercase preference of proxy bypass and correct matching including ports
     os.environ['no_proxy'] = 'localhost, noproxy.com, my.proxy:1234'
     os.environ['No_Proxy'] = 'xyz.com'
     self.assertTrue(urllib.proxy_bypass_environment('localhost'))
     self.assertTrue(urllib.proxy_bypass_environment('noproxy.com:5678'))
     self.assertTrue(urllib.proxy_bypass_environment('my.proxy:1234'))
     self.assertFalse(urllib.proxy_bypass_environment('my.proxy'))
     self.assertFalse(urllib.proxy_bypass_environment('arbitrary'))
     # Test lowercase preference with replacement
     os.environ['http_proxy'] = 'http://somewhere:3128'
     os.environ['Http_Proxy'] = 'http://somewhereelse:3128'
     proxies = urllib.getproxies_environment()
     self.assertEqual('http://somewhere:3128', proxies['http'])
コード例 #8
0
    def __init__(self,
            host=None,
            ssl_port=None,
            handler=None,
            proxy_hostname=None,
            proxy_port=None,
            proxy_user=None,
            proxy_password=None,
            username=None, password=None,
            cert_file=None, key_file=None,
            insecure=None):
        """
        Two ways to authenticate:
            - username/password for HTTP basic authentication. (owner admin role)
            - uuid/key_file/cert_file for identity cert authentication.
              (consumer role)

        Must specify one method of authentication or the other, not both.
        """
        self.host = host or config.get('server', 'hostname')
        self.ssl_port = ssl_port or safe_int(config.get('server', 'port'))
        self.handler = handler or config.get('server', 'prefix')

        # remove trailing "/" from the prefix if it is there
        # BZ848836
        self.handler = self.handler.rstrip("/")

        # get the proxy information from the environment variable
        # if available and host is not in no_proxy
        if urllib.proxy_bypass_environment(self.host):
            info = {'proxy_username': '',
                   'proxy_hostname': '',
                   'proxy_port': '',
                   'proxy_password': ''}
        else:
            info = utils.get_env_proxy_info()

        self.proxy_hostname = proxy_hostname or config.get('server', 'proxy_hostname') or info['proxy_hostname']
        self.proxy_port = proxy_port or config.get('server', 'proxy_port') or info['proxy_port']
        self.proxy_user = proxy_user or config.get('server', 'proxy_user') or info['proxy_username']
        self.proxy_password = proxy_password or config.get('server', 'proxy_password') or info['proxy_password']

        self.cert_file = cert_file
        self.key_file = key_file
        self.username = username
        self.password = password

        self.ca_cert_dir = config.get('rhsm', 'ca_cert_dir')
        self.ssl_verify_depth = safe_int(config.get('server', 'ssl_verify_depth'))

        self.insecure = insecure
        if insecure is None:
            self.insecure = False
            config_insecure = safe_int(config.get('server', 'insecure'))
            if config_insecure:
                self.insecure = True

        using_basic_auth = False
        using_id_cert_auth = False

        if username and password:
            using_basic_auth = True
        elif cert_file and key_file:
            using_id_cert_auth = True

        if using_basic_auth and using_id_cert_auth:
            raise Exception("Cannot specify both username/password and "
                    "cert_file/key_file")
        #if not (using_basic_auth or using_id_cert_auth):
        #    raise Exception("Must specify either username/password or "
        #            "cert_file/key_file")

        proxy_description = None
        if self.proxy_hostname and self.proxy_port:
            proxy_description = "http_proxy=%s:%s " % (self.proxy_hostname, self.proxy_port)
        auth_description = None
        # initialize connection
        if using_basic_auth:
            self.conn = Restlib(self.host, self.ssl_port, self.handler,
                    username=self.username, password=self.password,
                    proxy_hostname=self.proxy_hostname, proxy_port=self.proxy_port,
                    proxy_user=self.proxy_user, proxy_password=self.proxy_password,
                    ca_dir=self.ca_cert_dir, insecure=self.insecure,
                    ssl_verify_depth=self.ssl_verify_depth)
            auth_description = "auth=basic username=%s" % username
        elif using_id_cert_auth:
            self.conn = Restlib(self.host, self.ssl_port, self.handler,
                                cert_file=self.cert_file, key_file=self.key_file,
                                proxy_hostname=self.proxy_hostname, proxy_port=self.proxy_port,
                                proxy_user=self.proxy_user, proxy_password=self.proxy_password,
                                ca_dir=self.ca_cert_dir, insecure=self.insecure,
                                ssl_verify_depth=self.ssl_verify_depth)
            auth_description = "auth=identity_cert ca_dir=%s verify=%s" % (self.ca_cert_dir, self.insecure)
        else:
            self.conn = Restlib(self.host, self.ssl_port, self.handler,
                    proxy_hostname=self.proxy_hostname, proxy_port=self.proxy_port,
                    proxy_user=self.proxy_user, proxy_password=self.proxy_password,
                    ca_dir=self.ca_cert_dir, insecure=self.insecure,
                    ssl_verify_depth=self.ssl_verify_depth)
            auth_description = "auth=none"

        self.conn.user_agent = "RHSM/1.0 (cmd=%s)" % utils.cmd_name(sys.argv)

        self.resources = None
        self.capabilities = None
        connection_description = ""
        if proxy_description:
            connection_description += proxy_description
        connection_description += "host=%s port=%s handler=%s %s" % (self.host, self.ssl_port,
                                                                    self.handler, auth_description)
        log.info("Connection built: %s", connection_description)
コード例 #9
0
ファイル: connection.py プロジェクト: vritant/python-rhsm
    def __init__(self,
            host=None,
            ssl_port=None,
            handler=None,
            proxy_hostname=None,
            proxy_port=None,
            proxy_user=None,
            proxy_password=None,
            username=None, password=None,
            cert_file=None, key_file=None,
            insecure=None):
        """
        Two ways to authenticate:
            - username/password for HTTP basic authentication. (owner admin role)
            - uuid/key_file/cert_file for identity cert authentication.
              (consumer role)

        Must specify one method of authentication or the other, not both.
        """
        self.host = host or config.get('server', 'hostname')
        self.ssl_port = ssl_port or safe_int(config.get('server', 'port'))
        self.handler = handler or config.get('server', 'prefix')

        # remove trailing "/" from the prefix if it is there
        # BZ848836
        self.handler = self.handler.rstrip("/")

        # get the proxy information from the environment variable
        # if available and host is not in no_proxy
        if urllib.proxy_bypass_environment(self.host):
            info = {'proxy_username': '',
                   'proxy_hostname': '',
                   'proxy_port': '',
                   'proxy_password': ''}
        else:
            info = get_env_proxy_info()

        self.proxy_hostname = proxy_hostname or config.get('server', 'proxy_hostname') or info['proxy_hostname']
        self.proxy_port = proxy_port or config.get('server', 'proxy_port') or info['proxy_port']
        self.proxy_user = proxy_user or config.get('server', 'proxy_user') or info['proxy_username']
        self.proxy_password = proxy_password or config.get('server', 'proxy_password') or info['proxy_password']

        self.cert_file = cert_file
        self.key_file = key_file
        self.username = username
        self.password = password

        self.ca_cert_dir = config.get('rhsm', 'ca_cert_dir')
        self.ssl_verify_depth = safe_int(config.get('server', 'ssl_verify_depth'))

        self.insecure = insecure
        if insecure is None:
            self.insecure = False
            config_insecure = safe_int(config.get('server', 'insecure'))
            if config_insecure:
                self.insecure = True

        using_basic_auth = False
        using_id_cert_auth = False

        if username and password:
            using_basic_auth = True
        elif cert_file and key_file:
            using_id_cert_auth = True

        if using_basic_auth and using_id_cert_auth:
            raise Exception("Cannot specify both username/password and "
                    "cert_file/key_file")
        #if not (using_basic_auth or using_id_cert_auth):
        #    raise Exception("Must specify either username/password or "
        #            "cert_file/key_file")

        proxy_description = None
        if self.proxy_hostname and self.proxy_port:
            proxy_description = "http_proxy=%s:%s " % (self.proxy_hostname, self.proxy_port)
        auth_description = None
        # initialize connection
        if using_basic_auth:
            self.conn = Restlib(self.host, self.ssl_port, self.handler,
                    username=self.username, password=self.password,
                    proxy_hostname=self.proxy_hostname, proxy_port=self.proxy_port,
                    proxy_user=self.proxy_user, proxy_password=self.proxy_password,
                    ca_dir=self.ca_cert_dir, insecure=self.insecure,
                    ssl_verify_depth=self.ssl_verify_depth)
            auth_description = "auth=basic username=%s" % username
        elif using_id_cert_auth:
            self.conn = Restlib(self.host, self.ssl_port, self.handler,
                                cert_file=self.cert_file, key_file=self.key_file,
                                proxy_hostname=self.proxy_hostname, proxy_port=self.proxy_port,
                                proxy_user=self.proxy_user, proxy_password=self.proxy_password,
                                ca_dir=self.ca_cert_dir, insecure=self.insecure,
                                ssl_verify_depth=self.ssl_verify_depth)
            auth_description = "auth=identity_cert ca_dir=%s verify=%s" % (self.ca_cert_dir, self.insecure)
        else:
            self.conn = Restlib(self.host, self.ssl_port, self.handler,
                    proxy_hostname=self.proxy_hostname, proxy_port=self.proxy_port,
                    proxy_user=self.proxy_user, proxy_password=self.proxy_password,
                    ca_dir=self.ca_cert_dir, insecure=self.insecure,
                    ssl_verify_depth=self.ssl_verify_depth)
            auth_description = "auth=none"

        self.resources = None
        self.capabilities = None
        connection_description = ""
        if proxy_description:
            connection_description += proxy_description
        connection_description += "host=%s port=%s handler=%s %s" % (self.host, self.ssl_port,
                                                                    self.handler, auth_description)
        log.info("Connection built: %s", connection_description)