Merge lp:~dooferlad/linaro-license-protection/invalid-buildinfo-403 into lp:~linaro-automation/linaro-license-protection/trunk

Proposed by James Tunnicliffe
Status: Merged
Approved by: Stevan Radaković
Approved revision: 106
Merged at revision: 106
Proposed branch: lp:~dooferlad/linaro-license-protection/invalid-buildinfo-403
Merge into: lp:~linaro-automation/linaro-license-protection/trunk
Diff against target: 128 lines (+60/-4)
6 files modified
license_protected_downloads/tests/test_views.py (+16/-0)
license_protected_downloads/tests/testserver_root/build-info/broken-build-info/BUILD-INFO.txt (+13/-0)
license_protected_downloads/tests/testserver_root/build-info/broken-build-info/test.txt (+1/-0)
license_protected_downloads/views.py (+16/-4)
sampleroot/build-info/broken-build-info/BUILD-INFO.txt (+13/-0)
sampleroot/build-info/broken-build-info/test.txt (+1/-0)
To merge this branch: bzr merge lp:~dooferlad/linaro-license-protection/invalid-buildinfo-403
Reviewer Review Type Date Requested Status
Stevan Radaković code Approve
Review via email: mp+120417@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Stevan Radaković (stevanr) wrote :

Looks good.
Approve +1

review: Approve (code)

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-16 09:47:06 +0000
3+++ license_protected_downloads/tests/test_views.py 2012-08-20 15:43:35 +0000
4@@ -395,5 +395,21 @@
5 # Test that we use the "samsung" theme. This contains exynos.png
6 self.assertContains(response, "exynos.png")
7
8+ def test_broken_build_info_directory(self):
9+ target_file = "build-info/broken-build-info"
10+ url = urlparse.urljoin("http://testserver/", target_file)
11+ response = self.client.get(url, follow=True)
12+
13+ # If a build-info file is invalid, we don't allow access
14+ self.assertEqual(response.status_code, 403)
15+
16+ def test_broken_build_info_file(self):
17+ target_file = "build-info/broken-build-info/test.txt"
18+ url = urlparse.urljoin("http://testserver/", target_file)
19+ response = self.client.get(url, follow=True)
20+
21+ # If a build-info file is invalid, we don't allow access
22+ self.assertEqual(response.status_code, 403)
23+
24 if __name__ == '__main__':
25 unittest.main()
26
27=== added directory 'license_protected_downloads/tests/testserver_root/build-info/broken-build-info'
28=== added file 'license_protected_downloads/tests/testserver_root/build-info/broken-build-info/BUILD-INFO.txt'
29--- license_protected_downloads/tests/testserver_root/build-info/broken-build-info/BUILD-INFO.txt 1970-01-01 00:00:00 +0000
30+++ license_protected_downloads/tests/testserver_root/build-info/broken-build-info/BUILD-INFO.txt 2012-08-20 15:43:35 +0000
31@@ -0,0 +1,13 @@
32+Format-Version: 0asdfk
33+
34+Files-Patternasdfjklh: *
35+Build-Name: landing-snowball
36+Theme: stericsson
37+License-Type: protasdklfjasfected
38+License-Text: <p>IMPORTANT — PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY.</p>
39+ <p>
40+ This Agreement is a legally binding contract between you - either an
41+ individual or a legal entity - (hereinafter referred to as "Licensee")
42+ and ST-Ericsson SA, a company incorporated under the laws of
43+ Switzerland (hereinafter referred to as "ST-Ericsson").
44+ </p>
45
46=== added file 'license_protected_downloads/tests/testserver_root/build-info/broken-build-info/test.txt'
47--- license_protected_downloads/tests/testserver_root/build-info/broken-build-info/test.txt 1970-01-01 00:00:00 +0000
48+++ license_protected_downloads/tests/testserver_root/build-info/broken-build-info/test.txt 2012-08-20 15:43:35 +0000
49@@ -0,0 +1,1 @@
50+This is protected with click-through Linaro license.
51
52=== modified file 'license_protected_downloads/views.py'
53--- license_protected_downloads/views.py 2012-08-16 09:47:06 +0000
54+++ license_protected_downloads/views.py 2012-08-20 15:43:35 +0000
55@@ -2,7 +2,6 @@
56 import hashlib
57 import mimetypes
58 import os
59-import os.path
60 import re
61 import time
62 from mimetypes import guess_type
63@@ -19,7 +18,7 @@
64 from django.utils.encoding import smart_str
65
66 import bzr_version
67-from buildinfo import BuildInfo
68+from buildinfo import BuildInfo, IncorrectDataFormatException
69 from models import License
70 from openid_auth import OpenIDAuth
71 from BeautifulSoup import BeautifulSoup
72@@ -134,8 +133,15 @@
73 buildinfo_path = os.path.join(os.path.dirname(path), "BUILD-INFO.txt")
74 open_eula_path = os.path.join(os.path.dirname(path), "OPEN-EULA.txt")
75 eula_path = os.path.join(os.path.dirname(path), "EULA.txt")
76+
77 if os.path.isfile(buildinfo_path):
78- build_info = BuildInfo(path)
79+ try:
80+ build_info = BuildInfo(path)
81+ except IncorrectDataFormatException:
82+ # If we can't parse the BuildInfo, return [], which indicates no
83+ # license in dir_list and will trigger a 403 error in file_server.
84+ return []
85+
86 license_type = build_info.get("license-type")
87 license_text = build_info.get("license-text")
88 theme = build_info.get("theme")
89@@ -250,7 +256,13 @@
90 path = result[1]
91
92 if BuildInfo.build_info_exists(path):
93- build_info = BuildInfo(path)
94+ try:
95+ build_info = BuildInfo(path)
96+ except IncorrectDataFormatException:
97+ # If we can't parse the BuildInfo. Return a HttpResponseForbidden.
98+ return HttpResponseForbidden(
99+ "Error parsing BUILD-INFO.txt")
100+
101 launchpad_teams = build_info.get("openid-launchpad-teams")
102 if launchpad_teams:
103 launchpad_teams = launchpad_teams.split(",")
104
105=== added directory 'sampleroot/build-info/broken-build-info'
106=== added file 'sampleroot/build-info/broken-build-info/BUILD-INFO.txt'
107--- sampleroot/build-info/broken-build-info/BUILD-INFO.txt 1970-01-01 00:00:00 +0000
108+++ sampleroot/build-info/broken-build-info/BUILD-INFO.txt 2012-08-20 15:43:35 +0000
109@@ -0,0 +1,13 @@
110+Format-Version: 0asdfk
111+
112+Files-Patternasdfjklh: *
113+Build-Name: landing-snowball
114+Theme: stericsson
115+License-Type: protasdklfjasfected
116+License-Text: <p>IMPORTANT — PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY.</p>
117+ <p>
118+ This Agreement is a legally binding contract between you - either an
119+ individual or a legal entity - (hereinafter referred to as "Licensee")
120+ and ST-Ericsson SA, a company incorporated under the laws of
121+ Switzerland (hereinafter referred to as "ST-Ericsson").
122+ </p>
123
124=== added file 'sampleroot/build-info/broken-build-info/test.txt'
125--- sampleroot/build-info/broken-build-info/test.txt 1970-01-01 00:00:00 +0000
126+++ sampleroot/build-info/broken-build-info/test.txt 2012-08-20 15:43:35 +0000
127@@ -0,0 +1,1 @@
128+This is protected with click-through Linaro license.

Subscribers

People subscribed via source and target branches