aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Tunnicliffe <james.tunnicliffe@linaro.org>2012-06-26 19:50:23 +0100
committerJames Tunnicliffe <james.tunnicliffe@linaro.org>2012-06-26 19:50:23 +0100
commit26ecf1a01d9a7ea3b58ee9d63d8e3f6102afd495 (patch)
treee0d5e7e852544b604f881fed2a0a4ec9a9905526
parent6a7cf687fe8dd0b97b0dba9502a39caa77343d94 (diff)
Moved tests into their own directory so we can be more modular.
Started on license tests. Added 404 page (required by Django).
-rw-r--r--license_protected_downloads/tests/BUILD-INFO.txt (renamed from license_protected_downloads/BUILD-INFO.txt)0
-rw-r--r--license_protected_downloads/tests/__init__.py10
-rw-r--r--license_protected_downloads/tests/lic_view_buildinfo.py (renamed from license_protected_downloads/tests.py)77
-rw-r--r--license_protected_downloads/tests/license_protected_file_downloader.py (renamed from tests/license_protected_file_downloader.py)0
-rw-r--r--license_protected_downloads/tests/test_click_through_license.py330
-rw-r--r--license_protected_downloads/views.py3
-rw-r--r--templates/404.html5
7 files changed, 397 insertions, 28 deletions
diff --git a/license_protected_downloads/BUILD-INFO.txt b/license_protected_downloads/tests/BUILD-INFO.txt
index df7ff21..df7ff21 100644
--- a/license_protected_downloads/BUILD-INFO.txt
+++ b/license_protected_downloads/tests/BUILD-INFO.txt
diff --git a/license_protected_downloads/tests/__init__.py b/license_protected_downloads/tests/__init__.py
new file mode 100644
index 0000000..64fd323
--- /dev/null
+++ b/license_protected_downloads/tests/__init__.py
@@ -0,0 +1,10 @@
+from license_protected_downloads.tests.lic_view_buildinfo import *
+#from license_protected_downloads.tests.test_click_through_license import *
+
+#starts the test suite
+__test__= {
+ 'LicenseTestCase': LicenseTestCase,
+ 'ViewTests': ViewTests,
+ 'BuildInfoTests': BuildInfoTests,
+ #'TestLicense': TestLicense,
+}
diff --git a/license_protected_downloads/tests.py b/license_protected_downloads/tests/lic_view_buildinfo.py
index 102264f..e364331 100644
--- a/license_protected_downloads/tests.py
+++ b/license_protected_downloads/tests/lic_view_buildinfo.py
@@ -1,5 +1,8 @@
+from license_protected_downloads.views import _insert_license_into_db
+
__author__ = 'dooferlad'
+import os
import unittest
import hashlib
from django.test import Client, TestCase
@@ -7,6 +10,7 @@ from license_protected_downloads.models import License
from license_protected_downloads.buildinfo import BuildInfo
from license_protected_downloads.buildinfo import IncorrectDataFormatException
+THIS_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
class LicenseTestCase(TestCase):
def setUp(self):
@@ -34,19 +38,36 @@ class LicenseTestCase(TestCase):
class ViewTests(TestCase):
def setUp(self):
self.client = Client()
+ buildinfo_file_path = os.path.join(THIS_DIRECTORY,
+ "BUILD-INFO.txt")
+ self.build_info = BuildInfo(buildinfo_file_path)
- def test_license_directly(self):
- response = self.client.get('/licenses/license.html')
- self.assertEqual(response.status_code, 200)
- self.assertContains(response, 'Index of /')
+ lic1_text = 'Samsung License'
+ self.digest1 = hashlib.md5(lic1_text).hexdigest()
+
+ def test_license_directly_samsung(self):
+ text = self.build_info.get("license-text")
+ digest = hashlib.md5(text).hexdigest()
+ theme = "samsung"
- def test_licensefile_directly_samsung(self):
- response = self.client.get('/licenses/samsung.html')
+ _insert_license_into_db(digest, text, theme)
+
+ url = "/"
+ response = self.client.get('/license?lic=%s&url=%s' % (digest, url))
self.assertEqual(response.status_code, 200)
- self.assertContains(response, 'Index of /')
+
+ # Make sure that we get the license text in the license page
+ self.assertContains(response, text)
+
+ # Test that we use the "samsung" theme. This contains exynos.png
+ self.assertContains(response, "exynos.png")
class BuildInfoTests(unittest.TestCase):
+ def setUp(self):
+ self.buildinfo_file_path = os.path.join(THIS_DIRECTORY,
+ "BUILD-INFO.txt")
+
def test_readFile_nonFile(self):
with self.assertRaises(IOError):
build_info = BuildInfo("license_protected_downloads")
@@ -56,17 +77,17 @@ class BuildInfoTests(unittest.TestCase):
build_info = BuildInfo("nonexistent.file")
def test_readFile_File(self):
- build_info = BuildInfo("license_protected_downloads/BUILD-INFO.txt")
+ build_info = BuildInfo(self.buildinfo_file_path)
self.assertIn("Files-Pattern: *.txt", build_info.lines)
def test_getFormatVersion(self):
- build_info = BuildInfo("license_protected_downloads/BUILD-INFO.txt")
+ build_info = BuildInfo(self.buildinfo_file_path)
self.assertEqual("0.1", build_info.getFormatVersion())
def test_get_emptyField(self):
- build_info = BuildInfo("license_protected_downloads/BUILD-INFO.txt")
+ build_info = BuildInfo(self.buildinfo_file_path)
for pair in build_info.file_info_array:
if "openid-launchpad-teams" in pair:
value = pair["openid-launchpad-teams"]
@@ -74,7 +95,7 @@ class BuildInfoTests(unittest.TestCase):
self.assertFalse(value)
def test_get(self):
- build_info = BuildInfo("license_protected_downloads/BUILD-INFO.txt")
+ build_info = BuildInfo(self.buildinfo_file_path)
for pair in build_info.file_info_array:
if "build-name" in pair:
value = pair["build-name"]
@@ -83,38 +104,38 @@ class BuildInfoTests(unittest.TestCase):
def test_parseLine_fails(self):
line = "no separator"
- build_info = BuildInfo("license_protected_downloads/BUILD-INFO.txt")
+ build_info = BuildInfo(self.buildinfo_file_path)
with self.assertRaises(IncorrectDataFormatException):
build_info.parseLine(line)
def test_parseLine_passes(self):
line = "Build-Name:value"
- build_info = BuildInfo("license_protected_downloads/BUILD-INFO.txt")
+ build_info = BuildInfo(self.buildinfo_file_path)
self.assertDictEqual({"build-name":"value"}, build_info.parseLine(line))
def test_parseLine_trims(self):
line = "Build-Name: value"
- build_info = BuildInfo("license_protected_downloads/BUILD-INFO.txt")
+ build_info = BuildInfo(self.buildinfo_file_path)
self.assertDictEqual({"build-name":"value"}, build_info.parseLine(line))
def test_parseLine_invalid_field(self):
line = "field: value"
- build_info = BuildInfo("license_protected_downloads/BUILD-INFO.txt")
+ build_info = BuildInfo(self.buildinfo_file_path)
with self.assertRaises(IncorrectDataFormatException):
build_info.parseLine(line)
def test_parseData_no_format_version_fails(self):
- build_info = BuildInfo("license_protected_downloads/BUILD-INFO.txt")
+ build_info = BuildInfo(self.buildinfo_file_path)
with self.assertRaises(IncorrectDataFormatException):
build_info.parseData(["Build-Name: blah"])
def test_parseData_blocks(self):
- build_info = BuildInfo("license_protected_downloads/BUILD-INFO.txt")
+ build_info = BuildInfo(self.buildinfo_file_path)
build_info.build_info_array = [{}]
data = ["Format-Version: 2.0", "Files-Pattern: *.txt", "Build-Name: weehee",
"Files-Pattern: *.tgz", "Build-Name: woohoo"]
@@ -126,7 +147,7 @@ class BuildInfoTests(unittest.TestCase):
'*.tgz': [{'build-name': 'woohoo'}]}])
def test_parseData_block_multiple_patterns(self):
- build_info = BuildInfo("license_protected_downloads/BUILD-INFO.txt")
+ build_info = BuildInfo(self.buildinfo_file_path)
build_info.build_info_array = [{}]
data = ["Format-Version: 2.0", "Files-Pattern: *.txt,*.tgz",
"Build-Name: weehee"]
@@ -138,26 +159,26 @@ class BuildInfoTests(unittest.TestCase):
'*.tgz': [{'build-name': 'weehee'}]}])
def test_parseContinuation_no_continuation(self):
- build_info = BuildInfo("license_protected_downloads/BUILD-INFO.txt")
+ build_info = BuildInfo(self.buildinfo_file_path)
build_info.line_no = 0
self.assertEquals("", build_info.parseContinuation(["no-space"]))
def test_parseContinuation_indexed(self):
- build_info = BuildInfo("license_protected_downloads/BUILD-INFO.txt")
+ build_info = BuildInfo(self.buildinfo_file_path)
build_info.line_no = 0
self.assertEquals("", build_info.parseContinuation(["no-space", " space"]))
def test_parseContinuation(self):
- build_info = BuildInfo("license_protected_downloads/BUILD-INFO.txt")
+ build_info = BuildInfo(self.buildinfo_file_path)
build_info.line_no = 1
val = build_info.parseContinuation(["no-space", " line1", " line2"])
self.assertEquals("\nline1\nline2", val)
def test_parseBlock_license(self):
- build_info = BuildInfo("license_protected_downloads/BUILD-INFO.txt")
+ build_info = BuildInfo(self.buildinfo_file_path)
build_info.line_no = 0
build_info.build_info_array = [{}]
data = ["Format-Version: 2.0", "License-Text: line1", " line2"]
@@ -167,7 +188,7 @@ class BuildInfoTests(unittest.TestCase):
"license-text": "line1\nline2"}])
def test_parseData_extra_fields(self):
- build_info = BuildInfo("license_protected_downloads/BUILD-INFO.txt")
+ build_info = BuildInfo(self.buildinfo_file_path)
build_info.build_info_array = [{}]
data = ["Format-Version: 2.0", "Files-Pattern: *.txt", "Build-Name: woohoo"]
build_info.parseData(data)
@@ -177,7 +198,7 @@ class BuildInfoTests(unittest.TestCase):
'*.txt': [{'build-name': 'woohoo'}]}])
def test_parseData_format_version(self):
- build_info = BuildInfo("license_protected_downloads/BUILD-INFO.txt")
+ build_info = BuildInfo(self.buildinfo_file_path)
build_info.build_info_array = [{}]
data = ["Format-Version: 2.0"]
build_info.parseData(data)
@@ -186,7 +207,7 @@ class BuildInfoTests(unittest.TestCase):
[{"format-version": "2.0"}])
def test_parseData_array_expected(self):
- build_info = BuildInfo("license_protected_downloads/BUILD-INFO.txt")
+ build_info = BuildInfo(self.buildinfo_file_path)
build_info.build_info_array = [{}]
data = "Format-Version: 2.0"
@@ -194,7 +215,7 @@ class BuildInfoTests(unittest.TestCase):
build_info.parseData(data)
def test_parseData_fails(self):
- build_info = BuildInfo("license_protected_downloads/BUILD-INFO.txt")
+ build_info = BuildInfo(self.buildinfo_file_path)
build_info.build_info_array = [{}]
data = ["text"]
@@ -202,12 +223,12 @@ class BuildInfoTests(unittest.TestCase):
build_info.parseData(data)
def test_isValidField_false(self):
- build_info = BuildInfo("license_protected_downloads/BUILD-INFO.txt")
+ build_info = BuildInfo(self.buildinfo_file_path)
self.assertFalse(build_info.isValidField("field"))
def test_isValidField_true(self):
- build_info = BuildInfo("license_protected_downloads/BUILD-INFO.txt")
+ build_info = BuildInfo(self.buildinfo_file_path)
for field in build_info.fields_defined:
self.assertTrue(build_info.isValidField(field))
diff --git a/tests/license_protected_file_downloader.py b/license_protected_downloads/tests/license_protected_file_downloader.py
index 5726a56..5726a56 100644
--- a/tests/license_protected_file_downloader.py
+++ b/license_protected_downloads/tests/license_protected_file_downloader.py
diff --git a/license_protected_downloads/tests/test_click_through_license.py b/license_protected_downloads/tests/test_click_through_license.py
new file mode 100644
index 0000000..0c8fe05
--- /dev/null
+++ b/license_protected_downloads/tests/test_click_through_license.py
@@ -0,0 +1,330 @@
+#!/usr/bin/env python
+
+import re
+import os
+import shutil
+import shlex
+import subprocess
+import socket
+
+from django.test import Client, TestCase
+from testtools.matchers import Mismatch
+from license_protected_file_downloader import LicenseProtectedFileFetcher
+
+fetcher = LicenseProtectedFileFetcher()
+cwd = os.getcwd()
+docroot = cwd
+srvroot = os.path.abspath(os.path.join(*([cwd] + ['tests'])))
+local_rewrite = 'RewriteCond %{REMOTE_ADDR} 127.0.0.1 [OR]'
+
+host = 'http://127.0.0.1'
+port = '0' # 0 == Pick a free port.
+samsung_license_path = '/licenses/license.php'
+ste_license_path = '/licenses/license.php'
+linaro_license_path = '/licenses/license.php'
+samsung_test_file = '/android/~linaro-android/staging-origen/test.txt'
+ste_test_file = ('/android/~linaro-android/staging-snowball'
+ '/173/target/product/snowball/test.txt')
+ste_open_test_file = '/android/~linaro-android/staging-snowball/173/test.txt'
+never_available = '/android/~linaro-android/staging-imx53/test.txt'
+linaro_test_file = '/android/~linaro-android/staging-panda/test.txt'
+not_protected_test_file = ('/android/~linaro-android/staging-vexpress-a9'
+ '/test.txt')
+not_found_test_file = ('/android/~linaro-android/staging-vexpress-a9'
+ '/notfound.txt')
+per_file_samsung_test_file = '/android/images/origen-blob.txt'
+per_file_ste_test_file = '/android/images/snowball-blob.txt'
+per_file_not_protected_test_file = '/android/images/MANIFEST'
+dirs_only_dir = '/android/~linaro-android/'
+build_info_samsung_test_file = '/android/build-info/origen-blob.txt'
+build_info_ste_test_file = '/android/build-info/snowball-blob.txt'
+build_info_not_protected_test_file = '/android/build-info/panda-open.txt'
+build_info_openid_test_file = '/android/build-info/openid.txt'
+
+
+class Contains(object):
+ '''Match if a string contains substring'''
+ def __init__(self, substr):
+ self.substr = substr
+
+ def __str__(self):
+ return 'Contains(%s)' % (self.substr,)
+
+ def match(self, actual):
+ for line in actual.splitlines():
+ res = re.search(self.substr, line)
+ if res:
+ return None
+ return Mismatch("Initial string doesn't contain substring (%s)" %
+ self.substr)
+
+
+class CommandNotFoundException(Exception):
+ ''' Unable to find command '''
+
+
+class NonZeroReturnValueException(Exception):
+ ''' Command exited with nonzero return value '''
+
+
+class TestLicense(TestCase):
+ '''Tests for accessing files and directories with license protection'''
+
+ @classmethod
+ def setUpClass(cls):
+ global host
+ global port
+ if port == '0':
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ s.bind(('127.0.0.1', 0))
+ port = str(s.getsockname()[1])
+ s.close()
+ host = host + ':' + port
+ shutil.copy("%s/apache2.conf.tmpl" % srvroot, "%s/apache2.conf" %
+ srvroot)
+ shutil.copy("%s/.htaccess" % docroot, "%s/dothtaccess" % docroot)
+ subprocess.Popen(['sed', '-i', 's/ServerRoot \"\"/ServerRoot \"%s\"/'
+ % srvroot.replace('/', '\/'), '%s/apache2.conf' % srvroot],
+ stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT).wait()
+ subprocess.Popen(['sed', '-i', 's/DocumentRoot \"\"/DocumentRoot '
+ '\"%s\"/' % docroot.replace('/', '\/'), '%s/apache2.conf'
+ % srvroot], stdout=open('/dev/null', 'w'),
+ stderr=subprocess.STDOUT).wait()
+ subprocess.Popen(['sed', '-i', 's/Directory \"\"/Directory \"%s\"/'
+ % docroot.replace('/', '\/'), '%s/apache2.conf' % srvroot],
+ stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT).wait()
+ subprocess.Popen(['sed', '-i', 's/Listen/Listen %s/' % port,
+ '%s/apache2.conf' % srvroot], stdout=open('/dev/null', 'w'),
+ stderr=subprocess.STDOUT).wait()
+ if subprocess.Popen(['which', 'apache2'],
+ stdout=open('/dev/null', 'w'),
+ stderr=subprocess.STDOUT).wait():
+ raise CommandNotFoundException("apache2 command not found. Please "
+ "install apache2 web server and rerun tests.")
+ args = shlex.split('apache2 -d %s -f apache2.conf -k start' % srvroot)
+ rc = subprocess.Popen(args, stdout=open('/dev/null', 'w'),
+ stderr=subprocess.STDOUT).wait()
+ if rc:
+ raise NonZeroReturnValueException("apache2 server exited with "
+ "error %s" % rc)
+
+ @classmethod
+ def tearDownClass(cls):
+ if os.path.exists("%s/cookies.txt" % docroot):
+ os.unlink("%s/cookies.txt" % docroot)
+ args = shlex.split('apache2 -d %s -f apache2.conf -k stop' % srvroot)
+ subprocess.Popen(args, stdout=open('/dev/null', 'w'),
+ stderr=subprocess.STDOUT).wait()
+ if os.path.exists("%s/apache2.conf" % srvroot):
+ os.unlink("%s/apache2.conf" % srvroot)
+ if os.path.exists("%s/click_through_license_access.log" % srvroot):
+ os.unlink("%s/click_through_license_access.log" % srvroot)
+ if os.path.exists("%s/click_through_license_error.log" % srvroot):
+ os.unlink("%s/click_through_license_error.log" % srvroot)
+ if os.path.exists("%s/rewrite.log" % srvroot):
+ os.unlink("%s/rewrite.log" % srvroot)
+ os.rename("%s/dothtaccess" % docroot, "%s/.htaccess" % docroot)
+
+ def setUp(self):
+ super(TestLicense, self).setUp()
+ global fetcher
+ fetcher = LicenseProtectedFileFetcher()
+
+ def tearDown(self):
+ super(TestLicense, self).tearDown()
+ if isinstance(fetcher, LicenseProtectedFileFetcher):
+ fetcher.close()
+ if os.path.exists("%s/cookies.txt" % docroot):
+ os.unlink("%s/cookies.txt" % docroot)
+
+ def test_licensefile_directly_samsung(self):
+ search = "Index of /"
+ testfile = fetcher.get(host + samsung_license_path)
+ self.assertThat(testfile, Contains(search))
+
+ def test_licensefile_directly_ste(self):
+ search = "Index of /"
+ testfile = fetcher.get(host + ste_license_path)
+ self.assertThat(testfile, Contains(search))
+
+ def test_licensefile_directly_linaro(self):
+ search = "Index of /"
+ testfile = fetcher.get(host + linaro_license_path)
+ self.assertThat(testfile, Contains(search))
+
+ def test_redirect_to_license_samsung(self):
+ search = "PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY"
+ testfile = fetcher.get_or_return_license(host + samsung_test_file)
+ self.assertThat(testfile[0], Contains(search))
+
+ def test_redirect_to_license_ste(self):
+ search = "PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY"
+ testfile = fetcher.get_or_return_license(host + ste_test_file)
+ self.assertThat(testfile[0], Contains(search))
+
+ def test_redirect_to_license_linaro(self):
+ search = "Linaro license."
+ testfile = fetcher.get_or_return_license(host + linaro_test_file)
+ self.assertThat(testfile[0], Contains(search))
+
+ def test_decline_license_samsung(self):
+ search = "License has not been accepted"
+ testfile = fetcher.get(host + samsung_test_file, accept_license=False)
+ self.assertThat(testfile, Contains(search))
+
+ def test_decline_license_ste(self):
+ search = "License has not been accepted"
+ testfile = fetcher.get(host + ste_test_file, accept_license=False)
+ self.assertThat(testfile, Contains(search))
+
+ def test_decline_license_linaro(self):
+ search = "License has not been accepted"
+ testfile = fetcher.get(host + linaro_test_file, accept_license=False)
+ self.assertThat(testfile, Contains(search))
+
+ def test_non_protected_dirs(self):
+ search = "This is always available."
+ testfile = fetcher.get(host + not_protected_test_file)
+ self.assertThat(testfile, Contains(search))
+
+ def test_never_available_dirs(self):
+ search = "Forbidden"
+ testfile = fetcher.get(host + never_available)
+ self.assertThat(testfile, Contains(search))
+
+ def test_accept_license_samsung_file(self):
+ search = "This is protected with click-through Samsung license."
+ testfile = fetcher.get(host + samsung_test_file)
+ fetcher.close()
+ if os.path.exists("%s/cookies.txt" % docroot):
+ os.rename("%s/cookies.txt" % docroot,
+ "%s/cookies.samsung" % docroot)
+ self.assertThat(testfile, Contains(search))
+
+ def test_accept_license_samsung_dir(self):
+ search = "Index of /android/~linaro-android/staging-origen"
+ testfile = fetcher.get(host + os.path.dirname(samsung_test_file))
+ self.assertThat(testfile, Contains(search))
+
+ def test_accept_license_ste_file(self):
+ search = "This is protected with click-through ST-E license."
+ testfile = fetcher.get(host + ste_test_file)
+ fetcher.close()
+ if os.path.exists("%s/cookies.txt" % docroot):
+ os.rename("%s/cookies.txt" % docroot, "%s/cookies.ste" % docroot)
+ self.assertThat(testfile, Contains(search))
+
+ def test_accept_license_ste_dir(self):
+ search = "Index of /android/~linaro-android/staging-snowball"
+ testfile = fetcher.get(host + os.path.dirname(ste_test_file))
+ self.assertThat(testfile, Contains(search))
+
+ def test_license_accepted_samsung(self):
+ search = "This is protected with click-through Samsung license."
+ os.rename("%s/cookies.samsung" % docroot, "%s/cookies.txt" % docroot)
+ testfile = fetcher.get(host + samsung_test_file)
+ self.assertThat(testfile, Contains(search))
+
+ def test_license_accepted_ste(self):
+ search = "This is protected with click-through ST-E license."
+ os.rename("%s/cookies.ste" % docroot, "%s/cookies.txt" % docroot)
+ testfile = fetcher.get(host + ste_test_file)
+ self.assertThat(testfile, Contains(search))
+
+ def test_internal_host_samsung(self):
+ search = "This is protected with click-through Samsung license."
+ subprocess.Popen(['sed', '-i', '/## Let internal hosts through '
+ 'always./ a %s' % local_rewrite, '%s/.htaccess' % docroot],
+ stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT).wait()
+ testfile = fetcher.get(host + samsung_test_file, ignore_license=True)
+ shutil.copy("%s/dothtaccess" % docroot, "%s/.htaccess" % docroot)
+ self.assertThat(testfile, Contains(search))
+
+ def test_internal_host_ste(self):
+ search = "This is protected with click-through ST-E license."
+ subprocess.Popen(['sed', '-i', '/## Let internal hosts through '
+ 'always./ a %s' % local_rewrite, '%s/.htaccess' % docroot],
+ stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT).wait()
+ testfile = fetcher.get(host + ste_test_file, ignore_license=True)
+ shutil.copy("%s/dothtaccess" % docroot, "%s/.htaccess" % docroot)
+ self.assertThat(testfile, Contains(search))
+
+ def test_ste_open_file(self):
+ search = "This is always available."
+ testfile = fetcher.get(host + ste_open_test_file)
+ self.assertThat(testfile, Contains(search))
+
+ def test_per_file_accept_license_samsung_file(self):
+ search = "This is protected with click-through Samsung license."
+ testfile = fetcher.get(host + per_file_samsung_test_file)
+ fetcher.close()
+ if os.path.exists("%s/cookies.txt" % docroot):
+ os.rename("%s/cookies.txt" % docroot,
+ "%s/cookies.samsung" % docroot)
+ self.assertThat(testfile, Contains(search))
+
+ def test_per_file_accept_license_ste_file(self):
+ search = "This is protected with click-through ST-E license."
+ testfile = fetcher.get(host + per_file_ste_test_file)
+ fetcher.close()
+ if os.path.exists("%s/cookies.txt" % docroot):
+ os.rename("%s/cookies.txt" % docroot, "%s/cookies.ste" % docroot)
+ self.assertThat(testfile, Contains(search))
+
+ def test_per_file_license_accepted_samsung(self):
+ search = "This is protected with click-through Samsung license."
+ os.rename("%s/cookies.samsung" % docroot, "%s/cookies.txt" % docroot)
+ testfile = fetcher.get(host + per_file_samsung_test_file,
+ ignore_license=True)
+ self.assertThat(testfile, Contains(search))
+
+ def test_per_file_license_accepted_ste(self):
+ search = "This is protected with click-through ST-E license."
+ os.rename("%s/cookies.ste" % docroot, "%s/cookies.txt" % docroot)
+ testfile = fetcher.get(host + per_file_ste_test_file,
+ ignore_license=True)
+ self.assertThat(testfile, Contains(search))
+
+ def test_per_file_non_protected_dirs(self):
+ search = "MANIFEST"
+ testfile = fetcher.get(host + per_file_not_protected_test_file)
+ self.assertThat(testfile, Contains(search))
+
+ def test_dir_containing_only_dirs(self):
+ search = "Index of /android/~linaro-android"
+ testfile = fetcher.get(host + dirs_only_dir)
+ self.assertThat(testfile, Contains(search))
+
+ def test_not_found_file(self):
+ search = "Not Found"
+ testfile = fetcher.get(host + not_found_test_file)
+ self.assertThat(testfile, Contains(search))
+
+ def test_build_info_non_protected_file(self):
+ search = "This is always available."
+ testfile = fetcher.get(host + build_info_not_protected_test_file)
+ self.assertThat(testfile, Contains(search))
+
+ def test_build_info_accept_license_samsung_file(self):
+ search = "This is protected with click-through Samsung license."
+ testfile = fetcher.get(host + build_info_samsung_test_file)
+ fetcher.close()
+ if os.path.exists("%s/cookies.txt" % docroot):
+ os.rename("%s/cookies.txt" % docroot,
+ "%s/cookies.samsung" % docroot)
+ self.assertThat(testfile, Contains(search))
+
+ def test_build_info_accept_license_ste_file(self):
+ search = "This is protected with click-through ST-E license."
+ testfile = fetcher.get(host + build_info_ste_test_file)
+ fetcher.close()
+ if os.path.exists("%s/cookies.txt" % docroot):
+ os.rename("%s/cookies.txt" % docroot, "%s/cookies.ste" % docroot)
+ self.assertThat(testfile, Contains(search))
+
+ def test_build_info_openid_protection(self):
+ search = "This is protected with OpenID."
+ testfile = fetcher.get(host + build_info_openid_test_file)
+ fetcher.close()
+ self.assertThat(testfile, Contains(search))
+
diff --git a/license_protected_downloads/views.py b/license_protected_downloads/views.py
index dfae70a..66c0f49 100644
--- a/license_protected_downloads/views.py
+++ b/license_protected_downloads/views.py
@@ -156,6 +156,9 @@ def accept_license(request):
return response
def show_license(request):
+ if 'lic' not in request.GET or 'url' not in request.GET:
+ raise Http404
+
lic = License.objects.filter(digest=request.GET['lic']).get()
return render_to_response('licenses/' + lic.theme + '.html',
diff --git a/templates/404.html b/templates/404.html
new file mode 100644
index 0000000..9f0f16e
--- /dev/null
+++ b/templates/404.html
@@ -0,0 +1,5 @@
+{% extends "header.html" %}
+
+{% block content %}
+Page not found.
+{% endblock %}