summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_nntplib.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-02-14 22:30:35 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-02-14 22:30:35 (GMT)
commit06b57ef9586c8095b38b58dbf04fb8de94c08c16 (patch)
tree887fb8c34ad06cb315c16f7757d827ddda0ac93a /Lib/test/test_nntplib.py
parent2603d0a6575024f619df0f4a0e1bfbfc11c1c52f (diff)
parent71135624d81fac63a1684d5cf31932652f9250ff (diff)
downloadcpython-06b57ef9586c8095b38b58dbf04fb8de94c08c16.zip
cpython-06b57ef9586c8095b38b58dbf04fb8de94c08c16.tar.gz
cpython-06b57ef9586c8095b38b58dbf04fb8de94c08c16.tar.bz2
Issue #10287: nntplib now queries the server's CAPABILITIES first before sending MODE READER, and only sends it if not already in READER mode.
Patch by Hynek Schlawack.
Diffstat (limited to 'Lib/test/test_nntplib.py')
-rw-r--r--Lib/test/test_nntplib.py51
1 files changed, 50 insertions, 1 deletions
diff --git a/Lib/test/test_nntplib.py b/Lib/test/test_nntplib.py
index 9753251..bfc9f41 100644
--- a/Lib/test/test_nntplib.py
+++ b/Lib/test/test_nntplib.py
@@ -385,6 +385,12 @@ class MockedNNTPTestsMixin:
return self.server
+class MockedNNTPWithReaderModeMixin(MockedNNTPTestsMixin):
+ def setUp(self):
+ super().setUp()
+ self.make_server(readermode=True)
+
+
class NNTPv1Handler:
"""A handler for RFC 977"""
@@ -725,6 +731,9 @@ class NNTPv2Handler(NNTPv1Handler):
else:
self.push_lit(fmt.format(''))
+ def handle_MODE(self, _):
+ raise Exception('MODE READER sent despite READER has been advertised')
+
def handle_OVER(self, message_spec=None):
return self.handle_XOVER(message_spec)
@@ -739,6 +748,34 @@ class CapsAfterLoginNNTPv2Handler(NNTPv2Handler):
super().handle_CAPABILITIES()
+class ModeSwitchingNNTPv2Handler(NNTPv2Handler):
+ """A server that starts in transit mode"""
+
+ def __init__(self):
+ self._switched = False
+
+ def handle_CAPABILITIES(self):
+ fmt = """\
+ 101 Capability list:
+ VERSION 2 3
+ IMPLEMENTATION INN 2.5.1
+ HDR
+ LIST ACTIVE ACTIVE.TIMES DISTRIB.PATS HEADERS NEWSGROUPS OVERVIEW.FMT
+ OVER
+ POST
+ {}READER
+ ."""
+ if self._switched:
+ self.push_lit(fmt.format(''))
+ else:
+ self.push_lit(fmt.format('MODE-'))
+
+ def handle_MODE(self, what):
+ assert not self._switched and what == 'reader'
+ self._switched = True
+ self.push_lit('200 Posting allowed')
+
+
class NNTPv1v2TestsMixin:
def setUp(self):
@@ -1145,6 +1182,18 @@ class CapsAfterLoginNNTPv2Tests(MockedNNTPTestsMixin, unittest.TestCase):
self.assertIn('VERSION', self.server._caps)
+class SendReaderNNTPv2Tests(MockedNNTPWithReaderModeMixin,
+ unittest.TestCase):
+ """Same tests as for v2 but we tell NTTP to send MODE READER to a server
+ that isn't in READER mode by default."""
+
+ nntp_version = 2
+ handler_class = ModeSwitchingNNTPv2Handler
+
+ def test_we_are_in_reader_mode_after_connect(self):
+ self.assertIn('READER', self.server._caps)
+
+
class MiscTests(unittest.TestCase):
def test_decode_header(self):
@@ -1305,7 +1354,7 @@ class MiscTests(unittest.TestCase):
def test_main():
tests = [MiscTests, NNTPv1Tests, NNTPv2Tests, CapsAfterLoginNNTPv2Tests,
- NetworkedNNTPTests]
+ SendReaderNNTPv2Tests, NetworkedNNTPTests]
if _have_ssl:
tests.append(NetworkedNNTP_SSLTests)
support.run_unittest(*tests)