Exemplo n.º 1
0
 def testSecureNoAuth_with_pycurl(self):
     """https with no client authentication"""
     req = Requests.Requests('https://cmsweb.cern.ch', {'pycurl':1})
     out = req.makeRequest('', decoder=False)
     self.assertEqual(out[1], 200)
     # we should get an html page in response
     self.assertNotEqual(out[0].find('html'), -1)
Exemplo n.º 2
0
 def testNoCache(self):
     """Cache disabled"""
     req = Requests.Requests('https://cmssdt.cern.ch/SDT/',
                             {'cachepath': None})
     out = req.makeRequest('/', decoder=False)
     self.assertEqual(out[3], False)
     self.assertTrue('html' in out[0])
Exemplo n.º 3
0
    def test10Calls_with_pycurl(self):
        fail_count = 0
        idict = {'req_cache_path': self.cache_path, 'pycurl': 1}
        req = Requests.Requests(self.urlbase, idict)

        for i in range(0, 5):
            time.sleep(i)
            print('test %s starting at %s' % (i, time.time()))
            try:
                result = req.get(
                    '/',
                    incoming_headers={'Cache-Control': 'no-cache'},
                    decode=False)
                self.assertEqual(False, result[3])
                self.assertEqual(200, result[1])
            except HTTPException as he:
                print('test %s raised a %s error' % (i, he.status))
                fail_count += 1
            except Exception as e:
                print('test %s raised an unexpected exception of type %s' %
                      (i, type(e)))
                print(e)
                fail_count += 1
        if fail_count > 0:
            raise Exception('Test did not pass!')
Exemplo n.º 4
0
    def __call__(self, wmTask):
        """
        Trip through steps, pull in files specified in the sandbox section
        PSet Tweaks etc

        """
        for t in wmTask.steps().nodeIterator():
            t = WMStep.WMStepHelper(t)
            stepPath = "%s/%s" % (self.workingDirectory(), t.name())
            for fileInfo in t.data.sandbox:
                # fileInfo.src is the source file
                # fileInfo.injob is where we stuck it
                match = re.search("^.*/(.*?)$", fileInfo.src)
                if (match):
                    fileSuffix = match.group(1)
                else:
                    fileSuffix = "sandboxFile.dat"

                fileTarget = "%s/%s" % (stepPath, fileSuffix)

                # Now build a Request object, make a request, and write
                # the output to a file:
                try:
                    request = Requests.Requests(fileInfo.src)
                    content = request.get('')[0]
                    f = open(fileTarget, 'w')
                    f.write(content)
                    f.close()
                except IOError, ex:
                    msg = "Could not write to fileTarget %s\n" % fileTarget
                    msg += str(ex)
                    logging.error(msg)
                    logging.debug("FileInfo: %s" % fileInfo)
                    raise
                fileInfo.injob = fileTarget
Exemplo n.º 5
0
 def test404Error(self):
     endp = "http://cmsweb.cern.ch"
     url = "/thispagedoesntexist/"
     req = Requests.Requests(endp, self.request_dict)
     for v in ['GET', 'POST']:
         self.assertRaises(HTTPException, req.makeRequest, url, verb=v)
     try:
         req.makeRequest(url, verb='GET')
     except HTTPException as e:
         #print e
         self.assertEqual(e.status, 404)
Exemplo n.º 6
0
 def testSecureOddPort_with_pycurl(self):
     """https with odd port"""
     proxy = os.environ.get('X509_USER_PROXY')
     if not proxy:
         raise nose.SkipTest('Only run if an X509 proxy is present')
     os.environ.pop('X509_HOST_CERT', None)
     os.environ.pop('X509_HOST_KEY', None)
     os.environ.pop('X509_USER_CERT', None)
     os.environ.pop('X509_USER_KEY', None)
     req = Requests.Requests('https://cmsweb.cern.ch:443', {'pycurl':1})
     out = req.makeRequest('/auth/trouble', decoder=False)
     self.assertEqual(out[1], 200)
     self.assertNotEqual(out[0].find('passed basic validation'), -1)
Exemplo n.º 7
0
 def testGetKeyCert(self):
     """test existance of key/cert"""
     proxy = os.environ.get('X509_USER_PROXY')
     if not proxy:
         raise nose.SkipTest('Only run if an X509 proxy is present')
     os.environ.pop('X509_HOST_CERT', None)
     os.environ.pop('X509_HOST_KEY', None)
     os.environ.pop('X509_USER_CERT', None)
     os.environ.pop('X509_USER_KEY', None)
     req = Requests.Requests('https://cmsweb.cern.ch')
     key, cert = req.getKeyCert()
     self.assertNotEqual(None, key)
     self.assertNotEqual(None, cert)
Exemplo n.º 8
0
    def testRecoveryFromConnRefused(self):
        """Connections succeed after server down"""
        import socket
        self.rt.stop()
        req = Requests.Requests(self.urlbase, {'req_cache_path': self.cache_path})
        headers = {'Cache-Control':'no-cache'}
        self.assertRaises(socket.error, req.get, '/', incoming_headers=headers)

        # now restart server and hope we can connect
        self.rt.start(blocking=False)
        result = req.get('/', incoming_headers=headers)
        self.assertEqual(result[3], False)
        self.assertEqual(result[1], 200)
Exemplo n.º 9
0
 def test404Error_with_pycurl(self):
     endp = "http://cmsweb.cern.ch"
     url = "/thispagedoesntexist/"
     idict = dict(self.request_dict)
     idict.update({'pycurl': 1})
     req = Requests.Requests(endp, idict)
     for v in ['GET', 'POST']:
         self.assertRaises(HTTPException, req.makeRequest, url, verb=v)
     try:
         req.makeRequest(url, verb='GET')
     except HTTPException, e:
         #print e
         self.assertEqual(e.status, 404)
Exemplo n.º 10
0
 def testSecureWithProxy(self):
     """https with proxy"""
     proxy = os.environ.get('X509_USER_PROXY')
     if not proxy:
         raise nose.SkipTest('Only run if an X509 proxy is present')
     os.environ.pop('X509_HOST_CERT', None)
     os.environ.pop('X509_HOST_KEY', None)
     os.environ.pop('X509_USER_CERT', None)
     os.environ.pop('X509_USER_KEY', None)
     req = Requests.Requests('https://cmsweb.cern.ch')
     out = req.makeRequest('/auth/trouble')
     self.assertEqual(out[1], 200)
     self.assertNotEqual(out[0].find('passed basic validation'), -1)
     self.assertNotEqual(out[0].find('certificate is a proxy'), -1)
Exemplo n.º 11
0
    def testRecoveryFromConnRefused_with_pycurl(self):
        """Connections succeed after server down"""
        import pycurl
        self.rt.stop()
        idict = {'req_cache_path': self.cache_path, 'pycurl':1}
        req = Requests.Requests(self.urlbase, idict)
        headers = {'Cache-Control':'no-cache'}
        self.assertRaises(pycurl.error, req.get, '/', incoming_headers=headers, decode=False)

        # now restart server and hope we can connect
        self.rt.start(blocking=False)
        result = req.get('/', incoming_headers=headers, decode=False)
        self.assertEqual(result[3], False)
        self.assertEqual(result[1], 200)
Exemplo n.º 12
0
 def testSecureWithProxy_with_pycurl(self):
     """https with proxy with pycurl"""
     proxy = os.environ.get('X509_USER_PROXY')
     if not proxy:
         raise nose.SkipTest('Only run if an X509 proxy is present')
     os.environ.pop('X509_HOST_CERT', None)
     os.environ.pop('X509_HOST_KEY', None)
     os.environ.pop('X509_USER_CERT', None)
     os.environ.pop('X509_USER_KEY', None)
     req = Requests.Requests('https://cmsweb.cern.ch', {'pycurl':1})
     out = req.makeRequest('/phedex/datasvc/json/prod/groups')
     self.assertEqual(out[1], 200)
     if  not isinstance(out[0], dict):
         msg = 'wrong data type'
         raise Exception(msg)
     out = req.makeRequest('/auth/trouble', decoder=False)
     self.assertEqual(out[1], 200)
     self.assertNotEqual(out[0].find('passed basic validation'), -1)
     self.assertNotEqual(out[0].find('certificate is a proxy'), -1)
Exemplo n.º 13
0
    def test10Calls(self):
        fail_count = 0
        req = Requests.Requests(self.urlbase,
                                {'req_cache_path': self.cache_path})

        for i in range(0, 5):
            time.sleep(i)
            print 'test %s starting at %s' % (i, time.time())
            try:
                result = req.get(
                    '/', incoming_headers={'Cache-Control': 'no-cache'})
                self.assertEqual(False, result[3])
                self.assertEqual(200, result[1])
            except HTTPException, he:
                print 'test %s raised a %s error' % (i, he.status)
                fail_count += 1
            except Exception, e:
                print 'test %s raised an unexpected exception of type %s' % (
                    i, type(e))
                print e
                fail_count += 1
Exemplo n.º 14
0
 def setUp(self):
     self.testInit = TestInit(__file__)
     self.testInit.setLogging()
     tmp = self.testInit.generateWorkDir()
     self.request = Requests.JSONRequests(idict={'req_cache_path' : tmp})