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

Proposed by James Tunnicliffe
Status: Merged
Approved by: Stevan Radaković
Approved revision: 108
Merged at revision: 109
Proposed branch: lp:~dooferlad/linaro-license-protection/files_default_protected
Merge into: lp:~linaro-automation/linaro-license-protection/trunk
Diff against target: 121 lines (+69/-3)
4 files modified
license_protected_downloads/tests/test_views.py (+34/-0)
license_protected_downloads/tests/testserver_root/partial-license-settings/partially-complete-build-info/BUILD-INFO.txt (+13/-0)
license_protected_downloads/views.py (+9/-3)
sampleroot/partial-license-settings/partially-complete-build-info/BUILD-INFO.txt (+13/-0)
To merge this branch: bzr merge lp:~dooferlad/linaro-license-protection/files_default_protected
Reviewer Review Type Date Requested Status
Stevan Radaković Approve
Review via email: mp+120773@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

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:37:44 +0000
4@@ -411,5 +411,39 @@
5 # If a build-info file is invalid, we don't allow access
6 self.assertEqual(response.status_code, 403)
7
8+ def test_partial_build_info_file_open(self):
9+ target_file = ("partial-license-settings/"
10+ "partially-complete-build-info/"
11+ "should_be_open.txt")
12+ url = urlparse.urljoin("http://testserver/", target_file)
13+ response = self.client.get(url, follow=True)
14+
15+ # If a build-info file specifies this file is open
16+ self.assertEqual(response.status_code, 200)
17+
18+ def test_partial_build_info_file_protected(self):
19+ target_file = ("partial-license-settings/"
20+ "partially-complete-build-info/"
21+ "should_be_protected.txt")
22+ file_path = os.path.join(TESTSERVER_ROOT, target_file)
23+ build_info = BuildInfo(file_path)
24+
25+ # Try to fetch file from server - we should be redirected
26+ url = urlparse.urljoin("http://testserver/", target_file)
27+ response = self.client.get(url, follow=True)
28+ digest = hashlib.md5(build_info.get("license-text")).hexdigest()
29+ self.assertRedirects(response, '/license?lic=%s&url=%s' %
30+ (digest, target_file))
31+
32+ def test_partial_build_info_file_unspecified(self):
33+ target_file = ("partial-license-settings/"
34+ "partially-complete-build-info/"
35+ "should_be_inaccessible.txt")
36+ url = urlparse.urljoin("http://testserver/", target_file)
37+ response = self.client.get(url, follow=True)
38+
39+ # If a build-info file has no information about this file
40+ self.assertEqual(response.status_code, 403)
41+
42 if __name__ == '__main__':
43 unittest.main()
44
45=== added directory 'license_protected_downloads/tests/testserver_root/partial-license-settings'
46=== added directory 'license_protected_downloads/tests/testserver_root/partial-license-settings/partially-complete-build-info'
47=== added file 'license_protected_downloads/tests/testserver_root/partial-license-settings/partially-complete-build-info/BUILD-INFO.txt'
48--- license_protected_downloads/tests/testserver_root/partial-license-settings/partially-complete-build-info/BUILD-INFO.txt 1970-01-01 00:00:00 +0000
49+++ license_protected_downloads/tests/testserver_root/partial-license-settings/partially-complete-build-info/BUILD-INFO.txt 2012-08-22 13:37:44 +0000
50@@ -0,0 +1,13 @@
51+Format-Version: 0.1
52+
53+Files-Pattern: *protected*
54+Build-Name: landing-multi-license
55+Theme: samsung
56+License-Type: protected
57+License-Text: <p>IMPORTANT — PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY.</p>
58+ <p>
59+ </p>
60+
61+Files-Pattern: *open*
62+Build-Name: false-positive
63+License-Type: open
64
65=== added file 'license_protected_downloads/tests/testserver_root/partial-license-settings/partially-complete-build-info/should_be_inaccessible.txt'
66=== added file 'license_protected_downloads/tests/testserver_root/partial-license-settings/partially-complete-build-info/should_be_open.txt'
67=== added file 'license_protected_downloads/tests/testserver_root/partial-license-settings/partially-complete-build-info/should_be_protected.txt'
68=== modified file 'license_protected_downloads/views.py'
69--- license_protected_downloads/views.py 2012-08-20 15:41:26 +0000
70+++ license_protected_downloads/views.py 2012-08-22 13:37:44 +0000
71@@ -177,7 +177,11 @@
72
73 digests = []
74
75- if license_type and license_type != "open":
76+ if license_type:
77+ if license_type == "open":
78+ return "OPEN"
79+
80+ # File matches a license, isn't open.
81 if openid_teams:
82 return "OPEN"
83 elif license_text:
84@@ -189,9 +193,11 @@
85 digests.append(digest)
86 _insert_license_into_db(digest, license_text, theme)
87 else:
88- return None
89+ # No license text - file as inaccessible.
90+ return []
91 else:
92- return "OPEN"
93+ # No license found - file is inaccessible.
94+ return []
95
96 return digests
97
98
99=== added directory 'sampleroot/partial-license-settings'
100=== added directory 'sampleroot/partial-license-settings/partially-complete-build-info'
101=== added file 'sampleroot/partial-license-settings/partially-complete-build-info/BUILD-INFO.txt'
102--- sampleroot/partial-license-settings/partially-complete-build-info/BUILD-INFO.txt 1970-01-01 00:00:00 +0000
103+++ sampleroot/partial-license-settings/partially-complete-build-info/BUILD-INFO.txt 2012-08-22 13:37:44 +0000
104@@ -0,0 +1,13 @@
105+Format-Version: 0.1
106+
107+Files-Pattern: *protected*
108+Build-Name: landing-multi-license
109+Theme: samsung
110+License-Type: protected
111+License-Text: <p>IMPORTANT — PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY.</p>
112+ <p>
113+ </p>
114+
115+Files-Pattern: *open*
116+Build-Name: false-positive
117+License-Type: open
118
119=== added file 'sampleroot/partial-license-settings/partially-complete-build-info/should_be_inaccessible.txt'
120=== added file 'sampleroot/partial-license-settings/partially-complete-build-info/should_be_open.txt'
121=== added file 'sampleroot/partial-license-settings/partially-complete-build-info/should_be_protected.txt'

Subscribers

People subscribed via source and target branches