def testIndex(self): sf = StaticFiles(libdir=self.tempdir, path='/path', allowDirectoryListing=True) headers, body = parseResponse(asString( sf.handleRequest(path='/path/'))) self.assertTrue('<a href="data.txt"' in body, body)
class StaticFilesTest(SeecrTestCase): def setUp(self): SeecrTestCase.setUp(self) with open(join(self.tempdir, 'data.txt'), 'w') as f: f.write('DATA') self.sf = StaticFiles(libdir=self.tempdir, path='/jquery') def testPath(self): self.assertEqual('/jquery/', self.sf.path) def testData(self): headers, body = parseResponse( asString(self.sf.handleRequest(path='/jquery/data.txt'))) self.assertEqual('200', headers['StatusCode']) self.assertEqual('text/plain', headers['Headers']['Content-Type']) self.assertEqual('DATA', body) def testDoesNotExist(self): headers, body = parseResponse( asString(self.sf.handleRequest(path='/jquery/no'))) self.assertEqual('404', headers['StatusCode']) def testNotMyPath(self): self.assertEqual('', asString(self.sf.handleRequest(path='/other'))) def testIndex(self): sf = StaticFiles(libdir=self.tempdir, path='/path', allowDirectoryListing=True) headers, body = parseResponse(asString( sf.handleRequest(path='/path/'))) self.assertTrue('<a href="data.txt"' in body, body)
class StaticFilesTest(SeecrTestCase): def setUp(self): SeecrTestCase.setUp(self) with open(join(self.tempdir, 'data.txt'), 'w') as f: f.write('DATA') self.sf = StaticFiles(libdir=self.tempdir, path='/jquery') def testPath(self): self.assertEqual('/jquery/', self.sf.path) def testData(self): headers, body = parseResponse(asString(self.sf.handleRequest(path='/jquery/data.txt'))) self.assertEqual('200', headers['StatusCode']) self.assertEqual('text/plain', headers['Headers']['Content-Type']) self.assertEqual('DATA', body) def testDoesNotExist(self): headers, body = parseResponse(asString(self.sf.handleRequest(path='/jquery/no'))) self.assertEqual('404', headers['StatusCode']) def testNotMyPath(self): self.assertEqual('', asString(self.sf.handleRequest(path='/other'))) def testIndex(self): sf = StaticFiles(libdir=self.tempdir, path='/path', allowDirectoryListing=True) headers, body = parseResponse(asString(sf.handleRequest(path='/path/'))) self.assertTrue('<a href="data.txt"' in body, body)
def testPrefixStaticFiles(self): fullLibDir = join(self.tempdir, 'library-3.4.5') makedirs(fullLibDir) with open(join(fullLibDir, 'data.txt'), 'w') as f: f.write('DATA') prefixDir = join(self.tempdir, 'librar*') sf = StaticFiles(libdir=prefixDir, path='/jquery') headers, body = parseResponse(asBytes(sf.handleRequest(path='/jquery/data.txt'))) self.assertEqual('200', headers['StatusCode']) self.assertEqual('text/plain', headers['Headers']['Content-Type']) self.assertEqual(b'DATA', body)
class StaticFilesTest(SeecrTestCase): def setUp(self): SeecrTestCase.setUp(self) with open(join(self.tempdir, 'data.txt'), 'w') as f: f.write('DATA') self.sf = StaticFiles(libdir=self.tempdir, path='/jquery') def testPath(self): self.assertEqual('/jquery/', self.sf.path) def testData(self): headers, body = parseResponse(asBytes(self.sf.handleRequest(path='/jquery/data.txt'))) self.assertEqual('200', headers['StatusCode']) self.assertEqual('text/plain', headers['Headers']['Content-Type']) self.assertEqual(b'DATA', body) def testDoesNotExist(self): headers, body = parseResponse(asBytes(self.sf.handleRequest(path='/jquery/no'))) self.assertEqual('404', headers['StatusCode']) def testNotMyPath(self): self.assertEqual(b'', asBytes(self.sf.handleRequest(path='/other'))) def testIndex(self): sf = StaticFiles(libdir=self.tempdir, path='/path', allowDirectoryListing=True) headers, body = parseResponse(asBytes(sf.handleRequest(path='/path/'))) self.assertTrue(b'<a href="data.txt"' in body, body) def testPrefix(self): fullLibDir = join(self.tempdir, 'library-3.4.5') makedirs(fullLibDir) self.assertEqual(fullLibDir, libdirForPrefix(self.tempdir, 'library-3')) self.assertEqual(fullLibDir, libdirForPrefix(self.tempdir, 'libra')) self.assertRaises(ValueError, lambda: libdirForPrefix(self.tempdir, 'doesnotexist')) makedirs(join(self.tempdir, 'prefix-same-1')) makedirs(join(self.tempdir, 'prefix-same-2')) self.assertRaises(ValueError, lambda: libdirForPrefix(self.tempdir, 'prefix-same-')) def testPrefixStaticFiles(self): fullLibDir = join(self.tempdir, 'library-3.4.5') makedirs(fullLibDir) with open(join(fullLibDir, 'data.txt'), 'w') as f: f.write('DATA') prefixDir = join(self.tempdir, 'librar*') sf = StaticFiles(libdir=prefixDir, path='/jquery') headers, body = parseResponse(asBytes(sf.handleRequest(path='/jquery/data.txt'))) self.assertEqual('200', headers['StatusCode']) self.assertEqual('text/plain', headers['Headers']['Content-Type']) self.assertEqual(b'DATA', body)
def setUp(self): SeecrTestCase.setUp(self) with open(join(self.tempdir, 'data.txt'), 'w') as f: f.write('DATA') self.sf = StaticFiles(libdir=self.tempdir, path='/jquery')
def dna(reactor, port, dataPath, logPath, statePath, externalUrl, customerLogoUrl, deproxyIps=None, **ignored): environment = createEnvironment(dataPath) harvesterData = environment.createHarvesterData() harvesterDataRetrieve = environment.createHarvesterDataRetrieve() deproxy = Deproxy(deproxyForIps=deproxyIps) repositoryStatus = be( (RepositoryStatus(logPath, statePath), (harvesterData, ) ) ) configDict = JsonDict( logPath=logPath, statePath=statePath, externaUrl=externalUrl, dataPath=dataPath, ) print("Started Metastreams with configuration:\n" + configDict.pretty_print()) userGroup = initializeUserGroupManagement(join(statePath, 'users'), harvesterData) basicHtmlLoginHelix = (BasicHtmlLoginForm( action="/login.action", loginPath="/login", home="/index", rememberMeCookie=False, lang="nl"), (userGroup.basicHtmlObserver,), ) varWwwdataPath = join(statePath, 'www-data', 'var') isdir(varWwwdataPath) or makedirs(varWwwdataPath) staticFilePaths = [] staticFiles = Transparent() for path, libdir in [ ('/js/bootstrap', '/usr/share/javascript/bootstrap5/js'), ('/css/bootstrap', '/usr/share/javascript/bootstrap5/css'), ('/css/bootstrap-icons', '/usr/share/javascript/bootstrap-icons'), ('/js/jquery', '/usr/share/javascript/jquery'), ('/js/jquery-tablesorter', '/usr/share/javascript/jquery-tablesorter'), ('/css/jquery-tablesorter', '/usr/share/javascript/jquery-tablesorter/css'), ('/js/autosize', '/usr/share/javascript/autosize'), ('/static', staticHtmlPath), ('/var', varWwwdataPath), ]: staticFiles.addObserver(StaticFiles(libdir=libdir, path=path)) staticFilePaths.append(path) return \ (Observable(), (ObservableHttpServer(reactor, port), (LogCollector(), (ApacheLogWriter(stdout),), (deproxy, (HandleRequestLog(), (BasicHttpHandler(), (SessionHandler(), (CookieMemoryStore(name="meresco-harvester", timeout=2*60*60), ), (UserFromSession(), (PathFilter("/info/version"), (StringServer(VERSION_STRING, ContentTypePlainText), ) ), (PathFilter("/info/config"), (StringServer(configDict.dumps(), ContentTypeJson), ) ), (PathFilter('/login.action'), basicHtmlLoginHelix ), (staticFiles,), (PathFilter('/', excluding=['/info/version', '/info/config', '/action', '/login.action'] + harvesterDataRetrieve.paths + staticFilePaths), (SecureZone("/login", excluding=["/index", "/invalid", "/rss", '/running.rss', '/showHarvesterStatus'], defaultLanguage="nl"), (PathFilter('/', excluding=userGroup.excludedPaths), (DynamicHtml( [dynamicHtmlPath], reactor=reactor, additionalGlobals={ 'externalUrl': externalUrl, 'escapeXml': escapeXml, 'compose': compose, 'dumps': dumps, 'VERSION': VERSION, 'CONFIG': configDict, 'Timeslot': Timeslot, 'ThroughputAnalyser': ThroughputAnalyser, 'dateSince': dateSince, 'callable': callable, 'OnlineHarvest': OnlineHarvest, 'StringIO': StringIO, 'okPlainText': okPlainText, 'ZuluTime': ZuluTime, 'xpathFirst': xpathFirst, 'customerLogoUrl': customerLogoUrl, 'uuid': lambda: str(uuid4()), }, indexPage="/index", ), basicHtmlLoginHelix, (harvesterData,), (repositoryStatus,), (userGroup.dynamicHtmlObserver,), ) ), (userGroup.actions,), ), ), (PathFilter('/action'), (HarvesterDataActions(), (harvesterData,) ), ), (PathFilter(harvesterDataRetrieve.paths), (harvesterDataRetrieve, (FilterFields(), (harvesterData,), ), (repositoryStatus,), ) ) ) ) ) ) ) ) ) )
def testIndex(self): sf = StaticFiles(libdir=self.tempdir, path='/path', allowDirectoryListing=True) headers, body = parseResponse(asString(sf.handleRequest(path='/path/'))) self.assertTrue('<a href="data.txt"' in body, body)