aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Doan <andy.doan@linaro.org>2014-12-09 17:01:53 -0600
committerAndy Doan <andy.doan@linaro.org>2014-12-09 17:01:53 -0600
commit17dc128238051a6dacda301f65758e5eb5b3ae95 (patch)
tree7b87d5b117be3b693d8bbc0aa08c972d19f476dd
parentb136b071ee79dc6e7e04c8d897cbe7bc61b9681e (diff)
fix link-latest when url has trailing '/'2014.12
we use os.path.dirname(src) to find the directory the "latest" symlink will go in. However, os.path.dirname does the following: os.path.dirname('/tmp/build/x') = '/tmp/build' os.path.dirname('/tmp/build/x/') = '/tmp/build/x' So we need to remove the trailing slash if it exists Change-Id: Id550f8b0167322ba6e0e19772154d1d81352b1fc
-rw-r--r--license_protected_downloads/api/v2.py3
-rw-r--r--license_protected_downloads/tests/test_api_v2.py14
2 files changed, 17 insertions, 0 deletions
diff --git a/license_protected_downloads/api/v2.py b/license_protected_downloads/api/v2.py
index 474c219..ecd2c32 100644
--- a/license_protected_downloads/api/v2.py
+++ b/license_protected_downloads/api/v2.py
@@ -154,6 +154,8 @@ class LatestLinkResource(PublishResource):
src = upload_target_path(
self.path, self.api_key.key, self.api_key.public)
+ if src[-1] == '/': # os.path.dirname means a different thing with /
+ src = src[:-1]
if not os.path.isdir(src):
APILog.mark(self.request, 'INVALID_ARGUMENTS', self.api_key)
raise HttpResponseError('Target does not exist: ' + self.path, 404)
@@ -172,6 +174,7 @@ class LatestLinkResource(PublishResource):
raise HttpResponseError('Invalid destination', 404)
os.symlink(src, dst)
+ APILog.mark(self.request, 'LINK_LATEST', self.api_key)
resp = HttpResponse(status=201)
resp['Location'] = dst
diff --git a/license_protected_downloads/tests/test_api_v2.py b/license_protected_downloads/tests/test_api_v2.py
index 3ea0cc1..efb5d49 100644
--- a/license_protected_downloads/tests/test_api_v2.py
+++ b/license_protected_downloads/tests/test_api_v2.py
@@ -197,6 +197,20 @@ class APIv2Tests(TestCase):
'/api/v2/link_latest/buildX', HTTP_AUTHTOKEN=token)
self.assertEqual(201, resp.status_code)
+ def test_link_latest_trailing_slash(self):
+ token = APIToken.objects.create(key=self.api_key).token
+ self._send_file('/api/v2/publish/build/X/a', token, 'content')
+
+ info = 'Format-Version: 0.5\n\nFiles-Pattern: *\nLicense-Type: open\n'
+ self._send_file('/api/v2/publish/build/X/BUILD-INFO.txt', token, info)
+
+ resp = self.client.post(
+ '/api/v2/link_latest/build/X/', HTTP_AUTHTOKEN=token)
+ self.assertEqual(201, resp.status_code)
+ resp = self.client.get('/build/latest/a')
+ self.assertEqual(200, resp.status_code)
+ self.assertEqual('content', open(resp['X-Sendfile']).read())
+
def test_link_latest_bad(self):
token = APIToken.objects.create(key=self.api_key).token
resp = self.client.post(