Merge lp:~dooferlad/linaro-license-protection/protect_hidden_files into lp:~linaro-automation/linaro-license-protection/trunk

Proposed by James Tunnicliffe
Status: Merged
Approved by: Stevan Radaković
Approved revision: 109
Merged at revision: 108
Proposed branch: lp:~dooferlad/linaro-license-protection/protect_hidden_files
Merge into: lp:~linaro-automation/linaro-license-protection/trunk
Diff against target: 91 lines (+41/-2)
2 files modified
license_protected_downloads/tests/test_views.py (+19/-0)
license_protected_downloads/views.py (+22/-2)
To merge this branch: bzr merge lp:~dooferlad/linaro-license-protection/protect_hidden_files
Reviewer Review Type Date Requested Status
Stevan Radaković Approve
Review via email: mp+120753@code.launchpad.net
To post a comment you must log in.
109. By James Tunnicliffe

Added another test.

Revision history for this message
Stevan Radaković (stevanr) wrote :

Looks good, tests pass as well.
Approve +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'license_protected_downloads/tests/test_views.py'
--- license_protected_downloads/tests/test_views.py 2012-08-20 15:41:26 +0000
+++ license_protected_downloads/tests/test_views.py 2012-08-22 13:54:30 +0000
@@ -411,5 +411,24 @@
411 # If a build-info file is invalid, we don't allow access411 # If a build-info file is invalid, we don't allow access
412 self.assertEqual(response.status_code, 403)412 self.assertEqual(response.status_code, 403)
413413
414 def test_unable_to_download_hidden_files(self):
415 target_file = '~linaro-android/staging-vexpress-a9/OPEN-EULA.txt'
416 url = urlparse.urljoin("http://testserver/", target_file)
417 response = self.client.get(url, follow=True)
418
419 # This file exists, but isn't listed so we shouldn't be able to
420 # download it.
421 self.assertEqual(response.status_code, 404)
422
423 def test_dot_files_are_hidden(self):
424 target_file = 'open'
425 url = urlparse.urljoin("http://testserver/", target_file)
426 response = self.client.get(url, follow=True)
427
428 # the directory open contains .hidden.txt - we shouldn't be able to
429 # see it in the listing.
430 self.assertNotContains(response, ".hidden.txt")
431
432
414if __name__ == '__main__':433if __name__ == '__main__':
415 unittest.main()434 unittest.main()
416435
=== added directory 'license_protected_downloads/tests/testserver_root/open'
=== added file 'license_protected_downloads/tests/testserver_root/open/.hidden.txt'
=== added file 'license_protected_downloads/tests/testserver_root/open/OPEN-EULA.txt'
=== modified file 'license_protected_downloads/views.py'
--- license_protected_downloads/views.py 2012-08-20 15:41:26 +0000
+++ license_protected_downloads/views.py 2012-08-22 13:54:30 +0000
@@ -26,7 +26,7 @@
2626
2727
28def _hidden_file(file_name):28def _hidden_file(file_name):
29 hidden_files = ["BUILD-INFO.txt", "EULA.txt", ".htaccess", "HEADER.html"]29 hidden_files = ["BUILD-INFO.txt", "EULA.txt", r"^\.", "HEADER.html"]
30 for pattern in hidden_files:30 for pattern in hidden_files:
31 if re.search(pattern, file_name):31 if re.search(pattern, file_name):
32 return True32 return True
@@ -34,7 +34,7 @@
3434
3535
36def _hidden_dir(file_name):36def _hidden_dir(file_name):
37 hidden_files = [".*openid.*", ".*restricted.*", ".*private.*"]37 hidden_files = [".*openid.*", ".*restricted.*", ".*private.*", r"^\."]
38 for pattern in hidden_files:38 for pattern in hidden_files:
39 if re.search(pattern, file_name):39 if re.search(pattern, file_name):
40 return True40 return True
@@ -246,6 +246,20 @@
246 return redirect('/')246 return redirect('/')
247247
248248
249def file_listed(path, url):
250 """Boolean response to "does this files show up in a directory listing."""
251 file_name = os.path.basename(path)
252 dir_name = os.path.dirname(path)
253
254 found = False
255 file_list = dir_list(url, dir_name)
256 for file in file_list:
257 if file["name"] == file_name:
258 found = True
259
260 return found
261
262
249def file_server(request, path):263def file_server(request, path):
250 url = path264 url = path
251 result = test_path(path)265 result = test_path(path)
@@ -293,6 +307,12 @@
293307
294 file_name = os.path.basename(path)308 file_name = os.path.basename(path)
295309
310 # If the file listing doesn't contain the file requested for download,
311 # return a 404. This prevents the download of BUILD-INFO.txt and other
312 # hidden files.
313 if not file_listed(path, url):
314 raise Http404
315
296 response = None316 response = None
297 if get_client_ip(request) in config.INTERNAL_HOSTS:317 if get_client_ip(request) in config.INTERNAL_HOSTS:
298 digests = 'OPEN'318 digests = 'OPEN'
299319
=== added directory 'sampleroot/open'
=== added file 'sampleroot/open/.hidden.txt'
=== added file 'sampleroot/open/OPEN-EULA.txt'

Subscribers

People subscribed via source and target branches