diff options
author | James Tunnicliffe <james.tunnicliffe@linaro.org> | 2012-08-22 13:44:15 +0100 |
---|---|---|
committer | James Tunnicliffe <james.tunnicliffe@linaro.org> | 2012-08-22 13:44:15 +0100 |
commit | f11c59376d0e61ac11c088fd5b2da0fefa1ec3ea (patch) | |
tree | 5219272d82adf8056e585f9895b467972ce3b4fd /license_protected_downloads | |
parent | d19685ee691ccdfd4930eabaf17220f356a0b8ba (diff) |
Files not matched in BUILD-INFO.txt should be inaccessible.
Diffstat (limited to 'license_protected_downloads')
6 files changed, 56 insertions, 3 deletions
diff --git a/license_protected_downloads/tests/test_views.py b/license_protected_downloads/tests/test_views.py index 1f6857c..8393a72 100644 --- a/license_protected_downloads/tests/test_views.py +++ b/license_protected_downloads/tests/test_views.py @@ -411,5 +411,39 @@ class ViewTests(TestCase): # If a build-info file is invalid, we don't allow access self.assertEqual(response.status_code, 403) + def test_partial_build_info_file_open(self): + target_file = ("partial-license-settings/" + "partially-complete-build-info/" + "should_be_open.txt") + url = urlparse.urljoin("http://testserver/", target_file) + response = self.client.get(url, follow=True) + + # If a build-info file specifies this file is open + self.assertEqual(response.status_code, 200) + + def test_partial_build_info_file_protected(self): + target_file = ("partial-license-settings/" + "partially-complete-build-info/" + "should_be_protected.txt") + file_path = os.path.join(TESTSERVER_ROOT, target_file) + build_info = BuildInfo(file_path) + + # Try to fetch file from server - we should be redirected + url = urlparse.urljoin("http://testserver/", target_file) + response = self.client.get(url, follow=True) + digest = hashlib.md5(build_info.get("license-text")).hexdigest() + self.assertRedirects(response, '/license?lic=%s&url=%s' % + (digest, target_file)) + + def test_partial_build_info_file_unspecified(self): + target_file = ("partial-license-settings/" + "partially-complete-build-info/" + "should_be_inaccessible.txt") + url = urlparse.urljoin("http://testserver/", target_file) + response = self.client.get(url, follow=True) + + # If a build-info file has no information about this file + self.assertEqual(response.status_code, 403) + if __name__ == '__main__': unittest.main() diff --git a/license_protected_downloads/tests/testserver_root/partial-license-settings/partially-complete-build-info/BUILD-INFO.txt b/license_protected_downloads/tests/testserver_root/partial-license-settings/partially-complete-build-info/BUILD-INFO.txt new file mode 100644 index 0000000..2fe14c7 --- /dev/null +++ b/license_protected_downloads/tests/testserver_root/partial-license-settings/partially-complete-build-info/BUILD-INFO.txt @@ -0,0 +1,13 @@ +Format-Version: 0.1 + +Files-Pattern: *protected* +Build-Name: landing-multi-license +Theme: samsung +License-Type: protected +License-Text: <p>IMPORTANT — PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY.</p> + <p> + </p> + +Files-Pattern: *open* +Build-Name: false-positive +License-Type: open diff --git a/license_protected_downloads/tests/testserver_root/partial-license-settings/partially-complete-build-info/should_be_inaccessible.txt b/license_protected_downloads/tests/testserver_root/partial-license-settings/partially-complete-build-info/should_be_inaccessible.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/license_protected_downloads/tests/testserver_root/partial-license-settings/partially-complete-build-info/should_be_inaccessible.txt diff --git a/license_protected_downloads/tests/testserver_root/partial-license-settings/partially-complete-build-info/should_be_open.txt b/license_protected_downloads/tests/testserver_root/partial-license-settings/partially-complete-build-info/should_be_open.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/license_protected_downloads/tests/testserver_root/partial-license-settings/partially-complete-build-info/should_be_open.txt diff --git a/license_protected_downloads/tests/testserver_root/partial-license-settings/partially-complete-build-info/should_be_protected.txt b/license_protected_downloads/tests/testserver_root/partial-license-settings/partially-complete-build-info/should_be_protected.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/license_protected_downloads/tests/testserver_root/partial-license-settings/partially-complete-build-info/should_be_protected.txt diff --git a/license_protected_downloads/views.py b/license_protected_downloads/views.py index 806800d..b8b568b 100644 --- a/license_protected_downloads/views.py +++ b/license_protected_downloads/views.py @@ -177,7 +177,11 @@ def is_protected(path): digests = [] - if license_type and license_type != "open": + if license_type: + if license_type == "open": + return "OPEN" + + # File matches a license, isn't open. if openid_teams: return "OPEN" elif license_text: @@ -189,9 +193,11 @@ def is_protected(path): digests.append(digest) _insert_license_into_db(digest, license_text, theme) else: - return None + # No license text - file as inaccessible. + return [] else: - return "OPEN" + # No license found - file is inaccessible. + return [] return digests |