Merge lp:~danilo/linaro-license-protection/django-refactor-integration-test into lp:~linaro-automation/linaro-license-protection/trunk

Proposed by Данило Шеган
Status: Rejected
Rejected by: Milo Casagrande
Proposed branch: lp:~danilo/linaro-license-protection/django-refactor-integration-test
Merge into: lp:~linaro-automation/linaro-license-protection/trunk
Prerequisite: lp:~danilo/linaro-license-protection/django-refactor
Diff against target: 468 lines (+0/-443)
4 files modified
.htaccess (+0/-100)
tests/__init__.py (+0/-3)
tests/mime.types (+0/-11)
tests/test_click_through_license.py (+0/-329)
To merge this branch: bzr merge lp:~danilo/linaro-license-protection/django-refactor-integration-test
Reviewer Review Type Date Requested Status
Данило Шеган (community) Needs Fixing
Review via email: mp+114411@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Данило Шеган (danilo) wrote :

We should instead fix the integration test to set up apache + mod_wsgi + mod_xsendfile for testing, and use the test-root to serve files out.

Revision history for this message
Данило Шеган (danilo) :
review: Needs Fixing

Unmerged revisions

91. By Данило Шеган

Merge latest django-refactor.

90. By Данило Шеган

Remove Apache-based integration tests.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed file '.htaccess'
2--- .htaccess 2012-06-20 11:06:51 +0000
3+++ .htaccess 1970-01-01 00:00:00 +0000
4@@ -1,100 +0,0 @@
5-IndexIgnore HEADER* licenses *EULA* BUILD-INFO.txt
6-IndexOptions FancyIndexing HTMLTable
7-
8-RewriteEngine On
9-
10-## LP_DOWNLOAD_DIR is set to the dir from REQUEST_URI
11-## or to the dir containig file form REQUEST_URI
12-RewriteCond %{REQUEST_FILENAME} !.*/licenses/.*
13-RewriteCond %{REQUEST_FILENAME} (.*\/)(.*)$
14-RewriteRule (.*\/)(.*) - [E=LP_DOWNLOAD_DIR:%1]
15-
16-## CO_DOMAIN is set to host name or host address
17-## without port number for use in cookie domain
18-RewriteCond %{SERVER_PORT} !^80$ [OR]
19-RewriteCond %{SERVER_PORT} !^443$
20-RewriteCond %{HTTP_HOST} ^([^:]*)$
21-RewriteRule .* - [E=CO_DOMAIN:%1]
22-
23-RewriteCond %{SERVER_PORT} !^80$ [OR]
24-RewriteCond %{SERVER_PORT} !^443$
25-RewriteCond %{HTTP_HOST} ^([^:]*):(.*)$
26-RewriteRule .* - [E=CO_DOMAIN:%1]
27-
28-## Let internal hosts through always.
29-# android-build.linaro.org.
30-RewriteCond %{REMOTE_ADDR} 50.17.250.69 [OR]
31-# validation.linaro.org.
32-RewriteCond %{REMOTE_ADDR} 82.69.11.23
33-RewriteRule .* - [L]
34-
35-## If license file is requested, and a download has been requested previously,
36-## pass through to the license file.
37-RewriteCond %{REQUEST_URI} /licenses/nolicense.html$ [OR]
38-RewriteCond %{REQUEST_URI} /licenses/license.php$
39-RewriteCond %{HTTP_COOKIE} downloadrequested
40-RewriteCond %{HTTP_COOKIE} !licenseaccepted=true
41-RewriteRule .* - [L]
42-
43-## When license files are requested directly, forward to
44-## the snapshots.l.o site itself.
45-RewriteCond %{REQUEST_URI} /licenses/license.php$
46-RewriteCond %{HTTP_COOKIE} !downloadrequested=(.*)
47-RewriteRule .* / [R,L]
48-
49-## If there is a cookie indicating license has been accepted, pass through.
50-## Unset it to be able to process several protected files in the same dir
51-RewriteCond %{HTTP_COOKIE} licenseaccepted=true
52-RewriteCond %{HTTP_COOKIE} downloadrequested=([^\;]*\/)([^/\;]*)
53-RewriteRule .* - [CO=licenseaccepted:INVALID:.%{ENV:CO_DOMAIN}:-1:%1,L]
54-
55-## When license is accepted, set the cookie.
56-RewriteCond %{REQUEST_URI} licenses/.*-accepted.html$
57-RewriteCond %{HTTP_COOKIE} downloadrequested=([^\;]*\/)([^/\;]*)
58-RewriteRule .* %1%2 [CO=licenseaccepted:true:.%{ENV:CO_DOMAIN}:5:%1,R,L]
59-
60-## When license is being declined, show the notice that you have to accept it.
61-RewriteCond %{REQUEST_URI} licenses/.*-declined.html$
62-RewriteCond %{HTTP_COOKIE} downloadrequested=(.*)
63-RewriteRule .* /licenses/nolicense.html [L]
64-
65-## Exception for images.
66-RewriteCond %{REQUEST_URI} /favicon.ico [OR]
67-RewriteCond %{REQUEST_URI} .*\.png
68-RewriteRule .* - [L]
69-
70-## Exception for restricted area
71-RewriteCond %{REQUEST_URI} .*openid.* [OR]
72-RewriteCond %{REQUEST_URI} .*restricted.* [OR]
73-RewriteCond %{REQUEST_URI} .*private.*
74-RewriteRule .* - [L]
75-
76-## Pass through any non-protected dirs.
77-RewriteCond %{REQUEST_FILENAME} -d
78-RewriteCond %{REQUEST_FILENAME}/OPEN-EULA.txt -f
79-RewriteRule .* - [L]
80-
81-RewriteCond %{REQUEST_FILENAME} -f
82-RewriteCond %{ENV:LP_DOWNLOAD_DIR}/OPEN-EULA.txt -f
83-RewriteRule .* - [L]
84-
85-## Unset cookie indicating redirect from license.php
86-## and redirect to reqested locations with status
87-RewriteCond %{HTTP_COOKIE} redirectlicensephp=403
88-RewriteRule .* - [CO=redirectlicensephp:INVALID:.%{ENV:CO_DOMAIN}:-1,L,F]
89-
90-RewriteCond %{HTTP_COOKIE} redirectlicensephp=200 [OR]
91-RewriteCond %{HTTP_COOKIE} redirectlicensephp=404
92-RewriteRule .* - [CO=redirectlicensephp:INVALID:.%{ENV:CO_DOMAIN}:-1,L]
93-
94-## Redirect to the license file protected builds.
95-RewriteCond %{REQUEST_URI} !^/$
96-RewriteRule .* /licenses/license.php [CO=downloadrequested:%{REQUEST_URI}:.%{ENV:CO_DOMAIN}:5:/,L,R]
97-
98-## Return "Permission denied" if no EULA/OPEN-EULA/BUILD-INFO exists
99-RewriteCond %{REQUEST_URI} !^/$
100-RewriteCond %{REQUEST_URI} !^/licenses/.*$
101-RewriteCond %{ENV:LP_DOWNLOAD_DIR}/EULA.txt !-f
102-RewriteCond %{ENV:LP_DOWNLOAD_DIR}/OPEN-EULA.txt !-f
103-RewriteCond %{ENV:LP_DOWNLOAD_DIR}/BUILD-INFO.txt !-f
104-RewriteRule .* - [R=403,L]
105
106=== modified file 'tests/__init__.py'
107--- tests/__init__.py 2012-07-11 13:07:22 +0000
108+++ tests/__init__.py 2012-07-11 13:07:23 +0000
109@@ -3,9 +3,6 @@
110
111 def test_suite():
112 module_names = [
113- 'tests.test_click_through_license.TestLicense',
114- 'tests.test_pep8.TestPep8',
115- 'tests.test_pyflakes.TestPyflakes',
116 'tests.test_publish_to_snapshots.TestSnapshotsPublisher',
117 ]
118 loader = unittest.TestLoader()
119
120=== removed file 'tests/mime.types'
121--- tests/mime.types 2012-04-02 09:42:58 +0000
122+++ tests/mime.types 1970-01-01 00:00:00 +0000
123@@ -1,11 +0,0 @@
124-text/css css
125-text/directory
126-text/html html htm shtml
127-text/plain asc txt text pot brf
128-text/uri-list
129-application/x-httpd-php phtml pht php
130-application/x-httpd-php-source phps
131-application/x-httpd-php3 php3
132-application/x-httpd-php3-preprocessed php3p
133-application/x-httpd-php4 php4
134-application/x-httpd-php5 php5
135
136=== removed file 'tests/test_click_through_license.py'
137--- tests/test_click_through_license.py 2012-07-11 13:07:22 +0000
138+++ tests/test_click_through_license.py 1970-01-01 00:00:00 +0000
139@@ -1,329 +0,0 @@
140-#!/usr/bin/env python
141-
142-import re
143-import os
144-import shutil
145-import shlex
146-import subprocess
147-import socket
148-
149-from testtools import TestCase
150-from testtools.matchers import Mismatch
151-from license_protected_file_downloader import LicenseProtectedFileFetcher
152-
153-fetcher = LicenseProtectedFileFetcher()
154-cwd = os.getcwd()
155-docroot = cwd
156-srvroot = os.path.abspath(os.path.join(*([cwd] + ['tests'])))
157-local_rewrite = 'RewriteCond %{REMOTE_ADDR} 127.0.0.1 [OR]'
158-
159-host = 'http://127.0.0.1'
160-port = '0' # 0 == Pick a free port.
161-samsung_license_path = '/licenses/license.php'
162-ste_license_path = '/licenses/license.php'
163-linaro_license_path = '/licenses/license.php'
164-samsung_test_file = '/android/~linaro-android/staging-origen/test.txt'
165-ste_test_file = ('/android/~linaro-android/staging-snowball'
166- '/173/target/product/snowball/test.txt')
167-ste_open_test_file = '/android/~linaro-android/staging-snowball/173/test.txt'
168-never_available = '/android/~linaro-android/staging-imx53/test.txt'
169-linaro_test_file = '/android/~linaro-android/staging-panda/test.txt'
170-not_protected_test_file = ('/android/~linaro-android/staging-vexpress-a9'
171- '/test.txt')
172-not_found_test_file = ('/android/~linaro-android/staging-vexpress-a9'
173- '/notfound.txt')
174-per_file_samsung_test_file = '/android/images/origen-blob.txt'
175-per_file_ste_test_file = '/android/images/snowball-blob.txt'
176-per_file_not_protected_test_file = '/android/images/MANIFEST'
177-dirs_only_dir = '/android/~linaro-android/'
178-build_info_samsung_test_file = '/android/build-info/origen-blob.txt'
179-build_info_ste_test_file = '/android/build-info/snowball-blob.txt'
180-build_info_not_protected_test_file = '/android/build-info/panda-open.txt'
181-build_info_openid_test_file = '/android/build-info/openid.txt'
182-
183-
184-class Contains(object):
185- '''Match if a string contains substring'''
186- def __init__(self, substr):
187- self.substr = substr
188-
189- def __str__(self):
190- return 'Contains(%s)' % (self.substr,)
191-
192- def match(self, actual):
193- for line in actual.splitlines():
194- res = re.search(self.substr, line)
195- if res:
196- return None
197- return Mismatch("Initial string doesn't contain substring (%s)" %
198- self.substr)
199-
200-
201-class CommandNotFoundException(Exception):
202- ''' Unable to find command '''
203-
204-
205-class NonZeroReturnValueException(Exception):
206- ''' Command exited with nonzero return value '''
207-
208-
209-class TestLicense(TestCase):
210- '''Tests for accessing files and directories with license protection'''
211-
212- @classmethod
213- def setUpClass(cls):
214- global host
215- global port
216- if port == '0':
217- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
218- s.bind(('127.0.0.1', 0))
219- port = str(s.getsockname()[1])
220- s.close()
221- host = host + ':' + port
222- shutil.copy("%s/apache2.conf.tmpl" % srvroot, "%s/apache2.conf" %
223- srvroot)
224- shutil.copy("%s/.htaccess" % docroot, "%s/dothtaccess" % docroot)
225- subprocess.Popen(['sed', '-i', 's/ServerRoot \"\"/ServerRoot \"%s\"/'
226- % srvroot.replace('/', '\/'), '%s/apache2.conf' % srvroot],
227- stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT).wait()
228- subprocess.Popen(['sed', '-i', 's/DocumentRoot \"\"/DocumentRoot '
229- '\"%s\"/' % docroot.replace('/', '\/'), '%s/apache2.conf'
230- % srvroot], stdout=open('/dev/null', 'w'),
231- stderr=subprocess.STDOUT).wait()
232- subprocess.Popen(['sed', '-i', 's/Directory \"\"/Directory \"%s\"/'
233- % docroot.replace('/', '\/'), '%s/apache2.conf' % srvroot],
234- stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT).wait()
235- subprocess.Popen(['sed', '-i', 's/Listen/Listen %s/' % port,
236- '%s/apache2.conf' % srvroot], stdout=open('/dev/null', 'w'),
237- stderr=subprocess.STDOUT).wait()
238- if subprocess.Popen(['which', 'apache2'],
239- stdout=open('/dev/null', 'w'),
240- stderr=subprocess.STDOUT).wait():
241- raise CommandNotFoundException("apache2 command not found. Please "
242- "install apache2 web server and rerun tests.")
243- args = shlex.split('apache2 -d %s -f apache2.conf -k start' % srvroot)
244- rc = subprocess.Popen(args, stdout=open('/dev/null', 'w'),
245- stderr=subprocess.STDOUT).wait()
246- if rc:
247- raise NonZeroReturnValueException("apache2 server exited with "
248- "error %s" % rc)
249-
250- @classmethod
251- def tearDownClass(cls):
252- if os.path.exists("%s/cookies.txt" % docroot):
253- os.unlink("%s/cookies.txt" % docroot)
254- args = shlex.split('apache2 -d %s -f apache2.conf -k stop' % srvroot)
255- subprocess.Popen(args, stdout=open('/dev/null', 'w'),
256- stderr=subprocess.STDOUT).wait()
257- if os.path.exists("%s/apache2.conf" % srvroot):
258- os.unlink("%s/apache2.conf" % srvroot)
259- if os.path.exists("%s/click_through_license_access.log" % srvroot):
260- os.unlink("%s/click_through_license_access.log" % srvroot)
261- if os.path.exists("%s/click_through_license_error.log" % srvroot):
262- os.unlink("%s/click_through_license_error.log" % srvroot)
263- if os.path.exists("%s/rewrite.log" % srvroot):
264- os.unlink("%s/rewrite.log" % srvroot)
265- os.rename("%s/dothtaccess" % docroot, "%s/.htaccess" % docroot)
266-
267- def setUp(self):
268- super(TestLicense, self).setUp()
269- global fetcher
270- fetcher = LicenseProtectedFileFetcher()
271-
272- def tearDown(self):
273- super(TestLicense, self).tearDown()
274- if isinstance(fetcher, LicenseProtectedFileFetcher):
275- fetcher.close()
276- if os.path.exists("%s/cookies.txt" % docroot):
277- os.unlink("%s/cookies.txt" % docroot)
278-
279- def test_licensefile_directly_samsung(self):
280- search = "Index of /"
281- testfile = fetcher.get(host + samsung_license_path)
282- self.assertThat(testfile, Contains(search))
283-
284- def test_licensefile_directly_ste(self):
285- search = "Index of /"
286- testfile = fetcher.get(host + ste_license_path)
287- self.assertThat(testfile, Contains(search))
288-
289- def test_licensefile_directly_linaro(self):
290- search = "Index of /"
291- testfile = fetcher.get(host + linaro_license_path)
292- self.assertThat(testfile, Contains(search))
293-
294- def test_redirect_to_license_samsung(self):
295- search = "PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY"
296- testfile = fetcher.get_or_return_license(host + samsung_test_file)
297- self.assertThat(testfile[0], Contains(search))
298-
299- def test_redirect_to_license_ste(self):
300- search = "PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY"
301- testfile = fetcher.get_or_return_license(host + ste_test_file)
302- self.assertThat(testfile[0], Contains(search))
303-
304- def test_redirect_to_license_linaro(self):
305- search = "Linaro license."
306- testfile = fetcher.get_or_return_license(host + linaro_test_file)
307- self.assertThat(testfile[0], Contains(search))
308-
309- def test_decline_license_samsung(self):
310- search = "License has not been accepted"
311- testfile = fetcher.get(host + samsung_test_file, accept_license=False)
312- self.assertThat(testfile, Contains(search))
313-
314- def test_decline_license_ste(self):
315- search = "License has not been accepted"
316- testfile = fetcher.get(host + ste_test_file, accept_license=False)
317- self.assertThat(testfile, Contains(search))
318-
319- def test_decline_license_linaro(self):
320- search = "License has not been accepted"
321- testfile = fetcher.get(host + linaro_test_file, accept_license=False)
322- self.assertThat(testfile, Contains(search))
323-
324- def test_non_protected_dirs(self):
325- search = "This is always available."
326- testfile = fetcher.get(host + not_protected_test_file)
327- self.assertThat(testfile, Contains(search))
328-
329- def test_never_available_dirs(self):
330- search = "Forbidden"
331- testfile = fetcher.get(host + never_available)
332- self.assertThat(testfile, Contains(search))
333-
334- def test_accept_license_samsung_file(self):
335- search = "This is protected with click-through Samsung license."
336- testfile = fetcher.get(host + samsung_test_file)
337- fetcher.close()
338- if os.path.exists("%s/cookies.txt" % docroot):
339- os.rename("%s/cookies.txt" % docroot,
340- "%s/cookies.samsung" % docroot)
341- self.assertThat(testfile, Contains(search))
342-
343- def test_accept_license_samsung_dir(self):
344- search = "Index of /android/~linaro-android/staging-origen"
345- testfile = fetcher.get(host + os.path.dirname(samsung_test_file))
346- self.assertThat(testfile, Contains(search))
347-
348- def test_accept_license_ste_file(self):
349- search = "This is protected with click-through ST-E license."
350- testfile = fetcher.get(host + ste_test_file)
351- fetcher.close()
352- if os.path.exists("%s/cookies.txt" % docroot):
353- os.rename("%s/cookies.txt" % docroot, "%s/cookies.ste" % docroot)
354- self.assertThat(testfile, Contains(search))
355-
356- def test_accept_license_ste_dir(self):
357- search = "Index of /android/~linaro-android/staging-snowball"
358- testfile = fetcher.get(host + os.path.dirname(ste_test_file))
359- self.assertThat(testfile, Contains(search))
360-
361- def test_license_accepted_samsung(self):
362- search = "This is protected with click-through Samsung license."
363- os.rename("%s/cookies.samsung" % docroot, "%s/cookies.txt" % docroot)
364- testfile = fetcher.get(host + samsung_test_file)
365- self.assertThat(testfile, Contains(search))
366-
367- def test_license_accepted_ste(self):
368- search = "This is protected with click-through ST-E license."
369- os.rename("%s/cookies.ste" % docroot, "%s/cookies.txt" % docroot)
370- testfile = fetcher.get(host + ste_test_file)
371- self.assertThat(testfile, Contains(search))
372-
373- def test_internal_host_samsung(self):
374- search = "This is protected with click-through Samsung license."
375- subprocess.Popen(['sed', '-i', '/## Let internal hosts through '
376- 'always./ a %s' % local_rewrite, '%s/.htaccess' % docroot],
377- stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT).wait()
378- testfile = fetcher.get(host + samsung_test_file, ignore_license=True)
379- shutil.copy("%s/dothtaccess" % docroot, "%s/.htaccess" % docroot)
380- self.assertThat(testfile, Contains(search))
381-
382- def test_internal_host_ste(self):
383- search = "This is protected with click-through ST-E license."
384- subprocess.Popen(['sed', '-i', '/## Let internal hosts through '
385- 'always./ a %s' % local_rewrite, '%s/.htaccess' % docroot],
386- stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT).wait()
387- testfile = fetcher.get(host + ste_test_file, ignore_license=True)
388- shutil.copy("%s/dothtaccess" % docroot, "%s/.htaccess" % docroot)
389- self.assertThat(testfile, Contains(search))
390-
391- def test_ste_open_file(self):
392- search = "This is always available."
393- testfile = fetcher.get(host + ste_open_test_file)
394- self.assertThat(testfile, Contains(search))
395-
396- def test_per_file_accept_license_samsung_file(self):
397- search = "This is protected with click-through Samsung license."
398- testfile = fetcher.get(host + per_file_samsung_test_file)
399- fetcher.close()
400- if os.path.exists("%s/cookies.txt" % docroot):
401- os.rename("%s/cookies.txt" % docroot,
402- "%s/cookies.samsung" % docroot)
403- self.assertThat(testfile, Contains(search))
404-
405- def test_per_file_accept_license_ste_file(self):
406- search = "This is protected with click-through ST-E license."
407- testfile = fetcher.get(host + per_file_ste_test_file)
408- fetcher.close()
409- if os.path.exists("%s/cookies.txt" % docroot):
410- os.rename("%s/cookies.txt" % docroot, "%s/cookies.ste" % docroot)
411- self.assertThat(testfile, Contains(search))
412-
413- def test_per_file_license_accepted_samsung(self):
414- search = "This is protected with click-through Samsung license."
415- os.rename("%s/cookies.samsung" % docroot, "%s/cookies.txt" % docroot)
416- testfile = fetcher.get(host + per_file_samsung_test_file,
417- ignore_license=True)
418- self.assertThat(testfile, Contains(search))
419-
420- def test_per_file_license_accepted_ste(self):
421- search = "This is protected with click-through ST-E license."
422- os.rename("%s/cookies.ste" % docroot, "%s/cookies.txt" % docroot)
423- testfile = fetcher.get(host + per_file_ste_test_file,
424- ignore_license=True)
425- self.assertThat(testfile, Contains(search))
426-
427- def test_per_file_non_protected_dirs(self):
428- search = "MANIFEST"
429- testfile = fetcher.get(host + per_file_not_protected_test_file)
430- self.assertThat(testfile, Contains(search))
431-
432- def test_dir_containing_only_dirs(self):
433- search = "Index of /android/~linaro-android"
434- testfile = fetcher.get(host + dirs_only_dir)
435- self.assertThat(testfile, Contains(search))
436-
437- def test_not_found_file(self):
438- search = "Not Found"
439- testfile = fetcher.get(host + not_found_test_file)
440- self.assertThat(testfile, Contains(search))
441-
442- def test_build_info_non_protected_file(self):
443- search = "This is always available."
444- testfile = fetcher.get(host + build_info_not_protected_test_file)
445- self.assertThat(testfile, Contains(search))
446-
447- def test_build_info_accept_license_samsung_file(self):
448- search = "This is protected with click-through Samsung license."
449- testfile = fetcher.get(host + build_info_samsung_test_file)
450- fetcher.close()
451- if os.path.exists("%s/cookies.txt" % docroot):
452- os.rename("%s/cookies.txt" % docroot,
453- "%s/cookies.samsung" % docroot)
454- self.assertThat(testfile, Contains(search))
455-
456- def test_build_info_accept_license_ste_file(self):
457- search = "This is protected with click-through ST-E license."
458- testfile = fetcher.get(host + build_info_ste_test_file)
459- fetcher.close()
460- if os.path.exists("%s/cookies.txt" % docroot):
461- os.rename("%s/cookies.txt" % docroot, "%s/cookies.ste" % docroot)
462- self.assertThat(testfile, Contains(search))
463-
464- def test_build_info_openid_protection(self):
465- search = "This is protected with OpenID."
466- testfile = fetcher.get(host + build_info_openid_test_file)
467- fetcher.close()
468- self.assertThat(testfile, Contains(search))

Subscribers

People subscribed via source and target branches