def test_no_proxy_via_environment_variable(self):
     """Test that env var no_proxy works."""
     host = self.cp.host
     with patch.dict('os.environ', {'HTTPS_PROXY': 'http://*****:*****@host', 'NO_PROXY': host}):
         uep = UEPConnection(username='******', password='******',
                             handler='/test', insecure=True)
         self.assertEqual(None, uep.proxy_hostname)
    def test_no_proxy_via_api(self):
        """Test that API trumps env var and config."""
        host = self.cp.host
        port = self.cp.ssl_port

        def mock_config(section, name):
            if (section, name) == ('server', 'no_proxy'):
                return 'foo.example.com'
            if (section, name) == ('server', 'hostname'):
                return host
            if (section, name) == ('server', 'port'):
                return port
            return None

        with patch.dict('os.environ', {
                'HTTPS_PROXY': 'http://*****:*****@host',
                'NO_PROXY': 'foo.example.com'
        }):
            with patch.object(connection.config, 'get', mock_config):
                uep = UEPConnection(username='******',
                                    password='******',
                                    handler='/test',
                                    insecure=True,
                                    no_proxy=host)
                self.assertEqual(None, uep.proxy_hostname)
 def test_no_proxy_with_one_asterisk_via_environment_variable(self):
     """Test that env var no_proxy with only one asterisk works."""
     with patch.dict('os.environ', {'HTTPS_PROXY': 'http://*****:*****@host',
                                    'no_proxy': '*'}):
         uep = UEPConnection(username='******', password='******',
                             handler='/test', insecure=True)
         self.assertEqual(None, uep.proxy_hostname)
 def setUp(self):
     # NOTE: this won't actually work, idea for this suite of unit tests
     # is to mock the actual server responses and just test logic in the
     # UEPConnection:
     self.cp = UEPConnection(username="******",
                             password="******",
                             handler="/Test/",
                             insecure=True)
예제 #5
0
 def test_https_proxy_info_allcaps(self):
     with patch.dict('os.environ', {'HTTPS_PROXY': 'http://*****:*****@host:4444'}):
         uep = UEPConnection(username="******", password="******",
              handler="/Test/", insecure=True)
         self.assertEquals("u", uep.proxy_user)
         self.assertEquals("p", uep.proxy_password)
         self.assertEquals("host", uep.proxy_hostname)
         self.assertEquals(int("4444"), uep.proxy_port)
예제 #6
0
 def test_no_port(self):
     with patch.dict('os.environ', {'HTTPS_PROXY': 'http://*****:*****@host'}):
         uep = UEPConnection(username="******", password="******",
              handler="/Test/", insecure=True)
         self.assertEquals("u", uep.proxy_user)
         self.assertEquals("p", uep.proxy_password)
         self.assertEquals("host", uep.proxy_hostname)
         self.assertEquals(3128, uep.proxy_port)
예제 #7
0
 def test_no_user_or_password(self):
     with patch.dict('os.environ', {'HTTPS_PROXY': 'http://host:1111'}):
         uep = UEPConnection(username="******", password="******",
              handler="/Test/", insecure=True)
         self.assertEquals(None, uep.proxy_user)
         self.assertEquals(None, uep.proxy_password)
         self.assertEquals("host", uep.proxy_hostname)
         self.assertEquals(int("1111"), uep.proxy_port)
 def test_uep_connection_honors_no_proxy_setting(self):
     with patch.dict('os.environ', {'no_proxy': 'foobar'}):
         uep = UEPConnection(host="foobar", username="******", password="******", handler="/Test/", insecure=True,
                             proxy_hostname="proxyfoo", proxy_password="******", proxy_port=42, proxy_user="******")
         self.assertIs(None, uep.proxy_user)
         self.assertIs(None, uep.proxy_password)
         self.assertIs(None, uep.proxy_hostname)
         self.assertIs(None, uep.proxy_port)
예제 #9
0
    def setUp(self):
        self.cp = UEPConnection(username="******",
                                password="******",
                                insecure=True)

        self.consumer = self.cp.registerConsumer("test-consumer",
                                                 "system",
                                                 owner="admin")
        self.consumer_uuid = self.consumer['uuid']
예제 #10
0
 def test_order(self):
     # should follow the order: HTTPS, https, HTTP, http
     with patch.dict('os.environ', {'HTTPS_PROXY': 'http://*****:*****@host:4444', 'http_proxy': 'http://*****:*****@host:2222'}):
         uep = UEPConnection(username="******", password="******",
              handler="/Test/", insecure=True)
         self.assertEquals("u", uep.proxy_user)
         self.assertEquals("p", uep.proxy_password)
         self.assertEquals("host", uep.proxy_hostname)
         self.assertEquals(int("4444"), uep.proxy_port)
예제 #11
0
 def setUp(self):
     self.cp = UEPConnection(username="******",
                             password="******",
                             insecure=True)
     self.owner_key = "test_owner_%d" % (random.randint(1, 5000))
     self.cp.conn.request_post('/owners', {
         'key': self.owner_key,
         'displayName': self.owner_key
     })
예제 #12
0
    def setUp(self):
        self.cp = UEPConnection(username="******", password="******", insecure=True)

        self.consumer = self.cp.registerConsumer("test-consumer", "system", owner="admin")
        self.consumer_uuid = self.consumer['uuid']

        # This product is present in the Candlepin test data
        self.cp.bindByProduct(self.consumer_uuid, ["awesomeos-instancebased"])

        entitlements = self.cp.getEntitlementList(self.consumer_uuid)
        self.assertTrue(len(entitlements) > 0)

        self.entitlement = entitlements[0]
        self.entitlement_id = self.entitlement['id']
 def setUp(self):
     # Try to remove all environment variables to not influence unit test
     try:
         os.environ.pop('no_proxy')
         os.environ.pop('NO_PROXY')
         os.environ.pop('HTTPS_PROXY')
     except KeyError:
         pass
     # NOTE: this won't actually work, idea for this suite of unit tests
     # is to mock the actual server responses and just test logic in the
     # UEPConnection:
     self.cp = UEPConnection(username="******", password="******",
             handler="/Test/", insecure=True)
     self.temp_ent_dir = mkdtemp()
예제 #14
0
def is_valid_server_info(hostname, port, prefix):
    """
    Check if we can communicate with a subscription service at the given
    location.

    Returns true or false.

    May throw a MissingCaCertException if the CA certificate has not been
    imported yet, which may be relevant to the caller.
    """
    # Proxy info should already be in config file and used by default:
    try:
        conn = UEPConnection(host=hostname, ssl_port=int(port), handler=prefix)
        conn.ping()
        return True
    except RestlibException, e:
        # If we're getting Unauthorized that's a good indication this is a
        # valid subscription service:
        if e.code == 401:
            return True
        else:
            log.exception(e)
            return False
예제 #15
0
 def test_has_proper_language_header_utf8(self, mock_locale):
     mock_locale.return_value = ('ja_JP', 'UTF-8')
     self.cp = UEPConnection()
     self.assertEqual(self.cp.conn.headers['Accept-Language'], 'ja-jp')
예제 #16
0
#!/usr/bin/env python

from rhsm.connection import UEPConnection
import json

cp = UEPConnection(host='lenovo.local.rm-rf.ca',
                   ssl_port=8443,
                   handler='/candlepin',
                   username='******',
                   password='******')

#cp = UEPConnection(
#    host='subscription.rhn.redhat.com',
#    ssl_port=443,
#    cert_file='/etc/pki/consumer/cert.pem',
#    key_file='/etc/pki/consumer/key.pem')

mapping = json.loads(
    open('/home/dgoodwin/src/candlepin/server/virtperf/checkin.json').read())
cp.hypervisorCheckIn('virtperf', None, mapping)
#cp.hypervisorCheckIn('5894300', None, mapping)
예제 #17
0
 def setUp(self):
     # Get handle to Restlib
     self.conn = UEPConnection().conn
     self.request_type = "GET"
     self.handler = "https://server/path"
예제 #18
0
 def setUp(self):
     self.cp = UEPConnection(username="******", password="******",
             insecure=True)
 def test_accepts_a_timeout(self):
     self.cp = UEPConnection(username="******",
                             password="******",
                             handler="/Test/",
                             insecure=True,
                             timeout=3)
예제 #20
0
#!/usr/bin/env python
# usage:
# vsphere-virt-who-simulator.py -o ACME_Corporation -e Dev host1:guest1,guest2 host3:guest3,guest4

from rhsm.connection import UEPConnection
from optparse import OptionParser

parser = OptionParser()

parser.add_option("-o", "--org", default="ACME_Corporation")
parser.add_option("-e", "--env", default="Dev")

[options, args] = parser.parse_args()

conn = UEPConnection(cert_file="/etc/pki/consumer/cert.pem",
                     key_file="/etc/pki/consumer/key.pem",
                     insecure=True)

# takes array in format ["host1:guest1,guest2","host2:guest3,guest4"]
# returns dict {"host1": ["guest1","guest2"], "host2": ["guest3","guest4"]}
mapping = dict([[host, guests.split(",")]
                for [host, guests] in [arg.split(":") for arg in args]])

print conn.hypervisorCheckIn(options.org, options.env, mapping)
예제 #21
0
def get_uep():
    key = ConsumerIdentity.keypath()
    cert = ConsumerIdentity.certpath()
    uep = UEPConnection(key_file=key, cert_file=cert)
    return uep