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])
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)
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!')
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
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)
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)
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)
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)
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)
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)
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)
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)
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