]> granicus.if.org Git - python/commitdiff
Merge #22215: have the smtplib 'quit' command reset the state.
authorR David Murray <rdmurray@bitdance.com>
Sat, 30 Aug 2014 20:55:45 +0000 (16:55 -0400)
committerR David Murray <rdmurray@bitdance.com>
Sat, 30 Aug 2014 20:55:45 +0000 (16:55 -0400)
1  2 
Lib/smtplib.py
Lib/test/test_smtplib.py
Misc/NEWS

diff --cc Lib/smtplib.py
Simple merge
index 816ed83d2773721c9818b2ec0fe032049725c666,95a9dbe91225e05df364114f05b4fb686554850e..5f12d28eeafe21cc147816c2007689ab645fe0e5
@@@ -857,25 -855,24 +857,40 @@@ class SMTPSimTests(unittest.TestCase)
          smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
          try: smtp.login(sim_auth[0], sim_auth[1])
          except smtplib.SMTPAuthenticationError as err:
 -            self.assertIn(sim_auth_login_password, str(err))
 +            self.assertIn(sim_auth_login_user, str(err))
 +        smtp.close()
 +
 +    def test_auth_function(self):
 +        smtp = smtplib.SMTP(HOST, self.port,
 +                            local_hostname='localhost', timeout=15)
 +        self.serv.add_feature("AUTH CRAM-MD5")
 +        smtp.user, smtp.password = sim_auth[0], sim_auth[1]
 +        supported = {'CRAM-MD5': smtp.auth_cram_md5,
 +                     'PLAIN': smtp.auth_plain,
 +                     'LOGIN': smtp.auth_login,
 +                    }
 +        for mechanism, method in supported.items():
 +            try: smtp.auth(mechanism, method)
 +            except smtplib.SMTPAuthenticationError as err:
 +                self.assertIn(sim_auth_credentials[mechanism.lower()].upper(),
 +                              str(err))
          smtp.close()
  
+     def test_quit_resets_greeting(self):
+         smtp = smtplib.SMTP(HOST, self.port,
+                             local_hostname='localhost',
+                             timeout=15)
+         code, message = smtp.ehlo()
+         self.assertEqual(code, 250)
+         self.assertIn('size', smtp.esmtp_features)
+         smtp.quit()
+         self.assertNotIn('size', smtp.esmtp_features)
+         smtp.connect(HOST, self.port)
+         self.assertNotIn('size', smtp.esmtp_features)
+         smtp.ehlo_or_helo_if_needed()
+         self.assertIn('size', smtp.esmtp_features)
+         smtp.quit()
      def test_with_statement(self):
          with smtplib.SMTP(HOST, self.port) as smtp:
              code, message = smtp.noop()
diff --cc Misc/NEWS
index 9a27b5ddd1fc30a28828b00fc84f8780b08a205d,5111b8aa16004bd388f369cd74648ada535b7b1c..d0e3d7293a30bb9ae397c6e756fc409ec43d912d
+++ b/Misc/NEWS
@@@ -124,10 -27,10 +124,14 @@@ Core and Builtin
  Library
  -------
  
+ - Issue #22216: smtplib now resets its state more completely after a quit.  The
+   most obvious consequence of the previous behavior was a STARTTLS failure
+   during a connect/starttls/quit/connect/starttls sequence.
 +- Issue #22098: ctypes' BigEndianStructure and LittleEndianStructure now
 +  define an empty __slots__ so that subclasses don't always get an instance
 +  dict.  Patch by Claudiu Popa.
 +
  - Issue #22185: Fix an occasional RuntimeError in threading.Condition.wait()
    caused by mutation of the waiters queue without holding the lock.  Patch
    by Doug Zongker.