Merge lp:~gesha/linaro-license-protection/per-file-EULA into lp:~linaro-automation/linaro-license-protection/trunk
- per-file-EULA
- Merge into trunk
Proposed by
Georgy Redkozubov
Status: | Merged |
---|---|
Merged at revision: | 60 |
Proposed branch: | lp:~gesha/linaro-license-protection/per-file-EULA |
Merge into: | lp:~linaro-automation/linaro-license-protection/trunk |
Diff against target: |
451 lines (+192/-75) 14 files modified
.htaccess (+10/-34) android/images/MANIFEST (+1/-0) android/images/origen-blob.txt (+1/-0) android/images/snowball-blob.txt (+1/-0) android/~linaro-android/staging-origen/test.txt (+1/-1) android/~linaro-android/staging-panda/test.txt (+1/-1) android/~linaro-android/staging-snowball/173/target/product/snowball/test.txt (+1/-1) android/~linaro-android/staging-snowball/173/test.txt (+1/-0) licenses/license.php (+117/-16) licenses/linaro.html (+1/-6) licenses/linaro.txt (+1/-0) licenses/samsung.html (+1/-5) licenses/ste.html (+0/-5) testing/test_click_through_license.py (+55/-6) |
To merge this branch: | bzr merge lp:~gesha/linaro-license-protection/per-file-EULA |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Данило Шеган (community) | Approve | ||
Review via email: mp+103238@code.launchpad.net |
Commit message
Description of the change
This branch adds per file EULA support for downloads click-through license protection.
To post a comment you must log in.
- 61. By Georgy Redkozubov
-
Fixed indentation
- 62. By Georgy Redkozubov
-
Added test for directory containing only directories
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file '.htaccess' | |||
2 | --- .htaccess 2012-03-27 13:50:19 +0000 | |||
3 | +++ .htaccess 2012-04-24 10:59:21 +0000 | |||
4 | @@ -31,6 +31,7 @@ | |||
5 | 31 | RewriteCond %{REQUEST_URI} /licenses/ste.html$ [OR] | 31 | RewriteCond %{REQUEST_URI} /licenses/ste.html$ [OR] |
6 | 32 | RewriteCond %{REQUEST_URI} /licenses/samsung.html$ [OR] | 32 | RewriteCond %{REQUEST_URI} /licenses/samsung.html$ [OR] |
7 | 33 | RewriteCond %{REQUEST_URI} /licenses/linaro.html$ [OR] | 33 | RewriteCond %{REQUEST_URI} /licenses/linaro.html$ [OR] |
8 | 34 | RewriteCond %{REQUEST_URI} /licenses/nolicense.html$ [OR] | ||
9 | 34 | RewriteCond %{REQUEST_URI} /licenses/license.php$ | 35 | RewriteCond %{REQUEST_URI} /licenses/license.php$ |
10 | 35 | RewriteCond %{HTTP_COOKIE} downloadrequested | 36 | RewriteCond %{HTTP_COOKIE} downloadrequested |
11 | 36 | RewriteCond %{HTTP_COOKIE} !licenseaccepted=true | 37 | RewriteCond %{HTTP_COOKIE} !licenseaccepted=true |
12 | @@ -45,13 +46,11 @@ | |||
13 | 45 | RewriteCond %{HTTP_COOKIE} !downloadrequested=(.*) | 46 | RewriteCond %{HTTP_COOKIE} !downloadrequested=(.*) |
14 | 46 | RewriteRule .* / [R,L] | 47 | RewriteRule .* / [R,L] |
15 | 47 | 48 | ||
16 | 48 | ## Exception for <iframe> | ||
17 | 49 | RewriteCond %{REQUEST_URI} ^.*/EULA.txt$ | ||
18 | 50 | RewriteRule .* - [L] | ||
19 | 51 | |||
20 | 52 | ## If there is a cookie indicating license has been accepted, pass through. | 49 | ## If there is a cookie indicating license has been accepted, pass through. |
21 | 50 | ## Unset it to be able to process several protected files in the same dir | ||
22 | 53 | RewriteCond %{HTTP_COOKIE} licenseaccepted=true | 51 | RewriteCond %{HTTP_COOKIE} licenseaccepted=true |
24 | 54 | RewriteRule .* - [L] | 52 | RewriteCond %{HTTP_COOKIE} downloadrequested=([^\;]*\/)([^/\;]*) |
25 | 53 | RewriteRule .* - [CO=licenseaccepted:INVALID:;:-1:%1,L] | ||
26 | 55 | 54 | ||
27 | 56 | ## When license is accepted, set the cookie. | 55 | ## When license is accepted, set the cookie. |
28 | 57 | RewriteCond %{REQUEST_URI} licenses/.*-accepted.html$ | 56 | RewriteCond %{REQUEST_URI} licenses/.*-accepted.html$ |
29 | @@ -72,36 +71,13 @@ | |||
30 | 72 | RewriteCond %{ENV:LP_DOWNLOAD_DIR}/OPEN-EULA.txt -f | 71 | RewriteCond %{ENV:LP_DOWNLOAD_DIR}/OPEN-EULA.txt -f |
31 | 73 | RewriteRule .* - [L] | 72 | RewriteRule .* - [L] |
32 | 74 | 73 | ||
33 | 74 | ## Unset cookie indicating redirect from license.php | ||
34 | 75 | RewriteCond %{HTTP_COOKIE} redirectlicensephp=yes | ||
35 | 76 | RewriteRule .* - [CO=redirectlicensephp:INVALID:;:-1,L] | ||
36 | 77 | |||
37 | 75 | ## Redirect to the Samsung license file protected builds. | 78 | ## Redirect to the Samsung license file protected builds. |
67 | 76 | RewriteCond %{REQUEST_FILENAME} -d | 79 | RewriteCond %{REQUEST_URI} !^/$ |
68 | 77 | RewriteCond %{REQUEST_FILENAME} .*origen.* | 80 | RewriteRule .* /licenses/license.php [CO=downloadrequested:%{REQUEST_URI}:.%{ENV:CO_DOMAIN},L,R] |
40 | 78 | RewriteCond %{REQUEST_FILENAME}/EULA.txt -f | ||
41 | 79 | RewriteRule .* /licenses/license.php?samsung [CO=downloadrequested:%{REQUEST_URI}:.%{ENV:CO_DOMAIN},R,L] | ||
42 | 80 | |||
43 | 81 | RewriteCond %{REQUEST_FILENAME} -f | ||
44 | 82 | RewriteCond %{REQUEST_FILENAME} .*origen.* | ||
45 | 83 | RewriteCond %{ENV:LP_DOWNLOAD_DIR}/EULA.txt -f | ||
46 | 84 | RewriteRule .* /licenses/license.php?samsung [CO=downloadrequested:%{REQUEST_URI}:.%{ENV:CO_DOMAIN},R,L] | ||
47 | 85 | |||
48 | 86 | ## Redirect to the ST-E license file protected builds. | ||
49 | 87 | RewriteCond %{REQUEST_FILENAME} -d | ||
50 | 88 | RewriteCond %{REQUEST_FILENAME} .*snowball.* | ||
51 | 89 | RewriteCond %{REQUEST_FILENAME}/EULA.txt -f | ||
52 | 90 | RewriteRule .* /licenses/license.php?ste [CO=downloadrequested:%{REQUEST_URI}:.%{ENV:CO_DOMAIN},R,L] | ||
53 | 91 | |||
54 | 92 | RewriteCond %{REQUEST_FILENAME} -f | ||
55 | 93 | RewriteCond %{REQUEST_FILENAME} .*snowball.* | ||
56 | 94 | RewriteCond %{ENV:LP_DOWNLOAD_DIR}/EULA.txt -f | ||
57 | 95 | RewriteRule .* /licenses/license.php?ste [CO=downloadrequested:%{REQUEST_URI}:.%{ENV:CO_DOMAIN},R,L] | ||
58 | 96 | |||
59 | 97 | ## Redirect to the Linaro license file protected builds. | ||
60 | 98 | RewriteCond %{REQUEST_FILENAME} -d | ||
61 | 99 | RewriteCond %{REQUEST_FILENAME}/EULA.txt -f | ||
62 | 100 | RewriteRule .* /licenses/license.php?linaro [CO=downloadrequested:%{REQUEST_URI}:.%{ENV:CO_DOMAIN},R,L] | ||
63 | 101 | |||
64 | 102 | RewriteCond %{REQUEST_FILENAME} -f | ||
65 | 103 | RewriteCond %{ENV:LP_DOWNLOAD_DIR}/EULA.txt -f | ||
66 | 104 | RewriteRule .* /licenses/license.php?linaro [CO=downloadrequested:%{REQUEST_URI}:.%{ENV:CO_DOMAIN},R,L] | ||
69 | 105 | 81 | ||
70 | 106 | ## Return "Permission denied" if no EULA/OPEN-EULA exists | 82 | ## Return "Permission denied" if no EULA/OPEN-EULA exists |
71 | 107 | RewriteCond %{REQUEST_URI} !^/$ | 83 | RewriteCond %{REQUEST_URI} !^/$ |
72 | 108 | 84 | ||
73 | === added directory 'android/images' | |||
74 | === added file 'android/images/MANIFEST' | |||
75 | --- android/images/MANIFEST 1970-01-01 00:00:00 +0000 | |||
76 | +++ android/images/MANIFEST 2012-04-24 10:59:21 +0000 | |||
77 | @@ -0,0 +1,1 @@ | |||
78 | 1 | MANIFEST | ||
79 | 0 | \ No newline at end of file | 2 | \ No newline at end of file |
80 | 1 | 3 | ||
81 | === added file 'android/images/origen-blob.EULA.txt.samsung' | |||
82 | === added file 'android/images/origen-blob.txt' | |||
83 | --- android/images/origen-blob.txt 1970-01-01 00:00:00 +0000 | |||
84 | +++ android/images/origen-blob.txt 2012-04-24 10:59:21 +0000 | |||
85 | @@ -0,0 +1,1 @@ | |||
86 | 1 | This is protected with click-through Samsung license. | ||
87 | 0 | \ No newline at end of file | 2 | \ No newline at end of file |
88 | 1 | 3 | ||
89 | === added file 'android/images/snowball-blob.EULA.txt.ste' | |||
90 | === added file 'android/images/snowball-blob.txt' | |||
91 | --- android/images/snowball-blob.txt 1970-01-01 00:00:00 +0000 | |||
92 | +++ android/images/snowball-blob.txt 2012-04-24 10:59:21 +0000 | |||
93 | @@ -0,0 +1,1 @@ | |||
94 | 1 | This is protected with click-through ST-E license. | ||
95 | 0 | \ No newline at end of file | 2 | \ No newline at end of file |
96 | 1 | 3 | ||
97 | === modified file 'android/~linaro-android/staging-origen/test.txt' | |||
98 | --- android/~linaro-android/staging-origen/test.txt 2011-12-09 16:08:16 +0000 | |||
99 | +++ android/~linaro-android/staging-origen/test.txt 2012-04-24 10:59:21 +0000 | |||
100 | @@ -1,1 +1,1 @@ | |||
102 | 1 | This is a protected with click-through Samsung license. | 1 | This is protected with click-through Samsung license. |
103 | 2 | 2 | ||
104 | === modified file 'android/~linaro-android/staging-panda/test.txt' | |||
105 | --- android/~linaro-android/staging-panda/test.txt 2012-03-27 09:53:11 +0000 | |||
106 | +++ android/~linaro-android/staging-panda/test.txt 2012-04-24 10:59:21 +0000 | |||
107 | @@ -1,1 +1,1 @@ | |||
109 | 1 | This is a protected with click-through Linaro license. | 1 | This is protected with click-through Linaro license. |
110 | 2 | 2 | ||
111 | === added file 'android/~linaro-android/staging-snowball/173/OPEN-EULA.txt' | |||
112 | === modified file 'android/~linaro-android/staging-snowball/173/target/product/snowball/test.txt' | |||
113 | --- android/~linaro-android/staging-snowball/173/target/product/snowball/test.txt 2012-03-27 13:57:57 +0000 | |||
114 | +++ android/~linaro-android/staging-snowball/173/target/product/snowball/test.txt 2012-04-24 10:59:21 +0000 | |||
115 | @@ -1,1 +1,1 @@ | |||
117 | 1 | This is a protected with click-through ST-E license. | 1 | This is protected with click-through ST-E license. |
118 | 2 | 2 | ||
119 | === added file 'android/~linaro-android/staging-snowball/173/test.txt' | |||
120 | --- android/~linaro-android/staging-snowball/173/test.txt 1970-01-01 00:00:00 +0000 | |||
121 | +++ android/~linaro-android/staging-snowball/173/test.txt 2012-04-24 10:59:21 +0000 | |||
122 | @@ -0,0 +1,1 @@ | |||
123 | 1 | This is always available. | ||
124 | 0 | 2 | ||
125 | === modified file 'licenses/license.php' | |||
126 | --- licenses/license.php 2012-04-20 16:00:26 +0000 | |||
127 | +++ licenses/license.php 2012-04-24 10:59:21 +0000 | |||
128 | @@ -1,18 +1,119 @@ | |||
129 | 1 | <?php | 1 | <?php |
146 | 2 | $down = $_COOKIE["downloadrequested"]; | 2 | // Get list of files into array to process them later. |
147 | 3 | $lic = $_SERVER["QUERY_STRING"]; | 3 | // Used to find special licenses and dirs with only subdirs. |
148 | 4 | $host = $_SERVER["HTTP_HOST"]; | 4 | function getFilesList($dirname) |
149 | 5 | $doc = $_SERVER["DOCUMENT_ROOT"]; | 5 | { |
150 | 6 | $fn = $doc.$down; | 6 | $files = array(); |
151 | 7 | if (file_exists($fn) and is_file($fn)) { | 7 | if ($handle = opendir($dirname)) { |
152 | 8 | $repl = dirname($down); | 8 | while ($handle && false !== ($entry = readdir($handle))) { |
153 | 9 | } else { | 9 | if ($entry != "." && $entry != ".." && !is_dir($dirname.$entry) && !is_link($dirname.$entry)) { |
154 | 10 | $repl = $down; | 10 | $files[] = $entry; |
155 | 11 | } | 11 | } |
156 | 12 | 12 | } | |
157 | 13 | $template_content = file_get_contents($doc."/licenses/".$lic.".html"); | 13 | } |
158 | 14 | $eula_content = file_get_contents($doc."/licenses/".$lic.".txt"); | 14 | closedir($handle); |
159 | 15 | 15 | return $files; | |
160 | 16 | $out = str_replace("EULA.txt", $eula_content, $template_content); | 16 | } |
161 | 17 | echo $out; | 17 | |
162 | 18 | // Get array of file name and extension from full filename. | ||
163 | 19 | function splitFilename($filename) | ||
164 | 20 | { | ||
165 | 21 | $pos = strpos($filename, '.'); | ||
166 | 22 | if ($pos === false) { // dot is not found in the filename | ||
167 | 23 | return array($filename, ''); // no extension | ||
168 | 24 | } else { | ||
169 | 25 | $basename = substr($filename, 0, $pos); | ||
170 | 26 | $extension = substr($filename, $pos+1); | ||
171 | 27 | return array($basename, $extension); | ||
172 | 28 | } | ||
173 | 29 | } | ||
174 | 30 | |||
175 | 31 | // Find special EULA based on filename template. | ||
176 | 32 | function findSpecialEULA($fl, $pattern) | ||
177 | 33 | { | ||
178 | 34 | if (!empty($fl)) { | ||
179 | 35 | foreach ($fl as $f) { | ||
180 | 36 | if (preg_match($pattern, $f, $matches)) { | ||
181 | 37 | return $f; | ||
182 | 38 | } | ||
183 | 39 | } | ||
184 | 40 | } | ||
185 | 41 | return false; | ||
186 | 42 | } | ||
187 | 43 | |||
188 | 44 | // Get license theme name from EULA filename. | ||
189 | 45 | function getTheme($eula, $down) | ||
190 | 46 | { | ||
191 | 47 | if ($eula != 'EULA.txt') { // Special EULA file was found | ||
192 | 48 | $theme = array_pop(explode(".", $eula)); | ||
193 | 49 | } else { // No special EULA file was found | ||
194 | 50 | $eula = "EULA.txt"; | ||
195 | 51 | if (preg_match("/.*snowball.*/", $down)) { | ||
196 | 52 | $theme = "ste"; | ||
197 | 53 | } elseif (preg_match("/.*origen.*/", $down)) { | ||
198 | 54 | $theme = "samsung"; | ||
199 | 55 | } else { | ||
200 | 56 | $theme = "linaro"; | ||
201 | 57 | } | ||
202 | 58 | } | ||
203 | 59 | return $theme; | ||
204 | 60 | } | ||
205 | 61 | |||
206 | 62 | $down = $_COOKIE["downloadrequested"]; | ||
207 | 63 | $host = $_SERVER["HTTP_HOST"]; | ||
208 | 64 | $doc = $_SERVER["DOCUMENT_ROOT"]; | ||
209 | 65 | $fn = $doc.$down; // Filename on server | ||
210 | 66 | $flist = array(); | ||
211 | 67 | $eula = ''; | ||
212 | 68 | |||
213 | 69 | if (file_exists($fn) and is_file($fn)) { // Requested download is file | ||
214 | 70 | $search_dir = dirname($fn); | ||
215 | 71 | $repl = dirname($down); | ||
216 | 72 | $name_only = splitFilename(basename($down)); | ||
217 | 73 | } elseif (is_dir($fn)) { // Requested download is directory | ||
218 | 74 | $search_dir = $fn; | ||
219 | 75 | $repl = $down; | ||
220 | 76 | $name_only = array(); | ||
221 | 77 | } else { // Requested download not found on server | ||
222 | 78 | header("HTTP/1.0 404 Not Found"); | ||
223 | 79 | header("Status: 404"); | ||
224 | 80 | echo "<h1>404 Not Found</h1>"; | ||
225 | 81 | echo "The requested URL was not found on this server."; | ||
226 | 82 | exit; | ||
227 | 83 | } | ||
228 | 84 | |||
229 | 85 | $flist = getFilesList($search_dir); | ||
230 | 86 | |||
231 | 87 | if (!empty($name_only)) { | ||
232 | 88 | $pattern = "/^".$name_only[0]."\.EULA\.txt.*/"; | ||
233 | 89 | $eula = findSpecialEULA($flist, $pattern); | ||
234 | 90 | } | ||
235 | 91 | |||
236 | 92 | if (is_file($doc."/".$repl."/".$eula)) { // Special EULA found | ||
237 | 93 | $theme = getTheme($eula, $down); | ||
238 | 94 | } elseif (is_file($doc."/".$repl."/EULA.txt")) { // No special EULA found | ||
239 | 95 | $theme = getTheme("EULA.txt", $down); | ||
240 | 96 | } elseif (file_exists($fn) and findSpecialEULA($flist, "/.*EULA.txt.*/")) { | ||
241 | 97 | // If file is requested but no special EULA for it and no EULA.txt is present, | ||
242 | 98 | // look for any EULA and if found decide that current file is not protected. | ||
243 | 99 | setcookie("redirectlicensephp", "yes", 0, "/"); | ||
244 | 100 | header("Location: ".$down); | ||
245 | 101 | exit; | ||
246 | 102 | } elseif (empty($flist)) { // Directory contains only subdirs | ||
247 | 103 | setcookie("redirectlicensephp", "yes", 0, "/"); | ||
248 | 104 | header("Location: ".$down); | ||
249 | 105 | exit; | ||
250 | 106 | } else { // No special EULA, no EULA.txt, no OPEN-EULA.txt found | ||
251 | 107 | header("HTTP/1.1 403 Forbidden"); | ||
252 | 108 | header("Status: 403"); | ||
253 | 109 | echo "<h1>Forbidden</h1>"; | ||
254 | 110 | echo "You don't have permission to access ".$down." on this server."; | ||
255 | 111 | exit; | ||
256 | 112 | } | ||
257 | 113 | |||
258 | 114 | $template_content = file_get_contents($doc."/licenses/".$theme.".html"); | ||
259 | 115 | $eula_content = file_get_contents($doc."/licenses/".$theme.".txt"); | ||
260 | 116 | |||
261 | 117 | $out = str_replace("EULA.txt", $eula_content, $template_content); | ||
262 | 118 | echo $out; | ||
263 | 18 | ?> | 119 | ?> |
264 | 19 | 120 | ||
265 | === modified file 'licenses/linaro.html' | |||
266 | --- licenses/linaro.html 2012-03-27 13:57:57 +0000 | |||
267 | +++ licenses/linaro.html 2012-04-24 10:59:21 +0000 | |||
268 | @@ -82,11 +82,6 @@ | |||
269 | 82 | #actions .button-accept:hover { | 82 | #actions .button-accept:hover { |
270 | 83 | background: #9c5; | 83 | background: #9c5; |
271 | 84 | } | 84 | } |
272 | 85 | iframe#eula { | ||
273 | 86 | width: 100%; | ||
274 | 87 | height: 100%; | ||
275 | 88 | scrolling: auto; | ||
276 | 89 | } | ||
277 | 90 | </style> | 85 | </style> |
278 | 91 | </head> | 86 | </head> |
279 | 92 | <body> | 87 | <body> |
280 | @@ -101,7 +96,7 @@ | |||
281 | 101 | <div id="content"> | 96 | <div id="content"> |
282 | 102 | 97 | ||
283 | 103 | <div id="license-text"> | 98 | <div id="license-text"> |
285 | 104 | <iframe id="eula" frameborder=0 src="EULA.txt"></iframe> | 99 | EULA.txt |
286 | 105 | </div><!-- license-text --> | 100 | </div><!-- license-text --> |
287 | 106 | 101 | ||
288 | 107 | <div id="actions"> | 102 | <div id="actions"> |
289 | 108 | 103 | ||
290 | === added file 'licenses/linaro.txt' | |||
291 | --- licenses/linaro.txt 1970-01-01 00:00:00 +0000 | |||
292 | +++ licenses/linaro.txt 2012-04-24 10:59:21 +0000 | |||
293 | @@ -0,0 +1,1 @@ | |||
294 | 1 | Linaro license. | ||
295 | 0 | \ No newline at end of file | 2 | \ No newline at end of file |
296 | 1 | 3 | ||
297 | === modified file 'licenses/samsung.html' | |||
298 | --- licenses/samsung.html 2012-04-20 16:00:26 +0000 | |||
299 | +++ licenses/samsung.html 2012-04-24 10:59:21 +0000 | |||
300 | @@ -45,6 +45,7 @@ | |||
301 | 45 | color: black; | 45 | color: black; |
302 | 46 | margin: 2em; | 46 | margin: 2em; |
303 | 47 | padding: 2em; | 47 | padding: 2em; |
304 | 48 | overflow: scroll; | ||
305 | 48 | text-align: left; | 49 | text-align: left; |
306 | 49 | -moz-border-radius: 10px; | 50 | -moz-border-radius: 10px; |
307 | 50 | -webkit-border-radius: 10px; | 51 | -webkit-border-radius: 10px; |
308 | @@ -82,11 +83,6 @@ | |||
309 | 82 | #actions .button-accept:hover { | 83 | #actions .button-accept:hover { |
310 | 83 | background: #9c5; | 84 | background: #9c5; |
311 | 84 | } | 85 | } |
312 | 85 | iframe#eula { | ||
313 | 86 | width: 100%; | ||
314 | 87 | height: 100%; | ||
315 | 88 | scrolling: auto; | ||
316 | 89 | } | ||
317 | 90 | </style> | 86 | </style> |
318 | 91 | </head> | 87 | </head> |
319 | 92 | <body> | 88 | <body> |
320 | 93 | 89 | ||
321 | === modified file 'licenses/ste.html' | |||
322 | --- licenses/ste.html 2012-04-20 16:00:26 +0000 | |||
323 | +++ licenses/ste.html 2012-04-24 10:59:21 +0000 | |||
324 | @@ -88,11 +88,6 @@ | |||
325 | 88 | #actions .button-accept:hover { | 88 | #actions .button-accept:hover { |
326 | 89 | background: #9c5; | 89 | background: #9c5; |
327 | 90 | } | 90 | } |
328 | 91 | iframe#eula { | ||
329 | 92 | width: 100%; | ||
330 | 93 | height: 100%; | ||
331 | 94 | scrolling: auto; | ||
332 | 95 | } | ||
333 | 96 | </style> | 91 | </style> |
334 | 97 | </head> | 92 | </head> |
335 | 98 | <body> | 93 | <body> |
336 | 99 | 94 | ||
337 | === modified file 'testing/test_click_through_license.py' | |||
338 | --- testing/test_click_through_license.py 2012-03-27 09:53:11 +0000 | |||
339 | +++ testing/test_click_through_license.py 2012-04-24 10:59:21 +0000 | |||
340 | @@ -24,9 +24,14 @@ | |||
341 | 24 | linaro_license_path = '/licenses/linaro.html' | 24 | linaro_license_path = '/licenses/linaro.html' |
342 | 25 | samsung_test_file = '/android/~linaro-android/staging-origen/test.txt' | 25 | samsung_test_file = '/android/~linaro-android/staging-origen/test.txt' |
343 | 26 | ste_test_file = '/android/~linaro-android/staging-snowball/173/target/product/snowball/test.txt' | 26 | ste_test_file = '/android/~linaro-android/staging-snowball/173/target/product/snowball/test.txt' |
344 | 27 | ste_open_test_file = '/android/~linaro-android/staging-snowball/173/test.txt' | ||
345 | 27 | never_available = '/android/~linaro-android/staging-imx53/test.txt' | 28 | never_available = '/android/~linaro-android/staging-imx53/test.txt' |
346 | 28 | linaro_test_file = '/android/~linaro-android/staging-panda/test.txt' | 29 | linaro_test_file = '/android/~linaro-android/staging-panda/test.txt' |
347 | 29 | not_protected_test_file = '/android/~linaro-android/staging-vexpress-a9/test.txt' | 30 | not_protected_test_file = '/android/~linaro-android/staging-vexpress-a9/test.txt' |
348 | 31 | per_file_samsung_test_file = '/android/images/origen-blob.txt' | ||
349 | 32 | per_file_ste_test_file = '/android/images/snowball-blob.txt' | ||
350 | 33 | per_file_not_protected_test_file = '/android/images/MANIFEST' | ||
351 | 34 | dirs_only_dir = '/android/~linaro-android/' | ||
352 | 30 | 35 | ||
353 | 31 | 36 | ||
354 | 32 | class Contains(object): | 37 | class Contains(object): |
355 | @@ -180,7 +185,7 @@ | |||
356 | 180 | self.assertThat(testfile, Contains(search)) | 185 | self.assertThat(testfile, Contains(search)) |
357 | 181 | 186 | ||
358 | 182 | def test_accept_license_samsung_file(self): | 187 | def test_accept_license_samsung_file(self): |
360 | 183 | search = "This is a protected with click-through Samsung license." | 188 | search = "This is protected with click-through Samsung license." |
361 | 184 | testfile = fetcher.get(host + samsung_test_file) | 189 | testfile = fetcher.get(host + samsung_test_file) |
362 | 185 | fetcher.close() | 190 | fetcher.close() |
363 | 186 | if os.path.exists("%s/cookies.txt" % docroot): | 191 | if os.path.exists("%s/cookies.txt" % docroot): |
364 | @@ -194,7 +199,7 @@ | |||
365 | 194 | self.assertThat(testfile, Contains(search)) | 199 | self.assertThat(testfile, Contains(search)) |
366 | 195 | 200 | ||
367 | 196 | def test_accept_license_ste_file(self): | 201 | def test_accept_license_ste_file(self): |
369 | 197 | search = "This is a protected with click-through ST-E license." | 202 | search = "This is protected with click-through ST-E license." |
370 | 198 | testfile = fetcher.get(host + ste_test_file) | 203 | testfile = fetcher.get(host + ste_test_file) |
371 | 199 | fetcher.close() | 204 | fetcher.close() |
372 | 200 | if os.path.exists("%s/cookies.txt" % docroot): | 205 | if os.path.exists("%s/cookies.txt" % docroot): |
373 | @@ -207,19 +212,19 @@ | |||
374 | 207 | self.assertThat(testfile, Contains(search)) | 212 | self.assertThat(testfile, Contains(search)) |
375 | 208 | 213 | ||
376 | 209 | def test_license_accepted_samsung(self): | 214 | def test_license_accepted_samsung(self): |
378 | 210 | search = "This is a protected with click-through Samsung license." | 215 | search = "This is protected with click-through Samsung license." |
379 | 211 | os.rename("%s/cookies.samsung" % docroot, "%s/cookies.txt" % docroot) | 216 | os.rename("%s/cookies.samsung" % docroot, "%s/cookies.txt" % docroot) |
380 | 212 | testfile = fetcher.get(host + samsung_test_file, ignore_license=True) | 217 | testfile = fetcher.get(host + samsung_test_file, ignore_license=True) |
381 | 213 | self.assertThat(testfile, Contains(search)) | 218 | self.assertThat(testfile, Contains(search)) |
382 | 214 | 219 | ||
383 | 215 | def test_license_accepted_ste(self): | 220 | def test_license_accepted_ste(self): |
385 | 216 | search = "This is a protected with click-through ST-E license." | 221 | search = "This is protected with click-through ST-E license." |
386 | 217 | os.rename("%s/cookies.ste" % docroot, "%s/cookies.txt" % docroot) | 222 | os.rename("%s/cookies.ste" % docroot, "%s/cookies.txt" % docroot) |
387 | 218 | testfile = fetcher.get(host + ste_test_file, ignore_license=True) | 223 | testfile = fetcher.get(host + ste_test_file, ignore_license=True) |
388 | 219 | self.assertThat(testfile, Contains(search)) | 224 | self.assertThat(testfile, Contains(search)) |
389 | 220 | 225 | ||
390 | 221 | def test_internal_host_samsung(self): | 226 | def test_internal_host_samsung(self): |
392 | 222 | search = "This is a protected with click-through Samsung license." | 227 | search = "This is protected with click-through Samsung license." |
393 | 223 | subprocess.Popen(['sed', '-i', '/## Let internal hosts through ' | 228 | subprocess.Popen(['sed', '-i', '/## Let internal hosts through ' |
394 | 224 | 'always./ a %s' % local_rewrite, '%s/.htaccess' % docroot], | 229 | 'always./ a %s' % local_rewrite, '%s/.htaccess' % docroot], |
395 | 225 | stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT).wait() | 230 | stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT).wait() |
396 | @@ -228,10 +233,54 @@ | |||
397 | 228 | self.assertThat(testfile, Contains(search)) | 233 | self.assertThat(testfile, Contains(search)) |
398 | 229 | 234 | ||
399 | 230 | def test_internal_host_ste(self): | 235 | def test_internal_host_ste(self): |
401 | 231 | search = "This is a protected with click-through ST-E license." | 236 | search = "This is protected with click-through ST-E license." |
402 | 232 | subprocess.Popen(['sed', '-i', '/## Let internal hosts through ' | 237 | subprocess.Popen(['sed', '-i', '/## Let internal hosts through ' |
403 | 233 | 'always./ a %s' % local_rewrite, '%s/.htaccess' % docroot], | 238 | 'always./ a %s' % local_rewrite, '%s/.htaccess' % docroot], |
404 | 234 | stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT).wait() | 239 | stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT).wait() |
405 | 235 | testfile = fetcher.get(host + ste_test_file, ignore_license=True) | 240 | testfile = fetcher.get(host + ste_test_file, ignore_license=True) |
406 | 236 | shutil.copy("%s/dothtaccess" % docroot, "%s/.htaccess" % docroot) | 241 | shutil.copy("%s/dothtaccess" % docroot, "%s/.htaccess" % docroot) |
407 | 237 | self.assertThat(testfile, Contains(search)) | 242 | self.assertThat(testfile, Contains(search)) |
408 | 243 | |||
409 | 244 | def test_ste_open_file(self): | ||
410 | 245 | search = "This is always available." | ||
411 | 246 | testfile = fetcher.get(host + ste_open_test_file) | ||
412 | 247 | self.assertThat(testfile, Contains(search)) | ||
413 | 248 | |||
414 | 249 | def test_per_file_accept_license_samsung_file(self): | ||
415 | 250 | search = "This is protected with click-through Samsung license." | ||
416 | 251 | testfile = fetcher.get(host + per_file_samsung_test_file) | ||
417 | 252 | fetcher.close() | ||
418 | 253 | if os.path.exists("%s/cookies.txt" % docroot): | ||
419 | 254 | os.rename("%s/cookies.txt" % docroot, | ||
420 | 255 | "%s/cookies.samsung" % docroot) | ||
421 | 256 | self.assertThat(testfile, Contains(search)) | ||
422 | 257 | |||
423 | 258 | def test_per_file_accept_license_ste_file(self): | ||
424 | 259 | search = "This is protected with click-through ST-E license." | ||
425 | 260 | testfile = fetcher.get(host + per_file_ste_test_file) | ||
426 | 261 | fetcher.close() | ||
427 | 262 | if os.path.exists("%s/cookies.txt" % docroot): | ||
428 | 263 | os.rename("%s/cookies.txt" % docroot, "%s/cookies.ste" % docroot) | ||
429 | 264 | self.assertThat(testfile, Contains(search)) | ||
430 | 265 | |||
431 | 266 | def test_per_file_license_accepted_samsung(self): | ||
432 | 267 | search = "This is protected with click-through Samsung license." | ||
433 | 268 | os.rename("%s/cookies.samsung" % docroot, "%s/cookies.txt" % docroot) | ||
434 | 269 | testfile = fetcher.get(host + per_file_samsung_test_file, ignore_license=True) | ||
435 | 270 | self.assertThat(testfile, Contains(search)) | ||
436 | 271 | |||
437 | 272 | def test_per_file_license_accepted_ste(self): | ||
438 | 273 | search = "This is protected with click-through ST-E license." | ||
439 | 274 | os.rename("%s/cookies.ste" % docroot, "%s/cookies.txt" % docroot) | ||
440 | 275 | testfile = fetcher.get(host + per_file_ste_test_file, ignore_license=True) | ||
441 | 276 | self.assertThat(testfile, Contains(search)) | ||
442 | 277 | |||
443 | 278 | def test_per_file_non_protected_dirs(self): | ||
444 | 279 | search = "MANIFEST" | ||
445 | 280 | testfile = fetcher.get(host + per_file_not_protected_test_file) | ||
446 | 281 | self.assertThat(testfile, Contains(search)) | ||
447 | 282 | |||
448 | 283 | def test_dir_containing_only_dirs(self): | ||
449 | 284 | search = "Index of /android/~linaro-android" | ||
450 | 285 | testfile = fetcher.get(host + dirs_only_dir) | ||
451 | 286 | self.assertThat(testfile, Contains(search)) |
Looks good, it'd be nice to have a test for dirs only containing other dirs.