aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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(