Merge lp:~gesha/linaro-license-protection/openid-workaround into lp:~linaro-automation/linaro-license-protection/trunk

Proposed by Georgy Redkozubov
Status: Merged
Approved by: James Tunnicliffe
Approved revision: 124
Merged at revision: 123
Proposed branch: lp:~gesha/linaro-license-protection/openid-workaround
Merge into: lp:~linaro-automation/linaro-license-protection/trunk
Diff against target: 105 lines (+37/-2)
5 files modified
license_protected_downloads/config.py (+11/-0)
license_protected_downloads/tests/test_views.py (+11/-0)
license_protected_downloads/tests/testserver_root/precise/restricted/whitelisted.txt (+1/-0)
license_protected_downloads/views.py (+13/-2)
sampleroot/precise/restricted/whitelisted.txt (+1/-0)
To merge this branch: bzr merge lp:~gesha/linaro-license-protection/openid-workaround
Reviewer Review Type Date Requested Status
James Tunnicliffe (community) Approve
Review via email: mp+121667@code.launchpad.net

Description of the change

This branch adds whitelisting support to workaround issue with django access to apache-openid protected files.
Should be removed after we get full support of build-info and drop apache-openid protection.

To post a comment you must log in.
124. By Georgy Redkozubov

Added missing test dirs and files.

Revision history for this message
James Tunnicliffe (dooferlad) wrote :

Looks great.

Revision history for this message
James Tunnicliffe (dooferlad) wrote :

Oops. Forgot the approve button!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'license_protected_downloads/config.py'
--- license_protected_downloads/config.py 2012-07-24 11:51:25 +0000
+++ license_protected_downloads/config.py 2012-08-28 17:21:19 +0000
@@ -5,3 +5,14 @@
5 '50.17.250.69', # android-build.linaro.org5 '50.17.250.69', # android-build.linaro.org
6 '82.69.11.23', # validation.linaro.org6 '82.69.11.23', # validation.linaro.org
7)7)
8
9WHITELIST = (
10 '/hwpacks',
11 '/precise/restricted',
12 '/hwpacks/freescale',
13 '/hwpacks/samsung',
14 '/hwpacks/ste',
15 '/hwpacks/ti',
16 '/hwpacks/arm',
17 '/android/~linaro-android-restricted',
18)
819
=== modified file 'license_protected_downloads/tests/test_views.py'
--- license_protected_downloads/tests/test_views.py 2012-08-27 10:02:15 +0000
+++ license_protected_downloads/tests/test_views.py 2012-08-28 17:21:19 +0000
@@ -13,6 +13,7 @@
13from license_protected_downloads.views import _sizeof_fmt13from license_protected_downloads.views import _sizeof_fmt
14from license_protected_downloads.config import INTERNAL_HOSTS14from license_protected_downloads.config import INTERNAL_HOSTS
1515
16
16THIS_DIRECTORY = os.path.dirname(os.path.abspath(__file__))17THIS_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
17TESTSERVER_ROOT = os.path.join(THIS_DIRECTORY, "testserver_root")18TESTSERVER_ROOT = os.path.join(THIS_DIRECTORY, "testserver_root")
1819
@@ -487,6 +488,16 @@
487 self.assertEqual(_sizeof_fmt(1234567899), '1.1G')488 self.assertEqual(_sizeof_fmt(1234567899), '1.1G')
488 self.assertEqual(_sizeof_fmt(1234567899999), '1.1T')489 self.assertEqual(_sizeof_fmt(1234567899999), '1.1T')
489490
491 def test_whitelisted_dirs(self):
492 target_file = "precise/restricted/whitelisted.txt"
493 url = urlparse.urljoin("http://testserver/", target_file)
494 response = self.client.get(url, follow=True)
495
496 # If we have access to the file, we will get an X-Sendfile response
497 self.assertEqual(response.status_code, 200)
498 file_path = os.path.join(TESTSERVER_ROOT, target_file)
499 self.assertEqual(response['X-Sendfile'], file_path)
500
490501
491if __name__ == '__main__':502if __name__ == '__main__':
492 unittest.main()503 unittest.main()
493504
=== added directory 'license_protected_downloads/tests/testserver_root/precise'
=== added directory 'license_protected_downloads/tests/testserver_root/precise/restricted'
=== added file 'license_protected_downloads/tests/testserver_root/precise/restricted/whitelisted.txt'
--- license_protected_downloads/tests/testserver_root/precise/restricted/whitelisted.txt 1970-01-01 00:00:00 +0000
+++ license_protected_downloads/tests/testserver_root/precise/restricted/whitelisted.txt 2012-08-28 17:21:19 +0000
@@ -0,0 +1,1 @@
1This file is under whitelisted dir
0\ No newline at end of file2\ No newline at end of file
13
=== modified file 'license_protected_downloads/views.py'
--- license_protected_downloads/views.py 2012-08-27 10:56:15 +0000
+++ license_protected_downloads/views.py 2012-08-28 17:21:19 +0000
@@ -3,7 +3,6 @@
3import mimetypes3import mimetypes
4import os4import os
5import re5import re
6import time
7from mimetypes import guess_type6from mimetypes import guess_type
8from datetime import datetime7from datetime import datetime
98
@@ -296,6 +295,17 @@
296 return found295 return found
297296
298297
298def is_whitelisted(url):
299 """ Check if requested file is under whitelisted path.
300 """
301 found = False
302 for path in config.WHITELIST:
303 if re.search(r'^%s' % path, url):
304 found = True
305
306 return found
307
308
299def file_server(request, path):309def file_server(request, path):
300 """Serve up a file / directory listing or license page as required"""310 """Serve up a file / directory listing or license page as required"""
301 url = path311 url = path
@@ -351,7 +361,8 @@
351 raise Http404361 raise Http404
352362
353 response = None363 response = None
354 if get_client_ip(request) in config.INTERNAL_HOSTS:364 if get_client_ip(request) in config.INTERNAL_HOSTS or\
365 is_whitelisted(os.path.join('/', url)):
355 digests = 'OPEN'366 digests = 'OPEN'
356 else:367 else:
357 digests = is_protected(path)368 digests = is_protected(path)
358369
=== added directory 'sampleroot/precise'
=== added directory 'sampleroot/precise/restricted'
=== added file 'sampleroot/precise/restricted/whitelisted.txt'
--- sampleroot/precise/restricted/whitelisted.txt 1970-01-01 00:00:00 +0000
+++ sampleroot/precise/restricted/whitelisted.txt 2012-08-28 17:21:19 +0000
@@ -0,0 +1,1 @@
1This file is under whitelisted dir
0\ No newline at end of file2\ No newline at end of file

Subscribers

People subscribed via source and target branches