summaryrefslogtreecommitdiff
path: root/Lib/test/test_urllib2.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2011-03-29 12:53:55 -0700
committerGuido van Rossum <guido@python.org>2011-03-29 12:53:55 -0700
commit07ef62c47c14ea80e9fd0923e1693d222df506ff (patch)
tree8958a5f93c705f737f0a0932d8ad2512a7e24aa7 /Lib/test/test_urllib2.py
parent3c599bdbd1d7fd3436fff47d1338593dff3e58a2 (diff)
parent079381d236f6e62db3a48cbffb14978124d94d14 (diff)
downloadcpython-git-07ef62c47c14ea80e9fd0923e1693d222df506ff.tar.gz
Merge issue 11662 from 2.6.
Diffstat (limited to 'Lib/test/test_urllib2.py')
-rw-r--r--Lib/test/test_urllib2.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index 789dcd3442..95dfb88d2a 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -969,6 +969,27 @@ class HandlerTests(unittest.TestCase):
self.assertEqual(count,
urllib2.HTTPRedirectHandler.max_redirections)
+ def test_invalid_redirect(self):
+ from_url = "http://example.com/a.html"
+ valid_schemes = ['http', 'https', 'ftp']
+ invalid_schemes = ['file', 'imap', 'ldap']
+ schemeless_url = "example.com/b.html"
+ h = urllib2.HTTPRedirectHandler()
+ o = h.parent = MockOpener()
+ req = Request(from_url)
+
+ for scheme in invalid_schemes:
+ invalid_url = scheme + '://' + schemeless_url
+ self.assertRaises(urllib2.HTTPError, h.http_error_302,
+ req, MockFile(), 302, "Security Loophole",
+ MockHeaders({"location": invalid_url}))
+
+ for scheme in valid_schemes:
+ valid_url = scheme + '://' + schemeless_url
+ h.http_error_302(req, MockFile(), 302, "That's fine",
+ MockHeaders({"location": valid_url}))
+ self.assertEqual(o.req.get_full_url(), valid_url)
+
def test_cookie_redirect(self):
# cookies shouldn't leak into redirected requests
from cookielib import CookieJar