diff options
| author | guido@google.com <guido@google.com> | 2011-03-29 17:48:23 (GMT) |
|---|---|---|
| committer | guido@google.com <guido@google.com> | 2011-03-29 17:48:23 (GMT) |
| commit | 9a9fdfad59adb864ddd8f1227aada0c24b9d007b (patch) | |
| tree | 8edd271a7843d949972e1ca6675beabefe491ec1 /Lib/test/test_urllib2.py | |
| parent | f23c515e5b932ee26c3eaa95bf0447fbe43b2c47 (diff) | |
| parent | 92ecb8737b9c708268c6451a01835192c181b721 (diff) | |
| download | cpython-9a9fdfad59adb864ddd8f1227aada0c24b9d007b.zip cpython-9a9fdfad59adb864ddd8f1227aada0c24b9d007b.tar.gz cpython-9a9fdfad59adb864ddd8f1227aada0c24b9d007b.tar.bz2 | |
Merge urllib/urllib2 security fix from 2.5 branch.
Diffstat (limited to 'Lib/test/test_urllib2.py')
| -rw-r--r-- | Lib/test/test_urllib2.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 65ad8e3..640c661 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -942,6 +942,28 @@ 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) + req.timeout = socket._GLOBAL_DEFAULT_TIMEOUT + + 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 |
