diff options
author | Andy Doan <andy.doan@linaro.org> | 2015-07-30 11:56:48 -0500 |
---|---|---|
committer | Andy Doan <andy.doan@linaro.org> | 2015-07-30 11:56:48 -0500 |
commit | 65cd78e65b1bfb7836f170bc3b4af58a02a5b075 (patch) | |
tree | c6d139d0d9bb4a447d49a7700d2d5d9875df826a | |
parent | 0255455978152e6bb1b4b024a8683cc66f05f910 (diff) | |
download | linaro-license-protection-65cd78e65b1bfb7836f170bc3b4af58a02a5b075.tar.gz |
bug #1729: handle directory listings in a normal manner
The code base has always tried to handle a directory listing using the
same logic whether or not it included a trailing slash. This leads to
issues when people want to construct textile files that require relative
URLs.
There are 2 parts to this "fix":
1) start including the trailing slash when we generate our directory
listings.
2) perform a redirect if we are given a directory and don't have the
trailing slash.
Change-Id: I48c91ab9e9f1a72a3723fa4c84917db772b7215c
-rw-r--r-- | license_protected_downloads/common.py | 5 | ||||
-rw-r--r-- | license_protected_downloads/tests/test_views.py | 7 | ||||
-rw-r--r-- | license_protected_downloads/views.py | 3 |
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 != '/': |