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
=== modified file 'license_protected_downloads/tests/test_views.py'
--- license_protected_downloads/tests/test_views.py 2012-08-16 09:47:06 +0000
+++ license_protected_downloads/tests/test_views.py 2012-08-20 15:43:35 +0000
@@ -395,5 +395,21 @@
395 # Test that we use the "samsung" theme. This contains exynos.png395 # Test that we use the "samsung" theme. This contains exynos.png
396 self.assertContains(response, "exynos.png")396 self.assertContains(response, "exynos.png")
397397
398 def test_broken_build_info_directory(self):
399 target_file = "build-info/broken-build-info"
400 url = urlparse.urljoin("http://testserver/", target_file)
401 response = self.client.get(url, follow=True)
402
403 # If a build-info file is invalid, we don't allow access
404 self.assertEqual(response.status_code, 403)
405
406 def test_broken_build_info_file(self):
407 target_file = "build-info/broken-build-info/test.txt"
408 url = urlparse.urljoin("http://testserver/", target_file)
409 response = self.client.get(url, follow=True)
410
411 # If a build-info file is invalid, we don't allow access
412 self.assertEqual(response.status_code, 403)
413
398if __name__ == '__main__':414if __name__ == '__main__':
399 unittest.main()415 unittest.main()
400416
=== added directory 'license_protected_downloads/tests/testserver_root/build-info/broken-build-info'
=== added file 'license_protected_downloads/tests/testserver_root/build-info/broken-build-info/BUILD-INFO.txt'
--- license_protected_downloads/tests/testserver_root/build-info/broken-build-info/BUILD-INFO.txt 1970-01-01 00:00:00 +0000
+++ license_protected_downloads/tests/testserver_root/build-info/broken-build-info/BUILD-INFO.txt 2012-08-20 15:43:35 +0000
@@ -0,0 +1,13 @@
1Format-Version: 0asdfk
2
3Files-Patternasdfjklh: *
4Build-Name: landing-snowball
5Theme: stericsson
6License-Type: protasdklfjasfected
7License-Text: <p>IMPORTANT — PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY.</p>
8 <p>
9 This Agreement is a legally binding contract between you - either an
10 individual or a legal entity - (hereinafter referred to as "Licensee")
11 and ST-Ericsson SA, a company incorporated under the laws of
12 Switzerland (hereinafter referred to as "ST-Ericsson").
13 </p>
014
=== added file 'license_protected_downloads/tests/testserver_root/build-info/broken-build-info/test.txt'
--- license_protected_downloads/tests/testserver_root/build-info/broken-build-info/test.txt 1970-01-01 00:00:00 +0000
+++ license_protected_downloads/tests/testserver_root/build-info/broken-build-info/test.txt 2012-08-20 15:43:35 +0000
@@ -0,0 +1,1 @@
1This is protected with click-through Linaro license.
02
=== modified file 'license_protected_downloads/views.py'
--- license_protected_downloads/views.py 2012-08-16 09:47:06 +0000
+++ license_protected_downloads/views.py 2012-08-20 15:43:35 +0000
@@ -2,7 +2,6 @@
2import hashlib2import hashlib
3import mimetypes3import mimetypes
4import os4import os
5import os.path
6import re5import re
7import time6import time
8from mimetypes import guess_type7from mimetypes import guess_type
@@ -19,7 +18,7 @@
19from django.utils.encoding import smart_str18from django.utils.encoding import smart_str
2019
21import bzr_version20import bzr_version
22from buildinfo import BuildInfo21from buildinfo import BuildInfo, IncorrectDataFormatException
23from models import License22from models import License
24from openid_auth import OpenIDAuth23from openid_auth import OpenIDAuth
25from BeautifulSoup import BeautifulSoup24from BeautifulSoup import BeautifulSoup
@@ -134,8 +133,15 @@
134 buildinfo_path = os.path.join(os.path.dirname(path), "BUILD-INFO.txt")133 buildinfo_path = os.path.join(os.path.dirname(path), "BUILD-INFO.txt")
135 open_eula_path = os.path.join(os.path.dirname(path), "OPEN-EULA.txt")134 open_eula_path = os.path.join(os.path.dirname(path), "OPEN-EULA.txt")
136 eula_path = os.path.join(os.path.dirname(path), "EULA.txt")135 eula_path = os.path.join(os.path.dirname(path), "EULA.txt")
136
137 if os.path.isfile(buildinfo_path):137 if os.path.isfile(buildinfo_path):
138 build_info = BuildInfo(path)138 try:
139 build_info = BuildInfo(path)
140 except IncorrectDataFormatException:
141 # If we can't parse the BuildInfo, return [], which indicates no
142 # license in dir_list and will trigger a 403 error in file_server.
143 return []
144
139 license_type = build_info.get("license-type")145 license_type = build_info.get("license-type")
140 license_text = build_info.get("license-text")146 license_text = build_info.get("license-text")
141 theme = build_info.get("theme")147 theme = build_info.get("theme")
@@ -250,7 +256,13 @@
250 path = result[1]256 path = result[1]
251257
252 if BuildInfo.build_info_exists(path):258 if BuildInfo.build_info_exists(path):
253 build_info = BuildInfo(path)259 try:
260 build_info = BuildInfo(path)
261 except IncorrectDataFormatException:
262 # If we can't parse the BuildInfo. Return a HttpResponseForbidden.
263 return HttpResponseForbidden(
264 "Error parsing BUILD-INFO.txt")
265
254 launchpad_teams = build_info.get("openid-launchpad-teams")266 launchpad_teams = build_info.get("openid-launchpad-teams")
255 if launchpad_teams:267 if launchpad_teams:
256 launchpad_teams = launchpad_teams.split(",")268 launchpad_teams = launchpad_teams.split(",")
257269
=== added directory 'sampleroot/build-info/broken-build-info'
=== added file 'sampleroot/build-info/broken-build-info/BUILD-INFO.txt'
--- sampleroot/build-info/broken-build-info/BUILD-INFO.txt 1970-01-01 00:00:00 +0000
+++ sampleroot/build-info/broken-build-info/BUILD-INFO.txt 2012-08-20 15:43:35 +0000
@@ -0,0 +1,13 @@
1Format-Version: 0asdfk
2
3Files-Patternasdfjklh: *
4Build-Name: landing-snowball
5Theme: stericsson
6License-Type: protasdklfjasfected
7License-Text: <p>IMPORTANT — PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY.</p>
8 <p>
9 This Agreement is a legally binding contract between you - either an
10 individual or a legal entity - (hereinafter referred to as "Licensee")
11 and ST-Ericsson SA, a company incorporated under the laws of
12 Switzerland (hereinafter referred to as "ST-Ericsson").
13 </p>
014
=== added file 'sampleroot/build-info/broken-build-info/test.txt'
--- sampleroot/build-info/broken-build-info/test.txt 1970-01-01 00:00:00 +0000
+++ sampleroot/build-info/broken-build-info/test.txt 2012-08-20 15:43:35 +0000
@@ -0,0 +1,1 @@
1This is protected with click-through Linaro license.

Subscribers

People subscribed via source and target branches