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
1=== modified file 'license_protected_downloads/tests/test_views.py'
2--- license_protected_downloads/tests/test_views.py 2012-08-20 15:41:26 +0000
3+++ license_protected_downloads/tests/test_views.py 2012-08-22 13:54:30 +0000
4@@ -411,5 +411,24 @@
5 # If a build-info file is invalid, we don't allow access
6 self.assertEqual(response.status_code, 403)
7
8+ def test_unable_to_download_hidden_files(self):
9+ target_file = '~linaro-android/staging-vexpress-a9/OPEN-EULA.txt'
10+ url = urlparse.urljoin("http://testserver/", target_file)
11+ response = self.client.get(url, follow=True)
12+
13+ # This file exists, but isn't listed so we shouldn't be able to
14+ # download it.
15+ self.assertEqual(response.status_code, 404)
16+
17+ def test_dot_files_are_hidden(self):
18+ target_file = 'open'
19+ url = urlparse.urljoin("http://testserver/", target_file)
20+ response = self.client.get(url, follow=True)
21+
22+ # the directory open contains .hidden.txt - we shouldn't be able to
23+ # see it in the listing.
24+ self.assertNotContains(response, ".hidden.txt")
25+
26+
27 if __name__ == '__main__':
28 unittest.main()
29
30=== added directory 'license_protected_downloads/tests/testserver_root/open'
31=== added file 'license_protected_downloads/tests/testserver_root/open/.hidden.txt'
32=== added file 'license_protected_downloads/tests/testserver_root/open/OPEN-EULA.txt'
33=== modified file 'license_protected_downloads/views.py'
34--- license_protected_downloads/views.py 2012-08-20 15:41:26 +0000
35+++ license_protected_downloads/views.py 2012-08-22 13:54:30 +0000
36@@ -26,7 +26,7 @@
37
38
39 def _hidden_file(file_name):
40- hidden_files = ["BUILD-INFO.txt", "EULA.txt", ".htaccess", "HEADER.html"]
41+ hidden_files = ["BUILD-INFO.txt", "EULA.txt", r"^\.", "HEADER.html"]
42 for pattern in hidden_files:
43 if re.search(pattern, file_name):
44 return True
45@@ -34,7 +34,7 @@
46
47
48 def _hidden_dir(file_name):
49- hidden_files = [".*openid.*", ".*restricted.*", ".*private.*"]
50+ hidden_files = [".*openid.*", ".*restricted.*", ".*private.*", r"^\."]
51 for pattern in hidden_files:
52 if re.search(pattern, file_name):
53 return True
54@@ -246,6 +246,20 @@
55 return redirect('/')
56
57
58+def file_listed(path, url):
59+ """Boolean response to "does this files show up in a directory listing."""
60+ file_name = os.path.basename(path)
61+ dir_name = os.path.dirname(path)
62+
63+ found = False
64+ file_list = dir_list(url, dir_name)
65+ for file in file_list:
66+ if file["name"] == file_name:
67+ found = True
68+
69+ return found
70+
71+
72 def file_server(request, path):
73 url = path
74 result = test_path(path)
75@@ -293,6 +307,12 @@
76
77 file_name = os.path.basename(path)
78
79+ # If the file listing doesn't contain the file requested for download,
80+ # return a 404. This prevents the download of BUILD-INFO.txt and other
81+ # hidden files.
82+ if not file_listed(path, url):
83+ raise Http404
84+
85 response = None
86 if get_client_ip(request) in config.INTERNAL_HOSTS:
87 digests = 'OPEN'
88
89=== added directory 'sampleroot/open'
90=== added file 'sampleroot/open/.hidden.txt'
91=== added file 'sampleroot/open/OPEN-EULA.txt'

Subscribers

People subscribed via source and target branches