summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2013-10-27 06:46:09 (GMT)
committerGeorg Brandl <georg@python.org>2013-10-27 06:46:09 (GMT)
commitb89b5df9c9aa2e45bfffa95f5e3deb6234232c93 (patch)
treefd9bfa96b2e5cbc69acc235dd15dd682c10fc00e /Lib/test
parent68457be619b919127d0858322ce84e901fd89728 (diff)
parent045ee06ae91a1503a8d512929c54e16deabfe9a8 (diff)
downloadcpython-b89b5df9c9aa2e45bfffa95f5e3deb6234232c93.zip
cpython-b89b5df9c9aa2e45bfffa95f5e3deb6234232c93.tar.gz
cpython-b89b5df9c9aa2e45bfffa95f5e3deb6234232c93.tar.bz2
merge with 3.3
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_httplib.py9
-rw-r--r--Lib/test/test_imaplib.py11
-rw-r--r--Lib/test/test_nntplib.py10
-rw-r--r--Lib/test/test_poplib.py14
-rw-r--r--Lib/test/test_ssl.py38
5 files changed, 74 insertions, 8 deletions
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
index 778e919..31c0b6a 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -347,6 +347,15 @@ class BasicTest(TestCase):
self.fail("Did not expect response from HEAD request")
self.assertEqual(bytes(b), b'\x00'*5)
+ def test_too_many_headers(self):
+ headers = '\r\n'.join('Header%d: foo' % i
+ for i in range(client._MAXHEADERS + 1)) + '\r\n'
+ text = ('HTTP/1.1 200 OK\r\n' + headers)
+ s = FakeSocket(text)
+ r = client.HTTPResponse(s)
+ self.assertRaisesRegex(client.HTTPException,
+ r"got more than \d+ headers", r.begin)
+
def test_send_file(self):
expected = (b'GET /foo HTTP/1.1\r\nHost: example.com\r\n'
b'Accept-Encoding: identity\r\nContent-Length:')
diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py
index c37ea1d..81bfd1f 100644
--- a/Lib/test/test_imaplib.py
+++ b/Lib/test/test_imaplib.py
@@ -325,6 +325,17 @@ class BaseThreadedNetworkedTests(unittest.TestCase):
self.assertEqual(ret, "OK")
+ def test_linetoolong(self):
+ class TooLongHandler(SimpleIMAPHandler):
+ def handle(self):
+ # Send a very long response line
+ self.wfile.write(b'* OK ' + imaplib._MAXLINE*b'x' + b'\r\n')
+
+ with self.reaped_server(TooLongHandler) as server:
+ self.assertRaises(imaplib.IMAP4.error,
+ self.imap_class, *server.server_address)
+
+
class ThreadedNetworkedTests(BaseThreadedNetworkedTests):
server_class = socketserver.TCPServer
diff --git a/Lib/test/test_nntplib.py b/Lib/test/test_nntplib.py
index 7cf497a..d00c9db 100644
--- a/Lib/test/test_nntplib.py
+++ b/Lib/test/test_nntplib.py
@@ -584,6 +584,11 @@ class NNTPv1Handler:
<a4929a40-6328-491a-aaaf-cb79ed7309a2@q2g2000vbk.googlegroups.com>
<f30c0419-f549-4218-848f-d7d0131da931@y3g2000vbm.googlegroups.com>
.""")
+ elif (group == 'comp.lang.python' and
+ date_str in ('20100101', '100101') and
+ time_str == '090000'):
+ self.push_lit('too long line' * 3000 +
+ '\n.')
else:
self.push_lit("""\
230 An empty list of newsarticles follows
@@ -1179,6 +1184,11 @@ class NNTPv1v2TestsMixin:
self.assertEqual(cm.exception.response,
"435 Article not wanted")
+ def test_too_long_lines(self):
+ dt = datetime.datetime(2010, 1, 1, 9, 0, 0)
+ self.assertRaises(nntplib.NNTPDataError,
+ self.server.newnews, "comp.lang.python", dt)
+
class NNTPv1Tests(NNTPv1v2TestsMixin, MockedNNTPTestsMixin, unittest.TestCase):
"""Tests an NNTP v1 server (no capabilities)."""
diff --git a/Lib/test/test_poplib.py b/Lib/test/test_poplib.py
index 935848b..dd51ac9 100644
--- a/Lib/test/test_poplib.py
+++ b/Lib/test/test_poplib.py
@@ -94,7 +94,7 @@ class DummyPOP3Handler(asynchat.async_chat):
def cmd_list(self, arg):
if arg:
- self.push('+OK %s %s' %(arg, arg))
+ self.push('+OK %s %s' % (arg, arg))
else:
self.push('+OK')
asynchat.async_chat.push(self, LIST_RESP)
@@ -278,6 +278,10 @@ class TestPOP3Class(TestCase):
foo = self.client.retr('foo')
self.assertEqual(foo, expected)
+ def test_too_long_lines(self):
+ self.assertRaises(poplib.error_proto, self.client._shortcmd,
+ 'echo +%s' % ((poplib._MAXLINE + 10) * 'a'))
+
def test_dele(self):
self.assertOK(self.client.dele('foo'))
@@ -400,7 +404,13 @@ if SUPPORTS_SSL:
def tearDown(self):
if self.client.file is not None and self.client.sock is not None:
- self.client.quit()
+ try:
+ self.client.quit()
+ except poplib.error_proto:
+ # happens in the test_too_long_lines case; the overlong
+ # response will be treated as response to QUIT and raise
+ # this exception
+ pass
self.server.stop()
def test_stls(self):
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
index 2605e68..b1cb8c5 100644
--- a/Lib/test/test_ssl.py
+++ b/Lib/test/test_ssl.py
@@ -358,11 +358,7 @@ class BasicSocketTests(unittest.TestCase):
fail(cert, 'Xa.com')
fail(cert, '.a.com')
- cert = {'subject': ((('commonName', 'a.*.com'),),)}
- ok(cert, 'a.foo.com')
- fail(cert, 'a..com')
- fail(cert, 'a.com')
-
+ # only match one left-most wildcard
cert = {'subject': ((('commonName', 'f*.com'),),)}
ok(cert, 'foo.com')
ok(cert, 'f.com')
@@ -377,6 +373,36 @@ class BasicSocketTests(unittest.TestCase):
fail(cert, 'example.org')
fail(cert, 'null.python.org')
+ # error cases with wildcards
+ cert = {'subject': ((('commonName', '*.*.a.com'),),)}
+ fail(cert, 'bar.foo.a.com')
+ fail(cert, 'a.com')
+ fail(cert, 'Xa.com')
+ fail(cert, '.a.com')
+
+ cert = {'subject': ((('commonName', 'a.*.com'),),)}
+ fail(cert, 'a.foo.com')
+ fail(cert, 'a..com')
+ fail(cert, 'a.com')
+
+ # wildcard doesn't match IDNA prefix 'xn--'
+ idna = 'püthon.python.org'.encode("idna").decode("ascii")
+ cert = {'subject': ((('commonName', idna),),)}
+ ok(cert, idna)
+ cert = {'subject': ((('commonName', 'x*.python.org'),),)}
+ fail(cert, idna)
+ cert = {'subject': ((('commonName', 'xn--p*.python.org'),),)}
+ fail(cert, idna)
+
+ # wildcard in first fragment and IDNA A-labels in sequent fragments
+ # are supported.
+ idna = 'www*.pythön.org'.encode("idna").decode("ascii")
+ cert = {'subject': ((('commonName', idna),),)}
+ ok(cert, 'www.pythön.org'.encode("idna").decode("ascii"))
+ ok(cert, 'www1.pythön.org'.encode("idna").decode("ascii"))
+ fail(cert, 'ftp.pythön.org'.encode("idna").decode("ascii"))
+ fail(cert, 'pythön.org'.encode("idna").decode("ascii"))
+
# Slightly fake real-world example
cert = {'notAfter': 'Jun 26 21:41:46 2011 GMT',
'subject': ((('commonName', 'linuxfrz.org'),),),
@@ -437,7 +463,7 @@ class BasicSocketTests(unittest.TestCase):
cert = {'subject': ((('commonName', 'a*b.com'),),)}
ok(cert, 'axxb.com')
cert = {'subject': ((('commonName', 'a*b.co*'),),)}
- ok(cert, 'axxb.com')
+ fail(cert, 'axxb.com')
cert = {'subject': ((('commonName', 'a*b*.com'),),)}
with self.assertRaises(ssl.CertificateError) as cm:
ssl.match_hostname(cert, 'axxbxxc.com')