diff options
author | Paul Sokolovsky <paul.sokolovsky@linaro.org> | 2012-06-28 15:51:25 +0300 |
---|---|---|
committer | Paul Sokolovsky <paul.sokolovsky@linaro.org> | 2012-06-28 15:51:25 +0300 |
commit | c7533ed50f860a75edf050860cf6da2755708043 (patch) | |
tree | 5e7862a4acbd988c694c70e5ab3a4b04a7eb803a | |
parent | a92eb9cd89c2b622a0846a842bb3be36c3a75a7a (diff) | |
parent | 0f15e7368c6ea83a0f9152e97ad732fb3bb4e69d (diff) |
[merge] Merge upstream branch.
-rw-r--r-- | android/build-info/BUILD-INFO.txt | 10 | ||||
-rw-r--r-- | android/build-info/false-positive.txt | 1 | ||||
-rw-r--r-- | license_protected_downloads/buildinfo.py | 15 | ||||
-rw-r--r-- | license_protected_downloads/tests/test_buildinfo.py | 26 | ||||
-rw-r--r-- | license_protected_downloads/tests/test_views.py | 55 | ||||
-rw-r--r-- | license_protected_downloads/tests/testserver_root/build-info/BUILD-INFO.txt | 31 | ||||
-rw-r--r-- | license_protected_downloads/tests/testserver_root/build-info/multi-license.txt | 1 | ||||
-rw-r--r-- | license_protected_downloads/tests/testserver_root/images/snowball-blob.txt.EULA.txt.ste (renamed from license_protected_downloads/tests/testserver_root/images/snowball-blob.EULA.txt.ste) | 0 |
8 files changed, 128 insertions, 11 deletions
diff --git a/android/build-info/BUILD-INFO.txt b/android/build-info/BUILD-INFO.txt index 762ec8e..9922fa8 100644 --- a/android/build-info/BUILD-INFO.txt +++ b/android/build-info/BUILD-INFO.txt @@ -54,3 +54,13 @@ License-Type: protected License-Text: <p>IMPORTANT — PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY.</p> <p> </p> + +Files-Pattern: *false* +Build-Name: false-positive +Theme: stericsson +License-Type: protected +License-Text: License to accept + +Files-Pattern: *false* +Build-Name: false-positive +License-Type: open diff --git a/android/build-info/false-positive.txt b/android/build-info/false-positive.txt new file mode 100644 index 0000000..71a34cf --- /dev/null +++ b/android/build-info/false-positive.txt @@ -0,0 +1 @@ +This is protected with click-through Samsung and ST-E licenses.
\ No newline at end of file diff --git a/license_protected_downloads/buildinfo.py b/license_protected_downloads/buildinfo.py index 04c492c..7bd7171 100644 --- a/license_protected_downloads/buildinfo.py +++ b/license_protected_downloads/buildinfo.py @@ -21,6 +21,7 @@ class BuildInfo: self.readFile() self.parseData(self.lines) self.file_info_array = self.getInfoForFile() + self.remove_false_positives() self.max_index = len(self.file_info_array) @@ -152,6 +153,20 @@ class BuildInfo: break return text + def remove_false_positives(self): + open_type = [] + protected_type = [] + index = 0 + for block in self.file_info_array: + if block["license-type"] == 'open': + open_type.append(index) + if block["license-type"] == 'protected': + protected_type.append(index) + index += 1 + if len(protected_type) != 0 and len(open_type) != 0: + for index in open_type: + self.file_info_array.pop(index) + if __name__ == "__main__": bi = BuildInfo("/var/www/build-info/origen-blob.txt") # print bi.build_info_array diff --git a/license_protected_downloads/tests/test_buildinfo.py b/license_protected_downloads/tests/test_buildinfo.py index abab3c4..e86bfbb 100644 --- a/license_protected_downloads/tests/test_buildinfo.py +++ b/license_protected_downloads/tests/test_buildinfo.py @@ -178,6 +178,32 @@ class BuildInfoTests(unittest.TestCase): for field in build_info.fields_defined: self.assertTrue(build_info.isValidField(field)) + def test_remove_false_positives_real(self): + build_info = BuildInfo(self.buildinfo_file_path) + build_info.build_info_array = [{}] + build_info.file_info_array = [{}] + data = ["Format-Version: 2.0", "Files-Pattern: *.txt", "License-Type: protected", + "Files-Pattern: *.txt", "License-Type: open"] + build_info.parseData(data) + build_info.file_info_array = build_info.getInfoForFile() + build_info.remove_false_positives() + + self.assertEquals(build_info.file_info_array, + [{'license-type': 'protected'}]) + + def test_remove_false_none(self): + build_info = BuildInfo(self.buildinfo_file_path) + build_info.build_info_array = [{}] + build_info.file_info_array = [{}] + data = ["Format-Version: 2.0", "Files-Pattern: *.txt", "License-Type: protected", + "Files-Pattern: *.txt", "License-Type: protected"] + build_info.parseData(data) + build_info.file_info_array = build_info.getInfoForFile() + build_info.remove_false_positives() + + self.assertEquals(build_info.file_info_array, + [{'license-type': 'protected'}, {'license-type': 'protected'}]) + def test_get_search_path(self): dir_path = THIS_DIRECTORY + '/testserver_root/build-info/subdir' diff --git a/license_protected_downloads/tests/test_views.py b/license_protected_downloads/tests/test_views.py index 5ef66cc..68d3f28 100644 --- a/license_protected_downloads/tests/test_views.py +++ b/license_protected_downloads/tests/test_views.py @@ -101,15 +101,15 @@ class ViewTests(TestCase): # Test that we use the "linaro" theme. This contains linaro.png self.assertContains(response, "linaro.png") - def set_up_license(self, target_file): + def set_up_license(self, target_file, index=0): # Get BuildInfo for target file file_path = os.path.join(TESTSERVER_ROOT, target_file) build_info = BuildInfo(file_path) # Insert license information into database - text = build_info.get("license-text") + text = build_info.get("license-text", index) digest = hashlib.md5(text).hexdigest() - theme = "samsung" + theme = build_info.get("theme", index) _insert_license_into_db(digest, text, theme) return digest @@ -282,5 +282,54 @@ class ViewTests(TestCase): file_path = os.path.join(TESTSERVER_ROOT, target_file) self.assertEqual(response['X-Sendfile'], file_path) + def test_redirect_to_file_on_accept_multi_license(self): + target_file = "build-info/multi-license.txt" + digest = self.set_up_license(target_file) + + # Accept the first license for our file... + accept_url = '/accept-license?lic=%s&url=%s' % (digest, target_file) + response = self.client.post(accept_url, {"accept": "accept"}) + + # We should have a license accept cookie. + accept_cookie_name = "license_accepted_" + digest + self.assertTrue(accept_cookie_name in response.cookies) + + # We should get redirected back to the original file location. + self.assertEqual(response.status_code, 302) + url = urlparse.urljoin("http://testserver/", target_file) + listing_url = os.path.dirname(url) + self.assertEqual(response['Location'], + listing_url + "?dl=/" + target_file) + + client = Client() + client.cookies[accept_cookie_name] = accept_cookie_name + + digest = self.set_up_license(target_file, 1) + + # Accept the second license for our file... + accept_url = '/accept-license?lic=%s&url=%s' % (digest, target_file) + response = client.post(accept_url, {"accept": "accept"}) + + # We should have a license accept cookie. + accept_cookie_name1 = "license_accepted_" + digest + self.assertTrue(accept_cookie_name1 in response.cookies) + + # We should get redirected back to the original file location. + self.assertEqual(response.status_code, 302) + url = urlparse.urljoin("http://testserver/", target_file) + listing_url = os.path.dirname(url) + self.assertEqual(response['Location'], + listing_url + "?dl=/" + target_file) + + client = Client() + client.cookies[accept_cookie_name] = accept_cookie_name + client.cookies[accept_cookie_name1] = accept_cookie_name1 + response = client.get(url) + + # If we have access to the file, we will get an X-Sendfile response + self.assertEqual(response.status_code, 200) + file_path = os.path.join(TESTSERVER_ROOT, target_file) + self.assertEqual(response['X-Sendfile'], file_path) + if __name__ == '__main__': unittest.main() diff --git a/license_protected_downloads/tests/testserver_root/build-info/BUILD-INFO.txt b/license_protected_downloads/tests/testserver_root/build-info/BUILD-INFO.txt index 4ddc2fc..b75bfd8 100644 --- a/license_protected_downloads/tests/testserver_root/build-info/BUILD-INFO.txt +++ b/license_protected_downloads/tests/testserver_root/build-info/BUILD-INFO.txt @@ -6,14 +6,10 @@ Theme: stericsson License-Type: protected License-Text: <p>IMPORTANT — PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY.</p> <p> - THIS IS A LEGALLY BINDING AGREEMENT BETWEEN YOU, an individual or a - legal entity, (“LICENSEE”) AND SAMSUNG ELECTRONICS CO., - LTD. (“SAMSUNG”). BY CLICKING THE "ACCEPT" BUTTON, OR BY DOWNLOADING OR - INSTALLING OR OTHERWISE USING THE SOFTWARE, YOU AGREE TO BE BOUND BY THE - TERMS OF THIS AGREEMENT. IF YOU DO NOT AGREE TO THE TERMS OF THIS - AGREEMENT OR ARE NOT AUTHORISED TO ACCEPT AND AGREE TO THE TERMS OF THE - AGREEMENT ON BEHALF OF YOUR LEGAL ENTITY, DO NOT DOWNLOAD, INSTALL OR - OTHERWISE USE THE SOFTWARE. + This Agreement is a legally binding contract between you - either an + individual or a legal entity - (hereinafter referred to as "Licensee") + and ST-Ericsson SA, a company incorporated under the laws of + Switzerland (hereinafter referred to as "ST-Ericsson"). </p> Files-Pattern: *origen* @@ -46,3 +42,22 @@ Files-Pattern: *openid* Build-Name: landing-protected License-Type: protected OpenID-Launchpad-Teams: linaro + +Files-Pattern: *multi* +Build-Name: landing-multi-license +Theme: stericsson +License-Type: protected +License-Text: <p>IMPORTANT — PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY.</p> + <p> + THIS IS A LEGALLY BINDING AGREEMENT BETWEEN YOU, an individual or a + legal entity, (“LICENSEE”) AND SAMSUNG ELECTRONICS CO., + </p> + +Files-Pattern: *multi* +Build-Name: landing-multi-license +Theme: samsung +License-Type: protected +License-Text: <p>IMPORTANT — PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY.</p> + <p> + </p> + diff --git a/license_protected_downloads/tests/testserver_root/build-info/multi-license.txt b/license_protected_downloads/tests/testserver_root/build-info/multi-license.txt new file mode 100644 index 0000000..71a34cf --- /dev/null +++ b/license_protected_downloads/tests/testserver_root/build-info/multi-license.txt @@ -0,0 +1 @@ +This is protected with click-through Samsung and ST-E licenses.
\ No newline at end of file diff --git a/license_protected_downloads/tests/testserver_root/images/snowball-blob.EULA.txt.ste b/license_protected_downloads/tests/testserver_root/images/snowball-blob.txt.EULA.txt.ste index e69de29..e69de29 100644 --- a/license_protected_downloads/tests/testserver_root/images/snowball-blob.EULA.txt.ste +++ b/license_protected_downloads/tests/testserver_root/images/snowball-blob.txt.EULA.txt.ste |