aboutsummaryrefslogtreecommitdiff
path: root/license_protected_downloads
diff options
context:
space:
mode:
Diffstat (limited to 'license_protected_downloads')
-rw-r--r--license_protected_downloads/common.py5
-rw-r--r--license_protected_downloads/tests/test_views.py7
-rw-r--r--license_protected_downloads/views.py3
3 files changed, 14 insertions, 1 deletions
diff --git a/license_protected_downloads/common.py b/license_protected_downloads/common.py
index 81b72d3..94e05ec 100644
--- a/license_protected_downloads/common.py
+++ b/license_protected_downloads/common.py
@@ -182,7 +182,10 @@ class Artifact(object):
url += '/'
else:
url = '/'
- return url + self.file_name
+ url = url + self.file_name
+ if self.isdir() and url[-1] != '/':
+ url += '/'
+ return url
def get_type(self):
raise NotImplementedError()
diff --git a/license_protected_downloads/tests/test_views.py b/license_protected_downloads/tests/test_views.py
index 8bbe01a..c635609 100644
--- a/license_protected_downloads/tests/test_views.py
+++ b/license_protected_downloads/tests/test_views.py
@@ -346,6 +346,13 @@ class ViewTests(BaseServeViewTest):
r'<th></th><th>Name</th><th>Last modified</th>'
'<th>Size</th><th style="display: None">License</th>')
+ def test_dir_redirect(self):
+ '''URLs to directs without trailing / should result in a redirect'''
+ url = 'http://testserver/~linaro-android'
+ response = self.client.get(url)
+ self.assertEqual(302, response.status_code)
+ self.assertEqual(url + '/', response['Location'])
+
def test_not_found_file(self):
target_file = "12qwaszx"
url = urlparse.urljoin("http://testserver/", target_file)
diff --git a/license_protected_downloads/views.py b/license_protected_downloads/views.py
index 9f7fd18..a8d5be5 100644
--- a/license_protected_downloads/views.py
+++ b/license_protected_downloads/views.py
@@ -154,6 +154,9 @@ def _check_build_info(request, build_info):
def _handle_dir_list(request, artifact):
+ if request.path[-1] != '/':
+ return redirect(request.path + '/')
+
# Generate a link to the parent directory (if one exists)
url = artifact.url()
if url != '/':