diff options
author | Philip Sargent <philip.sargent@klebos.com> | 2021-04-28 00:48:20 +0100 |
---|---|---|
committer | Philip Sargent <philip.sargent@klebos.com> | 2021-04-28 00:48:20 +0100 |
commit | b9fad1f4fb0fd496aedfcb439709f308cd366de8 (patch) | |
tree | 34c9fab88b32c30328c6c17174e0df3326e73f50 /core | |
parent | 5e478c7eb0a2bcd23ca46d1c4bd200750fbc9231 (diff) | |
download | troggle-b9fad1f4fb0fd496aedfcb439709f308cd366de8.tar.gz troggle-b9fad1f4fb0fd496aedfcb439709f308cd366de8.tar.bz2 troggle-b9fad1f4fb0fd496aedfcb439709f308cd366de8.zip |
new path() interacts badly with include(). fixed
Diffstat (limited to 'core')
-rw-r--r-- | core/TESTS/tests.py | 48 | ||||
-rw-r--r-- | core/views/expo.py | 26 |
2 files changed, 63 insertions, 11 deletions
diff --git a/core/TESTS/tests.py b/core/TESTS/tests.py index 1cf9f60..77cd998 100644 --- a/core/TESTS/tests.py +++ b/core/TESTS/tests.py @@ -190,8 +190,22 @@ class PageTests(TestCase): content = response.content.decode() self.assertEqual(response.status_code, 302) - def test_page_expofiles_dir(self): - # Flat file tests. + def test_page_expofiles_root_dir(self): + # Root expofiles - odd interaction with url parsing so needs testing + response = self.client.get('/expofiles') + if response.status_code != 200: + self.assertEqual(response.status_code, 302) + if response.status_code != 302: + self.assertEqual(response.status_code, 200) + content = response.content.decode() + for ph in [ r'a href="/expofiles/geotiffsurveys">/geotiffsurveys/', + r'<a href="/expofiles/photos">/photos/', + r'<a href="/expofiles/surveyscans">/surveyscans/' ]: + phmatch = re.search(ph, content) + self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") + + def test_page_expofiles_root_slash_dir(self): + # Root expofiles - odd interaction with url parsing so needs testing response = self.client.get('/expofiles/') if response.status_code != 200: self.assertEqual(response.status_code, 302) @@ -200,7 +214,35 @@ class PageTests(TestCase): content = response.content.decode() for ph in [ r'a href="/expofiles/geotiffsurveys">/geotiffsurveys/', r'<a href="/expofiles/photos">/photos/', - r'<a href="/expofiles/surveyscans">/surveyscans' ]: + r'<a href="/expofiles/surveyscans">/surveyscans/' ]: + phmatch = re.search(ph, content) + self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") + + def test_page_expofiles_badness(self): + # should display expofiles directory contents not its parent + response = self.client.get('/expofiles/99badness99') + if response.status_code != 200: + self.assertEqual(response.status_code, 302) + if response.status_code != 302: + self.assertEqual(response.status_code, 200) + content = response.content.decode() + for ph in [ r'a href="/expofiles/geotiffsurveys">/geotiffsurveys/', + r'<a href="/expofiles/photos">/photos/', + r'<a href="/expofiles/surveyscans">/surveyscans/' ]: + phmatch = re.search(ph, content) + self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") + + def test_page_expofiles_docs_dir(self): + # Flat file tests. + response = self.client.get('/expofiles/documents/') + if response.status_code != 200: + self.assertEqual(response.status_code, 302) + if response.status_code != 302: + self.assertEqual(response.status_code, 200) + content = response.content.decode() + for ph in [ r'a href="/expofiles/documents/bier-tent-instructions.pdf">bier-tent-instructions.pdf', + r'a href="/expofiles/documents/boc.pdf">boc.pdf', + r'a href="/expofiles/documents/bierbook">/bierbook' ]: phmatch = re.search(ph, content) self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") diff --git a/core/views/expo.py b/core/views/expo.py index 42ca8a2..a312143 100644 --- a/core/views/expo.py +++ b/core/views/expo.py @@ -48,11 +48,11 @@ default_head = '''<head> <input type=submit value="Search"></li> </ul>''' -def expofiles_redirect(request, path): +def expofiles_redirect(request, filepath): '''This is used only when running as a test system without a local copy of /expofiles/ when settings.EXPOFILESREMOTE is True ''' - return redirect(urljoin('http://expo.survex.com/expofiles/', path)) + return redirect(urljoin('http://expo.survex.com/expofiles/', filepath)) def map(request): '''Serves unadorned the expoweb/map/map.html file @@ -70,6 +70,10 @@ def expofilessingle(request, filepath): '''sends a single binary file to the user, if not found, show the parent directory If the path actually is a directory, then show that. ''' + #print(f' - expofilessingle {filepath}') + if filepath =="" or filepath =="/": + return expofilesdir(request, settings.EXPOFILES, "") + fn=urlunquote(filepath) fn = Path(settings.EXPOFILES,filepath) if fn.is_dir(): @@ -77,21 +81,27 @@ def expofilessingle(request, filepath): if fn.is_file(): return HttpResponse(content=open(fn, "rb"),content_type=getmimetype(filepath)) # any file else: - # not a file, so show parent directory - return expofilesdir(request, Path(fn).parent, Path(filepath).parent) + # not a file, so show parent directory - DANGER need to check this is limited to below expofiles + if Path(fn).parent == Path(settings.EXPOFILES).parent: + return expofilesdir(request, Path(settings.EXPOFILES), Path(filepath).parent) + else: + return expofilesdir(request, Path(fn).parent, Path(filepath).parent) def expofilesdir(request, dirpath, filepath): '''does a directory display. If there is an index.html file we should display that. - dirpath is a full Path() resolved including lcoal machine /expofiles/ - filepath is a Path() and it does not have /expofiles/ in it ''' - # print(f' - expofilesdir {dirpath}') - urlpath = 'expofiles' / Path(filepath) + #print(f' - expofilesdir {dirpath} settings.EXPOFILESREMOTE: {settings.EXPOFILESREMOTE}') + if filepath: + urlpath = 'expofiles' / Path(filepath) + else: + urlpath = Path('expofiles') try: for f in dirpath.iterdir(): pass except FileNotFoundError: - print(f' - expofilesdir {dirpath}') + #print(f' - expofilesdir error {dirpath}') return expofilesdir(request, dirpath.parent, filepath.parent) fileitems = [] @@ -145,7 +155,7 @@ def mediapage(request, subpath=None, doc_root=None): '''This is for special prefix paths /photos/ /site_media/, /static/ etc. as defined in urls.py . If given a directory, gives a failure page. ''' - # print(" - XXXXX_ROOT: {} ...{}".format(doc_root, subpath)) + #print(" - XXXXX_ROOT: {} ...{}".format(doc_root, subpath)) if doc_root is not None: filetobeopened = Path(doc_root, subpath) if filetobeopened.is_dir(): |