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
1=== modified file 'license_protected_downloads/config.py'
2--- license_protected_downloads/config.py 2012-07-24 11:51:25 +0000
3+++ license_protected_downloads/config.py 2012-08-28 17:21:19 +0000
4@@ -5,3 +5,14 @@
5 '50.17.250.69', # android-build.linaro.org
6 '82.69.11.23', # validation.linaro.org
7 )
8+
9+WHITELIST = (
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+)
19
20=== modified file 'license_protected_downloads/tests/test_views.py'
21--- license_protected_downloads/tests/test_views.py 2012-08-27 10:02:15 +0000
22+++ license_protected_downloads/tests/test_views.py 2012-08-28 17:21:19 +0000
23@@ -13,6 +13,7 @@
24 from license_protected_downloads.views import _sizeof_fmt
25 from license_protected_downloads.config import INTERNAL_HOSTS
26
27+
28 THIS_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
29 TESTSERVER_ROOT = os.path.join(THIS_DIRECTORY, "testserver_root")
30
31@@ -487,6 +488,16 @@
32 self.assertEqual(_sizeof_fmt(1234567899), '1.1G')
33 self.assertEqual(_sizeof_fmt(1234567899999), '1.1T')
34
35+ def test_whitelisted_dirs(self):
36+ target_file = "precise/restricted/whitelisted.txt"
37+ url = urlparse.urljoin("http://testserver/", target_file)
38+ response = self.client.get(url, follow=True)
39+
40+ # If we have access to the file, we will get an X-Sendfile response
41+ self.assertEqual(response.status_code, 200)
42+ file_path = os.path.join(TESTSERVER_ROOT, target_file)
43+ self.assertEqual(response['X-Sendfile'], file_path)
44+
45
46 if __name__ == '__main__':
47 unittest.main()
48
49=== added directory 'license_protected_downloads/tests/testserver_root/precise'
50=== added directory 'license_protected_downloads/tests/testserver_root/precise/restricted'
51=== added file 'license_protected_downloads/tests/testserver_root/precise/restricted/whitelisted.txt'
52--- license_protected_downloads/tests/testserver_root/precise/restricted/whitelisted.txt 1970-01-01 00:00:00 +0000
53+++ license_protected_downloads/tests/testserver_root/precise/restricted/whitelisted.txt 2012-08-28 17:21:19 +0000
54@@ -0,0 +1,1 @@
55+This file is under whitelisted dir
56\ No newline at end of file
57
58=== modified file 'license_protected_downloads/views.py'
59--- license_protected_downloads/views.py 2012-08-27 10:56:15 +0000
60+++ license_protected_downloads/views.py 2012-08-28 17:21:19 +0000
61@@ -3,7 +3,6 @@
62 import mimetypes
63 import os
64 import re
65-import time
66 from mimetypes import guess_type
67 from datetime import datetime
68
69@@ -296,6 +295,17 @@
70 return found
71
72
73+def is_whitelisted(url):
74+ """ Check if requested file is under whitelisted path.
75+ """
76+ found = False
77+ for path in config.WHITELIST:
78+ if re.search(r'^%s' % path, url):
79+ found = True
80+
81+ return found
82+
83+
84 def file_server(request, path):
85 """Serve up a file / directory listing or license page as required"""
86 url = path
87@@ -351,7 +361,8 @@
88 raise Http404
89
90 response = None
91- if get_client_ip(request) in config.INTERNAL_HOSTS:
92+ if get_client_ip(request) in config.INTERNAL_HOSTS or\
93+ is_whitelisted(os.path.join('/', url)):
94 digests = 'OPEN'
95 else:
96 digests = is_protected(path)
97
98=== added directory 'sampleroot/precise'
99=== added directory 'sampleroot/precise/restricted'
100=== added file 'sampleroot/precise/restricted/whitelisted.txt'
101--- sampleroot/precise/restricted/whitelisted.txt 1970-01-01 00:00:00 +0000
102+++ sampleroot/precise/restricted/whitelisted.txt 2012-08-28 17:21:19 +0000
103@@ -0,0 +1,1 @@
104+This file is under whitelisted dir
105\ No newline at end of file

Subscribers

People subscribed via source and target branches