示例#1
0
    def testAuth(self):
        # CNY-981
        try:
            contentServer = rephelp.HTTPServerController(authRequester())
            baseUrl = contentServer.url()

            # test with user:pass
            contentURL = 'http://*****:*****@%s' % httplib.urlsplit(baseUrl)[1]
            name = 'foo.tar.gz'
            url = contentURL + '/' + name
            cached = lookaside.fetchURL(self.cfg, url, name)
            f = open(cached, 'r')
            self.assertEqual(f.read(), 'Hello, world!\n')

            # test with no password given
            contentURL = 'http://user@%s' % httplib.urlsplit(baseUrl)[1]
            name = 'foo2.tar.gz'
            url = contentURL + '/' + name
            cached = lookaside.fetchURL(self.cfg, url, name)
            f = open(cached, 'r')
            self.assertEqual(f.read(), 'Hello, world 2!\n')

            # test with no password at all
            name = 'foo3.tar.gz'
            url = baseUrl + '/' + name
            cached = self.logCheck(lookaside.fetchURL, (self.cfg, url, name), [
                'error: error downloading http://localhost:[0-9]*//foo3.tar.gz: HTTP Error 401: Unauthorized'
            ],
                                   regExp=True)
            self.assertEqual(cached, None)

            # test ftp with user:pass
            def fakeOpen(od, req, *args, **kw):
                self.req = req
                import StringIO
                s = 'baz file contents'
                r = StringIO.StringIO(s)
                r.headers = {'contentLength': len(s)}
                return r

            import urllib2
            self.mock(urllib2.OpenerDirector, 'open', fakeOpen)
            url = 'ftp://*****:*****@foo.com/bar/baz.tgz'
            name = 'baz.tgz'
            cached = lookaside.fetchURL(self.cfg, url, name)
            self.assertEqual(url, self.req.get_full_url())
            self.assertEqual(open(cached).read(), 'baz file contents')

        finally:
            contentServer.kill()
示例#2
0
    def testAuth(self):
        # CNY-981
        try:
            contentServer = rephelp.HTTPServerController(authRequester())
            baseUrl = contentServer.url()

            # test with user:pass
            contentURL = 'http://*****:*****@%s' % httplib.urlsplit(baseUrl)[1]
            name = 'foo.tar.gz'
            url = contentURL + '/' + name
            cached = lookaside.fetchURL(self.cfg, url, name)
            f = open(cached, 'r')
            self.assertEqual(f.read(), 'Hello, world!\n')

            # test with no password given
            contentURL = 'http://user@%s' % httplib.urlsplit(baseUrl)[1]
            name = 'foo2.tar.gz'
            url = contentURL + '/' + name
            cached = lookaside.fetchURL(self.cfg, url, name)
            f = open(cached, 'r')
            self.assertEqual(f.read(), 'Hello, world 2!\n')

            # test with no password at all
            name = 'foo3.tar.gz'
            url = baseUrl + '/' + name
            cached = self.logCheck(lookaside.fetchURL, (self.cfg, url, name),
                                   ['error: error downloading http://localhost:[0-9]*//foo3.tar.gz: HTTP Error 401: Unauthorized'],
                                   regExp=True)
            self.assertEqual(cached, None)

            # test ftp with user:pass
            def fakeOpen(od, req, *args, **kw):
                self.req = req
                import StringIO
                s = 'baz file contents'
                r = StringIO.StringIO(s)
                r.headers = {'contentLength': len(s)}
                return r

            import urllib2
            self.mock(urllib2.OpenerDirector, 'open', fakeOpen)
            url = 'ftp://*****:*****@foo.com/bar/baz.tgz'
            name = 'baz.tgz'
            cached = lookaside.fetchURL(self.cfg, url, name)
            self.assertEqual(url, self.req.get_full_url())
            self.assertEqual(open(cached).read(), 'baz file contents')

        finally:
            contentServer.kill()
示例#3
0
    def testHTTPProxy(self):
        '''Make sure that the lookaside cache can fetch through an http proxy'''
        if not os.path.exists(rephelp.HTTPProxy.proxyBinPath):
            raise testhelp.SkipTestException(
                'testHTTPProxy depends on squid being installed')

        class Always200Handler(SimpleHTTPRequestHandler):
            def log_message(self, *args, **kw):
                pass

            def do_GET(self):
                response = 'Hello, world!'
                self.send_response(200)
                self.send_header("Content-type", "text/unknown")
                self.send_header("Content-Length", len(response))
                self.end_headers()
                self.wfile.write(response)

        # create the file server
        server = rephelp.HTTPServerController(Always200Handler)

        proxy = rephelp.HTTPProxy(os.path.join(self.workDir, "http-cache"))
        proxyUri = proxy.start()

        repos = self.openRepository()

        try:
            self.cfg.proxy = {'http': 'http://*****:*****@localhost:%d/' % proxy.authPort
            }
            url2 = 'http://localhost:%d/authProxy.txt' \
                % (server.port)
            path = lookaside.fetchURL(self.cfg, url2, 'recipename')
            self.assertTrue(path)

            proxy.stop()
            l = open(proxy.accessLog).read()
            self.assertTrue(url1 in l)
            self.assertTrue(url2 in l)

        finally:
            proxy.stop()
            server.stop()
示例#4
0
    def testHTTPProxy(self):
        '''Make sure that the lookaside cache can fetch through an http proxy'''
        if not os.path.exists(rephelp.HTTPProxy.proxyBinPath):
            raise testhelp.SkipTestException(
                'testHTTPProxy depends on squid being installed')

        class Always200Handler(SimpleHTTPRequestHandler):
            def log_message(self, *args, **kw):
                pass

            def do_GET(self):
                response = 'Hello, world!'
                self.send_response(200)
                self.send_header("Content-type", "text/unknown")
                self.send_header("Content-Length", len(response))
                self.end_headers()
                self.wfile.write(response)

        # create the file server
        server = rephelp.HTTPServerController(Always200Handler)

        proxy = rephelp.HTTPProxy(os.path.join(self.workDir, "http-cache"))
        proxyUri = proxy.start()

        repos = self.openRepository()

        try:
            self.cfg.proxy = { 'http' : 'http://*****:*****@localhost:%d/'
                               % proxy.authPort }
            url2 = 'http://localhost:%d/authProxy.txt' \
                % (server.port)
            path = lookaside.fetchURL(self.cfg, url2,'recipename')
            self.assertTrue(path)

            proxy.stop()
            l = open(proxy.accessLog).read()
            self.assertTrue(url1 in l)
            self.assertTrue(url2 in l)

        finally:
            proxy.stop()
            server.stop()
示例#5
0
 def testCookies(self):
     # CNY-321
     try:
         contentServer = rephelp.HTTPServerController(cookieRequester())
         contentURL = contentServer.url()
         name = 'foo.tar.gz'
         url = contentURL + '/' + name
         cached = lookaside.fetchURL(self.cfg, url, name)
         f = open(cached, 'r')
         self.assertEqual(f.read(), 'Hello, world!\n')
     finally:
         contentServer.kill()
示例#6
0
 def testCookies(self):
     # CNY-321
     try:
         contentServer = rephelp.HTTPServerController(cookieRequester())
         contentURL = contentServer.url()
         name = 'foo.tar.gz'
         url = contentURL + '/' + name
         cached = lookaside.fetchURL(self.cfg, url, name)
         f = open(cached, 'r')
         self.assertEqual(f.read(), 'Hello, world!\n')
     finally:
         contentServer.kill()