def testOrAnythingUnderTheMagicDirectoryToo(self): request = self.make_request('/app1/__/blah/blah/blah', Zope=True) task = Task(StubChannel(), request) try: task.process() except Response, response: self.assertEqual(response.code, 404)
def testSubdirStillMatches(self): request = self.make_request('/app1/foo/bar.html', Zope=True) task = Task(StubChannel(), request) try: task.process() except Response, response: self.assertEqual(response.code, 200)
def testDirectlyAccessingMagicDirectoryRaises404(self): request = self.make_request('/app1/__', Zope=True) task = Task(StubChannel(), request) try: task.process() except Response, response: self.assertEqual(response.code, 404)
def testAppNotThereRaises404(self): request = self.make_request('/not-there', Zope=True) task = Task(StubChannel(), request) try: task.process() except Response, response: self.assertEqual(response.code, 404)
def testBasic(self): request = self.make_request('/index.html', Zope=True) task = Task(StubChannel(), request) try: task.process() except Response, response: pass
def testFailInDevMode(self): task = DUMMY_TASK() task.dev_mode = True task.channel = StubChannel() try: raise Exception("Yarrr!") except: task.fail() # Traceback and content length depend on incidental circumstances. expected = [ "HTTP/1.0 500 Internal Server Error" # "Content-Length: x" , "Content-Type: text/plain", "", "Internal Server Error", "", "Traceback (most recent call last):" # ... , 'Exception: Yarrr!' ] actual = task.channel.getvalue().splitlines() actual = actual[:1] + actual[2:7] + actual[-1:] self.assertEqual(expected, actual)
def testNonRootAppWithNoMagicDirectoryRaises500(self): request = self.make_request('/app1', Zope=True) task = Task(StubChannel(), request) os.remove(self.convert_path('root/app1/__/app.py')) os.remove(self.convert_path('root/app1/__/app.pyc')) os.rmdir(self.convert_path('root/app1/__')) try: task.process() except Response, response: self.assertEqual(response.code, 500)
def testEtcPasswdCaughtByFindApp(self): request = self.make_request( '../../../../../../../../../../etc/master.passwd', Zope=True) task = Task(StubChannel(), request) expected = [ "HTTP/1.0 500 Internal Server Error", "Content-Length: 25", "Content-Type: text/plain", "", "Internal Server Error", "", "" ] expected = '\r\n'.join(expected) actual = task.channel.getvalue() self.assertEqual(expected, actual)
def testFailInDepMode(self): task = DUMMY_TASK() task.dev_mode = False task.channel = StubChannel() try: raise Exception("Yarrr!") except: task.fail() expected = [ "HTTP/1.0 500 Internal Server Error", "Content-Length: 25", "Content-Type: text/plain", "", "Internal Server Error", "" ] actual = task.channel.getvalue().splitlines() self.assertEqual(expected, actual)