コード例 #1
0
ファイル: t_publisher.py プロジェクト: jimklimov/pkg5
        def test_04_proxy_uri(self):
                """Verify that a ProxyURI object can be created, copied,
                modified, and used as expected."""

                pobj = publisher.ProxyURI("http://example.com")
                self.assertTrue(pobj.uri == "http://example.com")

                tcert = os.path.join(self.test_root, "test.cert")
                tkey = os.path.join(self.test_root, "test.key")
                # check that we can't set several RepositoryURI attributes
                bad_props = {
                    "priority": 1,
                    "ssl_cert": tcert,
                    "ssl_key": tkey,
                    "trailing_slash": False
                }

                pobj = publisher.ProxyURI("http://example.com")
                for prop in bad_props:
                        self.assertRaises(ValueError,
                            setattr, pobj, prop, bad_props[prop])

                # check bad values for system
                self.assertRaises(api_errors.BadRepositoryAttributeValue,
                    setattr, pobj, "system", "Carrots")
                self.assertRaises(api_errors.BadRepositoryAttributeValue,
                    setattr, pobj, "system", None)

                # check that we can set URI values that RespositoryURI would
                # choke on
                uri = "http://*****:*****@server"
                pobj.uri = uri
                self.assertTrue(pobj.uri == uri)

                # check that setting system results in uri being overridden
                pobj.system = True
                self.assertTrue(pobj.system == True)
                self.assertTrue(pobj.uri == publisher.SYSREPO_PROXY)

                # check that clearing system also clears uri
                pobj.system = False
                self.assertTrue(pobj.system == False)
                self.assertTrue(pobj.uri == None)
コード例 #2
0
ファイル: p5s.py プロジェクト: thenovum/pkg5
 def transform_urls(urls):
     res = []
     for val in urls:
         # If the URI contains <sysrepo> then it's served
         # directly by the system-repository.
         if val.startswith("http://{0}".format(publisher.SYSREPO_PROXY)):
             scheme, netloc, path, params, query, fragment =\
                 urlparse(val)
             r = publisher.RepositoryURI(
                 urlunparse(
                     (scheme, proxy_host, path, params, query, fragment)))
         else:
             # This URI needs to be proxied through the
             # system-repository, so we assign it a special
             # ProxyURI, which gets replaced by the actual
             # URI of the system-repository in
             # imageconfig.BlendedConfig.__merge_publishers
             r = publisher.RepositoryURI(val)
             r.proxies = [publisher.ProxyURI(None, system=True)]
         res.append(r)
     return res
コード例 #3
0
ファイル: t_publisher.py プロジェクト: jimklimov/pkg5
        def test_01_repository_uri(self):
                """Verify that a RepositoryURI object can be created, copied,
                modified, and used as expected."""

                nsfile = os.path.join(self.test_root, "nosuchfile")
                tcert = os.path.join(self.test_root, "test.cert")
                tkey = os.path.join(self.test_root, "test.key")

                uprops = {
                    "priority": 1,
                    "ssl_cert": tcert,
                    "ssl_key": tkey,
                    "trailing_slash": False,
                }

                # Check that all properties can be set at construction time.
                uobj = publisher.RepositoryURI("https://example.com", **uprops)

                # Verify that all properties provided at construction time were
                # set as expected.
                self.assertEqual(uobj.uri, "https://example.com")
                for p in uprops:
                        self.assertEqual(uprops[p], getattr(uobj, p))

                # Verify that scheme matches provided URI.
                self.assertEqual(uobj.scheme, "https")

                # Verify that a copy matches its original.
                cuobj = copy.copy(uobj)
                self.assertEqual(uobj.uri, cuobj.uri)
                for p in uprops:
                        self.assertEqual(getattr(uobj, p), getattr(cuobj, p))
                cuobj = None

                # Verify that setting invalid property values raises the
                # expected exception.
                self.assertRaises(api_errors.BadRepositoryURI, setattr, uobj,
                    "uri", None)
                self.assertRaises(api_errors.UnsupportedRepositoryURI, setattr,
                    uobj, "uri", ":/notvalid")
                # this value is valid only for ProxyURI objects, not
                # RepositoryURI objects
                self.assertRaises(api_errors.BadRepositoryURI, setattr, uobj,
                    "uri", "http://*****:*****@server")
                self.assertRaises(api_errors.BadRepositoryURIPriority,
                    setattr, uobj, "priority", "foo")
                self.assertRaises(api_errors.BadRepositoryAttributeValue,
                    setattr, uobj, "ssl_cert", -1)
                self.assertRaises(api_errors.BadRepositoryAttributeValue,
                    setattr, uobj, "ssl_key", -1)

                # Verify that changing the URI scheme will null properties that
                # no longer apply.
                uobj.uri = "http://example.com"
                self.assertEqual(uobj.ssl_cert, None)
                self.assertEqual(uobj.ssl_key, None)

                # Verify that scheme matches provided URI.
                self.assertEqual(uobj.scheme, "http")

                # Verify that attempting to set properties not valid for the
                # current URI scheme raises the expected exception.
                self.assertRaises(api_errors.UnsupportedRepositoryURIAttribute,
                    setattr, uobj, "ssl_cert", tcert)
                self.assertRaises(api_errors.UnsupportedRepositoryURIAttribute,
                    setattr, uobj, "ssl_key", tkey)

                # Verify that individual properties can be set.
                uobj = publisher.RepositoryURI("https://example.com/")
                for p in uprops:
                        setattr(uobj, p, uprops[p])
                        self.assertEqual(getattr(uobj, p), uprops[p])

                # Finally, verify all properties (except URI and trailing_slash)
                # can be set to None.
                for p in ("priority", "ssl_cert", "ssl_key"):
                        setattr(uobj, p, None)
                        self.assertEqual(getattr(uobj, p), None)

                # Verify that proxies are set properly
                uobj = publisher.RepositoryURI("https://example.com",
                    proxies=[])
                uobj = publisher.RepositoryURI("https://example.com",
                    proxies=[publisher.ProxyURI("http://foo.com")])

                self.assertTrue(uobj.proxies == [publisher.ProxyURI(
                    "http://foo.com")])
                uobj.proxies = []
                self.assertTrue(uobj.proxies == [])

                # Verify that proxies and proxy are linked
                uobj.proxies = [publisher.ProxyURI("http://foo.com")]
                self.assertTrue(uobj.proxy == "http://foo.com")
                uobj.proxy = "http://bar"
                self.assertTrue(uobj.proxies == [publisher.ProxyURI("http://bar")])

                try:
                        raised = False
                        publisher.RepositoryURI("http://foo", proxies=[
                            publisher.ProxyURI("http://bar")],
                            proxy="http://foo")
                except api_errors.PublisherError:
                        raised = True
                finally:
                        self.assertTrue(raised, "No exception raised when "
                            "creating a RepositoryURI obj with proxies & proxy")

                # Check that we detect bad values for proxies
                self.assertRaises(api_errors.BadRepositoryAttributeValue,
                    setattr, uobj, "proxies", "foo")
                self.assertRaises(api_errors.BadRepositoryAttributeValue,
                    setattr, uobj, "proxies", [None])
                # we only support a single proxy per RepositoryURI
                self.assertRaises(api_errors.BadRepositoryAttributeValue,
                    setattr, uobj, "proxies", [
                    publisher.ProxyURI("http://foo.com"),
                    publisher.ProxyURI("http://bar.com")])