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

Proposed by Georgy Redkozubov
Status: Merged
Merged at revision: 72
Proposed branch: lp:~gesha/linaro-license-protection/997211
Merge into: lp:~linaro-automation/linaro-license-protection/trunk
Diff against target: 626 lines (+331/-178)
6 files modified
.htaccess (+8/-3)
licenses/LicenseHelper.php (+14/-27)
licenses/license.php (+7/-7)
testing/filefetcher.py (+0/-129)
testing/license_protected_file_downloader.py (+284/-0)
testing/test_click_through_license.py (+18/-12)
To merge this branch: bzr merge lp:~gesha/linaro-license-protection/997211
Reviewer Review Type Date Requested Status
Stevan Radaković code Approve
Review via email: mp+105452@code.launchpad.net

Description of the change

This branch adds proper redirection handling from license.php back to mod_rewrite.
Now correct URL is put in the location bar in cases of 404 and 403 errors instead of /licenses/license.php

To post a comment you must log in.
Revision history for this message
Stevan Radaković (stevanr) wrote :

You have some incorrect indentation in LicenseHelper.
Furthermore, is "redirectlicensephp" cookie supposed to be set in all three possible cases of redirection?

review: Needs Fixing (code)
Revision history for this message
Georgy Redkozubov (gesha) wrote :

> You have some incorrect indentation in LicenseHelper.
> Furthermore, is "redirectlicensephp" cookie supposed to be set in all three
> possible cases of redirection?

It is strictly needed for 200 and 403 cases but it is also needed to identify 403 status in .htaccess and this can't be done with server variables, so I used the same cookie.

71. By Georgy Redkozubov

Fixed indentation.

Revision history for this message
Stevan Radaković (stevanr) wrote :

Looks good now.

review: Approve (code)
72. By Georgy Redkozubov

[merge] Replace the filefetcher with newer version. Tests updated to use new filefetcher. License protection unit tests implemented, also light refactoring of license.php

73. By Georgy Redkozubov

Added test for 404 (Not found) error.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.htaccess'
--- .htaccess 2012-05-02 11:33:12 +0000
+++ .htaccess 2012-05-11 12:16:20 +0000
@@ -13,12 +13,12 @@
13## without port number for use in cookie domain13## without port number for use in cookie domain
14RewriteCond %{SERVER_PORT} !^80$ [OR]14RewriteCond %{SERVER_PORT} !^80$ [OR]
15RewriteCond %{SERVER_PORT} !^443$15RewriteCond %{SERVER_PORT} !^443$
16RewriteCond %{HTTP_HOST} (.*)(\:.*)16RewriteCond %{HTTP_HOST} ^([^:]*)$
17RewriteRule .* - [E=CO_DOMAIN:%1]17RewriteRule .* - [E=CO_DOMAIN:%1]
1818
19RewriteCond %{SERVER_PORT} !^80$ [OR]19RewriteCond %{SERVER_PORT} !^80$ [OR]
20RewriteCond %{SERVER_PORT} !^443$20RewriteCond %{SERVER_PORT} !^443$
21RewriteCond %{HTTP_HOST} (^.*$)21RewriteCond %{HTTP_HOST} ^([^:]*):(.*)$
22RewriteRule .* - [E=CO_DOMAIN:%1]22RewriteRule .* - [E=CO_DOMAIN:%1]
2323
24## Let internal hosts through always.24## Let internal hosts through always.
@@ -85,7 +85,12 @@
85RewriteRule .* - [L]85RewriteRule .* - [L]
8686
87## Unset cookie indicating redirect from license.php87## Unset cookie indicating redirect from license.php
88RewriteCond %{HTTP_COOKIE} redirectlicensephp=yes88## and redirect to reqested locations with status
89RewriteCond %{HTTP_COOKIE} redirectlicensephp=403
90RewriteRule .* - [CO=redirectlicensephp:INVALID:.%{ENV:CO_DOMAIN}:-1,L,F]
91
92RewriteCond %{HTTP_COOKIE} redirectlicensephp=200 [OR]
93RewriteCond %{HTTP_COOKIE} redirectlicensephp=404
89RewriteRule .* - [CO=redirectlicensephp:INVALID:.%{ENV:CO_DOMAIN}:-1,L]94RewriteRule .* - [CO=redirectlicensephp:INVALID:.%{ENV:CO_DOMAIN}:-1,L]
9095
91## Redirect to the Samsung license file protected builds.96## Redirect to the Samsung license file protected builds.
9297
=== modified file 'licenses/LicenseHelper.php'
--- licenses/LicenseHelper.php 2012-05-08 11:27:26 +0000
+++ licenses/LicenseHelper.php 2012-05-11 12:16:20 +0000
@@ -73,30 +73,17 @@
73 return $theme;73 return $theme;
74 }74 }
7575
76 public static function status_forbidden($dir)
77 {
78 header("Status: 403");
79 header("HTTP/1.1 403 Forbidden");
80 echo "<h1>Forbidden</h1>";
81 echo "You don't have permission to access ".$dir." on this server.";
82 exit;
83 }
84
85 public static function status_ok($dir, $domain)
86 {
87 header("Status: 200");
88 header("Location: ".$dir);
89 setcookie("redirectlicensephp", "yes", 0, "/", ".".$domain);
90 exit;
91 }
92
93 public static function status_not_found()
94 {
95 header("Status: 404");
96 header("HTTP/1.0 404 Not Found");
97 echo "<h1>404 Not Found</h1>";
98 echo "The requested URL was not found on this server.";
99 exit;
100 }
101
102}
103\ No newline at end of file76\ No newline at end of file
77 public static function redirect_with_status($dir, $domain, $status)
78 {
79 static $http = array (
80 200 => "HTTP/1.1 200 OK",
81 403 => "HTTP/1.1 403 Forbidden",
82 404 => "HTTP/1.1 404 Not Found"
83 );
84 header($http[$status]);
85 header ("Location: $dir");
86 header("Status: ".$status);
87 setcookie("redirectlicensephp", $status, 0, "/", ".".$domain);
88 exit;
89 }
90}
10491
=== modified file 'licenses/license.php'
--- licenses/license.php 2012-05-04 12:48:27 +0000
+++ licenses/license.php 2012-05-11 12:16:20 +0000
@@ -11,7 +11,7 @@
11$eula = '';11$eula = '';
1212
13if (preg_match("/.*openid.*/", $fn) or preg_match("/.*restricted.*/", $fn) or preg_match("/.*private.*/", $fn)) {13if (preg_match("/.*openid.*/", $fn) or preg_match("/.*restricted.*/", $fn) or preg_match("/.*private.*/", $fn)) {
14 LicenseHelper::status_ok($down, $domain);14 LicenseHelper::redirect_with_status($down, $domain, 200);
15}15}
1616
17if (file_exists($fn) and LicenseHelper::checkFile($fn)) { // Requested download is file17if (file_exists($fn) and LicenseHelper::checkFile($fn)) { // Requested download is file
@@ -23,7 +23,7 @@
23 $repl = $down;23 $repl = $down;
24 $name_only = array();24 $name_only = array();
25} else { // Requested download not found on server25} else { // Requested download not found on server
26 LicenseHelper::status_not_found();26 LicenseHelper::redirect_with_status($down, $domain, 404);
27}27}
2828
29$flist = LicenseHelper::getFilesList($search_dir);29$flist = LicenseHelper::getFilesList($search_dir);
@@ -41,18 +41,18 @@
41 } elseif (LicenseHelper::findFileByPattern($flist, "/.*EULA.txt.*/")) {41 } elseif (LicenseHelper::findFileByPattern($flist, "/.*EULA.txt.*/")) {
42 // If file is requested but no special EULA for it and no EULA.txt is present,42 // If file is requested but no special EULA for it and no EULA.txt is present,
43 // look for any EULA and if found decide that current file is not protected.43 // look for any EULA and if found decide that current file is not protected.
44 LicenseHelper::status_ok($down, $domain);44 LicenseHelper::redirect_with_status($down, $domain, 200);
45 } else {45 } else {
46 LicenseHelper::status_forbidden($down);46 LicenseHelper::redirect_with_status($down, $domain, 403);
47 }47 }
48} elseif (is_dir($fn)) {48} elseif (is_dir($fn)) {
49 if (empty($flist) or LicenseHelper::findFileByPattern($flist, "/.*EULA.txt.*/")) { // Directory contains only subdirs or any EULA49 if (empty($flist) or LicenseHelper::findFileByPattern($flist, "/.*EULA.txt.*/")) { // Directory contains only subdirs or any EULA
50 LicenseHelper::status_ok($down, $domain);50 LicenseHelper::redirect_with_status($down, $domain, 200);
51 } else { // No special EULA, no EULA.txt, no OPEN-EULA.txt found51 } else { // No special EULA, no EULA.txt, no OPEN-EULA.txt found
52 LicenseHelper::status_forbidden($down);52 LicenseHelper::redirect_with_status($down, $domain, 403);
53 }53 }
54} else {54} else {
55 LicenseHelper::status_forbidden($down);55 LicenseHelper::redirect_with_status($down, $domain, 403);
56}56}
5757
58$template_content = file_get_contents($doc."/licenses/".$theme.".html");58$template_content = file_get_contents($doc."/licenses/".$theme.".html");
5959
=== removed file 'testing/filefetcher.py'
--- testing/filefetcher.py 2012-01-13 11:48:16 +0000
+++ testing/filefetcher.py 1970-01-01 00:00:00 +0000
@@ -1,129 +0,0 @@
1#!/usr/bin/env python
2
3# Changes required to address EULA for the origen hwpacks
4
5import argparse
6import os
7import pycurl
8import re
9import urlparse
10
11
12class LicenseProtectedFileFetcher:
13 """Fetch a file from the web that may be protected by a license redirect
14
15 This is designed to run on snapshots.linaro.org. License HTML file are in
16 the form:
17
18 <vendor>.html has a link to <vendor>-accept.html
19
20 If self.get is pointed at a file that has to go through one of these
21 licenses, it should be able to automatically accept the license and
22 download the file.
23
24 Once a license has been accepted, it will be used for all following
25 downloads.
26
27 If self.close() is called before the object is deleted, cURL will store
28 the license accept cookie to cookies.txt, so it can be used for later
29 downloads.
30
31 """
32 def __init__(self):
33 """Set up cURL"""
34 self.curl = pycurl.Curl()
35 self.curl.setopt(pycurl.FOLLOWLOCATION, 1)
36 self.curl.setopt(pycurl.WRITEFUNCTION, self._write_body)
37 self.curl.setopt(pycurl.HEADERFUNCTION, self._write_header)
38 self.curl.setopt(pycurl.COOKIEFILE, "cookies.txt")
39 self.curl.setopt(pycurl.COOKIEJAR, "cookies.txt")
40
41 def _get(self, url):
42 """Clear out header and body storage, fetch URL, filling them in."""
43 self.curl.setopt(pycurl.URL, url)
44
45 self.body = ""
46 self.header = ""
47
48 self.curl.perform()
49
50 def get(self, url, ignore_license=False, accept_license=True):
51 """Fetch the requested URL, ignoring license at all or
52 accepting or declining licenses, returns file body.
53
54 Fetches the file at url. If a redirect is encountered, it is
55 expected to be to a license that has an accept or decline link.
56 Follow that link, then download original file or nolicense notice.
57
58 """
59 self._get(url)
60
61 if ignore_license:
62 return self.body
63
64 location = self._get_location()
65 if location:
66 # Off to the races - we have been redirected.
67 # Expect to find a link to self.location with -accepted or
68 # -declined inserted before the .html,
69 # i.e. ste.html -> ste-accepted.html
70
71 # Get the file from the URL (full path)
72 file = urlparse.urlparse(location).path
73
74 # Get the file without the rest of the path
75 file = os.path.split(file)[-1]
76
77 # Look for a link with accepted.html or declined.html
78 # in the page name. Follow it.
79 new_file = None
80 for line in self.body.splitlines():
81 if accept_license:
82 link_search = re.search("""href=.*?["'](.*?-accepted.html)""",
83 line)
84 else:
85 link_search = re.search("""href=.*?["'](.*?-declined.html)""",
86 line)
87 if link_search:
88 # Have found license decline URL!
89 new_file = link_search.group(1)
90
91 if new_file:
92 # accept or decline the license...
93 next_url = re.sub(file, new_file, location)
94 self._get(next_url)
95
96 # The above get *should* take us to the file requested via
97 # a redirect. If we manually need to follow that redirect,
98 # do that now.
99
100 if accept_license and self._get_location():
101 # If we haven't been redirected to our original file,
102 # we should be able to just download it now.
103 self._get(url)
104
105 return self.body
106
107 def _search_header(self, field):
108 """Search header for the supplied field, return field / None"""
109 for line in self.header.splitlines():
110 search = re.search(field + ":\s+(.*?)$", line)
111 if search:
112 return search.group(1)
113 return None
114
115 def _get_location(self):
116 """Return content of Location field in header / None"""
117 return self._search_header("Location")
118
119 def _write_body(self, buf):
120 """Used by curl as a sink for body content"""
121 self.body += buf
122
123 def _write_header(self, buf):
124 """Used by curl as a sink for header content"""
125 self.header += buf
126
127 def close(self):
128 """Wrapper to close curl - this will allow curl to write out cookies"""
129 self.curl.close()
1300
=== added file 'testing/license_protected_file_downloader.py'
--- testing/license_protected_file_downloader.py 1970-01-01 00:00:00 +0000
+++ testing/license_protected_file_downloader.py 2012-05-11 12:16:20 +0000
@@ -0,0 +1,284 @@
1#!/usr/bin/env python
2
3import argparse
4import os
5import pycurl
6import re
7import urlparse
8import html2text
9from BeautifulSoup import BeautifulSoup
10
11class LicenseProtectedFileFetcher:
12 """Fetch a file from the web that may be protected by a license redirect
13
14 This is designed to run on snapshots.linaro.org. License HTML file are in
15 the form:
16
17 <vendor>.html has a link to <vendor>-accept.html
18
19 If self.get is pointed at a file that has to go through one of these
20 licenses, it should be able to automatically accept the license and
21 download the file.
22
23 Once a license has been accepted, it will be used for all following
24 downloads.
25
26 If self.close() is called before the object is deleted, cURL will store
27 the license accept cookie to cookies.txt, so it can be used for later
28 downloads.
29
30 """
31 def __init__(self, cookie_file="cookies.txt"):
32 """Set up cURL"""
33 self.curl = pycurl.Curl()
34 self.curl.setopt(pycurl.WRITEFUNCTION, self._write_body)
35 self.curl.setopt(pycurl.HEADERFUNCTION, self._write_header)
36 self.curl.setopt(pycurl.FOLLOWLOCATION, 1)
37 self.curl.setopt(pycurl.COOKIEFILE, cookie_file)
38 self.curl.setopt(pycurl.COOKIEJAR, cookie_file)
39 self.file_out = None
40
41 def _get(self, url):
42 """Clear out header and body storage, fetch URL, filling them in."""
43 url = url.encode("ascii")
44 self.curl.setopt(pycurl.URL, url)
45
46 self.body = ""
47 self.header = ""
48
49 if self.file_name:
50 self.file_out = open(self.file_name, 'w')
51 else:
52 self.file_out = None
53
54 self.curl.perform()
55 self._parse_headers(url)
56
57 if self.file_out:
58 self.file_out.close()
59
60 def _parse_headers(self, url):
61 header = {}
62 for line in self.header.splitlines():
63 # Header lines typically are of the form thing: value...
64 test_line = re.search("^(.*?)\s*:\s*(.*)$", line)
65
66 if test_line:
67 header[test_line.group(1)] = test_line.group(2)
68
69 # The location attribute is sometimes relative, but we would
70 # like to have it as always absolute...
71 if 'Location' in header:
72 parsed_location = urlparse.urlparse(header["Location"])
73
74 # If not an absolute location...
75 if not parsed_location.netloc:
76 parsed_source_url = urlparse.urlparse(url)
77 new_location = ["", "", "", "", ""]
78
79 new_location[0] = parsed_source_url.scheme
80 new_location[1] = parsed_source_url.netloc
81 new_location[2] = header["Location"]
82
83 # Update location with absolute URL
84 header["Location"] = urlparse.urlunsplit(new_location)
85
86 self.header_text = self.header
87 self.header = header
88
89 def get_headers(self, url):
90 url = url.encode("ascii")
91 self.curl.setopt(pycurl.URL, url)
92
93 self.body = ""
94 self.header = ""
95
96 # Setting NOBODY causes CURL to just fetch the header.
97 self.curl.setopt(pycurl.NOBODY, True)
98 self.curl.perform()
99 self.curl.setopt(pycurl.NOBODY, False)
100
101 self._parse_headers(url)
102
103 return self.header
104
105 def get_or_return_license(self, url, file_name=None):
106 """Get file at the requested URL or, if behind a license, return that.
107
108 If the URL provided does not redirect us to a license, then return the
109 body of that file. If we are redirected to a license click through
110 then return (the license as plain text, url to accept the license).
111
112 If the user of this function accepts the license, then they should
113 call get_protected_file."""
114
115 self.file_name = file_name
116
117 # Get the license details. If this returns None, the file isn't license
118 # protected and we can just return the file we started to get in the
119 # function (self.body).
120 license_details = self._get_license(url)
121
122 if license_details:
123 return license_details
124
125 return self.body
126
127 def get(self, url, file_name=None, ignore_license=False, accept_license=True):
128 """Fetch the requested URL, accepting licenses
129
130 Fetches the file at url. If a redirect is encountered, it is
131 expected to be to a license that has an accept link. Follow that link,
132 then download the original file. Returns the fist 1MB of the file
133 (see _write_body).
134
135 """
136
137 self.file_name = file_name
138 if ignore_license:
139 self._get(url)
140 return self.body
141
142 license_details = self._get_license(url)
143
144 if license_details:
145 # Found a license.
146 if accept_license:
147 # Accept the license without looking at it and
148 # start fetching the file we originally wanted.
149 accept_url = license_details[1]
150 self.get_protected_file(accept_url, url)
151 else:
152 # We want to decline the license and return the notice.
153 decline_url = license_details[2]
154 self._get(decline_url)
155
156 else:
157 # If we got here, there wasn't a license protecting the file
158 # so we just fetch it.
159 self._get(url)
160
161 return self.body
162
163 def _get_license(self, url):
164 """Return (license, accept URL, decline URL) if found,
165 else return None.
166
167 """
168
169 self.get_headers(url)
170
171 if "Location" in self.header and self.header["Location"] != url:
172 # We have been redirected to a new location - the license file
173 location = self.header["Location"]
174
175 # Fetch the license HTML
176 self._get(location)
177
178 # Get the file from the URL (full path)
179 file = urlparse.urlparse(location).path
180
181 # Get the file without the rest of the path
182 file = os.path.split(file)[-1]
183
184 # Look for a link with accepted.html in the page name. Follow it.
185 accept_search, decline_search = None, None
186 for line in self.body.splitlines():
187 if not accept_search:
188 accept_search = re.search(
189 """href=.*?["'](.*?-accepted.html)""",
190 line)
191 if not decline_search:
192 decline_search = re.search(
193 """href=.*?["'](.*?-declined.html)""",
194 line)
195
196 if accept_search and decline_search:
197 # Have found license accept URL!
198 new_file = accept_search.group(1)
199 accept_url = re.sub(file, new_file, location)
200
201 # Found decline URL as well.
202 new_file_decline = decline_search.group(1)
203 decline_url = re.sub(file, new_file_decline, location)
204
205 # Parse the HTML using BeautifulSoup
206 soup = BeautifulSoup(self.body)
207
208 # The license is in a div with the ID license-text, so we
209 # use this to pull just the license out of the HTML.
210 html_license = u""
211 for chunk in soup.findAll(id="license-text"):
212 # Output of chunk.prettify is UTF8, but comes back
213 # as a str, so convert it here.
214 html_license += chunk.prettify().decode("utf-8")
215
216 text_license = html2text.html2text(html_license)
217
218 return text_license, accept_url, decline_url
219
220 return None
221
222 def get_protected_file(self, accept_url, url):
223 """Gets the file redirected to by the accept_url"""
224
225 self._get(accept_url) # Accept the license
226
227 if not("Location" in self.header and self.header["Location"] == url):
228 # If we got here, we don't have the file yet (weren't redirected
229 # to it). Fetch our target file. This should work now that we have
230 # the right cookie.
231 self._get(url) # Download the target file
232
233 return self.body
234
235 def _write_body(self, buf):
236 """Used by curl as a sink for body content"""
237
238 # If we have a target file to write to, write to it
239 if self.file_out:
240 self.file_out.write(buf)
241
242 # Only buffer first 1MB of body. This should be plenty for anything
243 # we wish to parse internally.
244 if len(self.body) < 1024*1024*1024:
245 # XXX Would be nice to stop keeping the file in RAM at all and
246 # passing large buffers around. Perhaps only keep in RAM if
247 # file_name == None? (used for getting directory listings
248 # normally).
249 self.body += buf
250
251 def _write_header(self, buf):
252 """Used by curl as a sink for header content"""
253 self.header += buf
254
255 def register_progress_callback(self, callback):
256 self.curl.setopt(pycurl.NOPROGRESS, 0)
257 self.curl.setopt(pycurl.PROGRESSFUNCTION, callback)
258
259 def close(self):
260 """Wrapper to close curl - this will allow curl to write out cookies"""
261 self.curl.close()
262
263def main():
264 """Download file specified on command line"""
265 parser = argparse.ArgumentParser(description="Download a file, accepting "
266 "any licenses required to do so.")
267
268 parser.add_argument('url', metavar="URL", type=str, nargs=1,
269 help="URL of file to download.")
270
271 args = parser.parse_args()
272
273 fetcher = LicenseProtectedFileFetcher()
274
275 # Get file name from URL
276 file_name = os.path.basename(urlparse.urlparse(args.url[0]).path)
277 if not file_name:
278 file_name = "downloaded"
279 fetcher.get(args.url[0], file_name)
280
281 fetcher.close()
282
283if __name__ == "__main__":
284 main()
0285
=== modified file 'testing/test_click_through_license.py'
--- testing/test_click_through_license.py 2012-05-07 08:48:51 +0000
+++ testing/test_click_through_license.py 2012-05-11 12:16:20 +0000
@@ -9,7 +9,7 @@
99
10from testtools import TestCase10from testtools import TestCase
11from testtools.matchers import Mismatch11from testtools.matchers import Mismatch
12from filefetcher import LicenseProtectedFileFetcher12from license_protected_file_downloader import LicenseProtectedFileFetcher
1313
14fetcher = LicenseProtectedFileFetcher()14fetcher = LicenseProtectedFileFetcher()
15cwd = os.getcwd()15cwd = os.getcwd()
@@ -28,6 +28,7 @@
28never_available = '/android/~linaro-android/staging-imx53/test.txt'28never_available = '/android/~linaro-android/staging-imx53/test.txt'
29linaro_test_file = '/android/~linaro-android/staging-panda/test.txt'29linaro_test_file = '/android/~linaro-android/staging-panda/test.txt'
30not_protected_test_file = '/android/~linaro-android/staging-vexpress-a9/test.txt'30not_protected_test_file = '/android/~linaro-android/staging-vexpress-a9/test.txt'
31not_found_test_file = '/android/~linaro-android/staging-vexpress-a9/notfound.txt'
31per_file_samsung_test_file = '/android/images/origen-blob.txt'32per_file_samsung_test_file = '/android/images/origen-blob.txt'
32per_file_ste_test_file = '/android/images/snowball-blob.txt'33per_file_ste_test_file = '/android/images/snowball-blob.txt'
33per_file_not_protected_test_file = '/android/images/MANIFEST'34per_file_not_protected_test_file = '/android/images/MANIFEST'
@@ -145,19 +146,19 @@
145 self.assertThat(testfile, Contains(search))146 self.assertThat(testfile, Contains(search))
146147
147 def test_redirect_to_license_samsung(self):148 def test_redirect_to_license_samsung(self):
148 search = "LICENSE AGREEMENT"149 search = "PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY"
149 testfile = fetcher.get(host + samsung_test_file, ignore_license=True)150 testfile = fetcher.get_or_return_license(host + samsung_test_file)
150 self.assertThat(testfile, Contains(search))151 self.assertThat(testfile[0], Contains(search))
151152
152 def test_redirect_to_license_ste(self):153 def test_redirect_to_license_ste(self):
153 search = "LICENSE AGREEMENT"154 search = "PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY"
154 testfile = fetcher.get(host + ste_test_file, ignore_license=True)155 testfile = fetcher.get_or_return_license(host + ste_test_file)
155 self.assertThat(testfile, Contains(search))156 self.assertThat(testfile[0], Contains(search))
156157
157 def test_redirect_to_license_linaro(self):158 def test_redirect_to_license_linaro(self):
158 search = "LICENSE AGREEMENT"159 search = "Linaro license."
159 testfile = fetcher.get(host + linaro_test_file, ignore_license=True)160 testfile = fetcher.get_or_return_license(host + linaro_test_file)
160 self.assertThat(testfile, Contains(search))161 self.assertThat(testfile[0], Contains(search))
161162
162 def test_decline_license_samsung(self):163 def test_decline_license_samsung(self):
163 search = "License has not been accepted"164 search = "License has not been accepted"
@@ -214,13 +215,13 @@
214 def test_license_accepted_samsung(self):215 def test_license_accepted_samsung(self):
215 search = "This is protected with click-through Samsung license."216 search = "This is protected with click-through Samsung license."
216 os.rename("%s/cookies.samsung" % docroot, "%s/cookies.txt" % docroot)217 os.rename("%s/cookies.samsung" % docroot, "%s/cookies.txt" % docroot)
217 testfile = fetcher.get(host + samsung_test_file, ignore_license=True)218 testfile = fetcher.get(host + samsung_test_file)
218 self.assertThat(testfile, Contains(search))219 self.assertThat(testfile, Contains(search))
219220
220 def test_license_accepted_ste(self):221 def test_license_accepted_ste(self):
221 search = "This is protected with click-through ST-E license."222 search = "This is protected with click-through ST-E license."
222 os.rename("%s/cookies.ste" % docroot, "%s/cookies.txt" % docroot)223 os.rename("%s/cookies.ste" % docroot, "%s/cookies.txt" % docroot)
223 testfile = fetcher.get(host + ste_test_file, ignore_license=True)224 testfile = fetcher.get(host + ste_test_file)
224 self.assertThat(testfile, Contains(search))225 self.assertThat(testfile, Contains(search))
225226
226 def test_internal_host_samsung(self):227 def test_internal_host_samsung(self):
@@ -284,3 +285,8 @@
284 search = "Index of /android/~linaro-android"285 search = "Index of /android/~linaro-android"
285 testfile = fetcher.get(host + dirs_only_dir)286 testfile = fetcher.get(host + dirs_only_dir)
286 self.assertThat(testfile, Contains(search))287 self.assertThat(testfile, Contains(search))
288
289 def test_not_found_file(self):
290 search = "Not Found"
291 testfile = fetcher.get(host + not_found_test_file)
292 self.assertThat(testfile, Contains(search))

Subscribers

People subscribed via source and target branches