Ticket #4963: 4963.2.patch

File 4963.2.patch, 6.2 KB (added by moijes12, 4 years ago)

The tests for pop3sBackwardCompatibilty now use DefaultOpenSSLContextFactory. For this, a copy of server.pem has been placed in twisted/mail/test. All other changes that were supplied in the first patch are in here too. So, now, SSLContextFactory has been deprecated and its usage has been replaced with DefaultOpenSSLContextFactory.

  • twisted/mail/test/test_options.py

     
    1212from twisted.mail.tap import Options, makeService
    1313from twisted.python.filepath import FilePath
    1414from twisted.internet import endpoints, defer
     15from twisted.python import util
    1516
    1617
    1718class OptionsTestCase(TestCase):
     
    140141        The deprecated I{--pop3s} and I{--certificate} options set up a POP3 SSL
    141142        server.
    142143        """
     144        certPath = util.sibpath(__file__, "server.pem")
    143145        cert = FilePath(self.mktemp())
    144         cert.setContent("")
     146        cert.setContent(file(certPath).read())
    145147        options = Options()
    146148        options.parseOptions(['--pop3s', '8995',
    147149                              '--certificate', cert.path])
  • twisted/mail/test/server.pem

     
     1-----BEGIN CERTIFICATE-----
     2MIIDBjCCAm+gAwIBAgIBATANBgkqhkiG9w0BAQQFADB7MQswCQYDVQQGEwJTRzER
     3MA8GA1UEChMITTJDcnlwdG8xFDASBgNVBAsTC00yQ3J5cHRvIENBMSQwIgYDVQQD
     4ExtNMkNyeXB0byBDZXJ0aWZpY2F0ZSBNYXN0ZXIxHTAbBgkqhkiG9w0BCQEWDm5n
     5cHNAcG9zdDEuY29tMB4XDTAwMDkxMDA5NTEzMFoXDTAyMDkxMDA5NTEzMFowUzEL
     6MAkGA1UEBhMCU0cxETAPBgNVBAoTCE0yQ3J5cHRvMRIwEAYDVQQDEwlsb2NhbGhv
     7c3QxHTAbBgkqhkiG9w0BCQEWDm5ncHNAcG9zdDEuY29tMFwwDQYJKoZIhvcNAQEB
     8BQADSwAwSAJBAKy+e3dulvXzV7zoTZWc5TzgApr8DmeQHTYC8ydfzH7EECe4R1Xh
     95kwIzOuuFfn178FBiS84gngaNcrFi0Z5fAkCAwEAAaOCAQQwggEAMAkGA1UdEwQC
     10MAAwLAYJYIZIAYb4QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVkIENlcnRpZmljYXRl
     11MB0GA1UdDgQWBBTPhIKSvnsmYsBVNWjj0m3M2z0qVTCBpQYDVR0jBIGdMIGagBT7
     12hyNp65w6kxXlxb8pUU/+7Sg4AaF/pH0wezELMAkGA1UEBhMCU0cxETAPBgNVBAoT
     13CE0yQ3J5cHRvMRQwEgYDVQQLEwtNMkNyeXB0byBDQTEkMCIGA1UEAxMbTTJDcnlw
     14dG8gQ2VydGlmaWNhdGUgTWFzdGVyMR0wGwYJKoZIhvcNAQkBFg5uZ3BzQHBvc3Qx
     15LmNvbYIBADANBgkqhkiG9w0BAQQFAAOBgQA7/CqT6PoHycTdhEStWNZde7M/2Yc6
     16BoJuVwnW8YxGO8Sn6UJ4FeffZNcYZddSDKosw8LtPOeWoK3JINjAk5jiPQ2cww++
     177QGG/g5NDjxFZNDJP1dGiLAxPW6JXwov4v0FmdzfLOZ01jDcgQQZqEpYlgpuI5JE
     18WUQ9Ho4EzbYCOQ==
     19-----END CERTIFICATE-----
     20-----BEGIN RSA PRIVATE KEY-----
     21MIIBPAIBAAJBAKy+e3dulvXzV7zoTZWc5TzgApr8DmeQHTYC8ydfzH7EECe4R1Xh
     225kwIzOuuFfn178FBiS84gngaNcrFi0Z5fAkCAwEAAQJBAIqm/bz4NA1H++Vx5Ewx
     23OcKp3w19QSaZAwlGRtsUxrP7436QjnREM3Bm8ygU11BjkPVmtrKm6AayQfCHqJoT
     24ZIECIQDW0BoMoL0HOYM/mrTLhaykYAVqgIeJsPjvkEhTFXWBuQIhAM3deFAvWNu4
     25nklUQ37XsCT2c9tmNt1LAT+slG2JOTTRAiAuXDtC/m3NYVwyHfFm+zKHRzHkClk2
     26HjubeEgjpj32AQIhAJqMGTaZVOwevTXvvHwNEH+vRWsAYU/gbx+OQB+7VOcBAiEA
     27oolb6NMg/R3enNPvS1O4UU1H8wpaF77L4yiSWlE0p4w=
     28-----END RSA PRIVATE KEY-----
     29-----BEGIN CERTIFICATE REQUEST-----
     30MIIBDTCBuAIBADBTMQswCQYDVQQGEwJTRzERMA8GA1UEChMITTJDcnlwdG8xEjAQ
     31BgNVBAMTCWxvY2FsaG9zdDEdMBsGCSqGSIb3DQEJARYObmdwc0Bwb3N0MS5jb20w
     32XDANBgkqhkiG9w0BAQEFAANLADBIAkEArL57d26W9fNXvOhNlZzlPOACmvwOZ5Ad
     33NgLzJ1/MfsQQJ7hHVeHmTAjM664V+fXvwUGJLziCeBo1ysWLRnl8CQIDAQABoAAw
     34DQYJKoZIhvcNAQEEBQADQQA7uqbrNTjVWpF6By5ZNPvhZ4YdFgkeXFVWi5ao/TaP
     35Vq4BG021fJ9nlHRtr4rotpgHDX1rr+iWeHKsx4+5DRSy
     36-----END CERTIFICATE REQUEST-----
  • twisted/mail/test/test_mail.py

     
    20312031            raise smtp.SMTPBadRcpt(user)
    20322032
    20332033
     2034
     2035class SSLContextFactoryTests(unittest.TestCase):
     2036    """
     2037    Tests for twisted.mail.protocols.SSLContextFactory.
     2038    """
     2039
     2040
     2041    def test_deprecation(self):
     2042        """
     2043        Test deprecation of twisted.mail.protocols.SSLContextFactory.
     2044        """
     2045        mail.protocols.SSLContextFactory('')
     2046        warningsShown = self.flushWarnings([self.test_deprecation])
     2047        self.assertEqual(len(warningsShown), 1)
     2048        self.assertIdentical(warningsShown[0]['category'], DeprecationWarning)
     2049        self.assertEqual(warningsShown[0]['message'], 'twisted.mail.protocols.SSLContextFactory was deprecated in Twisted 12.2.0: Use twisted.internet.ssl.DefaultOpenSSLContextFactory instead.')
     2050
     2051
     2052
    20342053from twisted.python.runtime import platformType
    20352054import types
    20362055if platformType != "posix":
  • twisted/mail/topfiles/4963.removal

     
     1twisted.mail.protocols.SSLContextFactory is now deprecated.
     2 No newline at end of file
  • twisted/mail/tap.py

     
    1616from twisted.mail import relaymanager
    1717from twisted.mail import alias
    1818
    19 from twisted.mail.protocols import SSLContextFactory
     19from twisted.internet.ssl import DefaultOpenSSLContextFactory
    2020
    2121from twisted.internet import endpoints
    2222
     
    271271        category=DeprecationWarning, stacklevel=3)
    272272
    273273    if certificate:
    274         ctx = SSLContextFactory(certificate)
     274        ctx = DefaultOpenSSLContextFactory(certificate, certificate)
    275275        return endpoints.SSL4ServerEndpoint(reactor, port, ctx)
    276276    return endpoints.TCP4ServerEndpoint(reactor, port)
    277277
  • twisted/mail/protocols.py

     
    1212from twisted.internet import defer
    1313from twisted.copyright import longversion
    1414from twisted.python import log
     15from twisted.python.deprecate import deprecatedModuleAttribute
     16from twisted.python.versions import Version
    1517
    1618from twisted import cred
    1719import twisted.cred.error
     
    209211# can be changed, of course.
    210212#
    211213class SSLContextFactory:
    212     """An SSL Context Factory
    213    
     214    """
     215    An SSL Context Factory.   
    214216    This loads a certificate and private key from a specified file.
    215217    """
     218
     219    deprecatedModuleAttribute(Version("Twisted", 12, 2, 0), "Use twisted.internet.ssl.DefaultOpenSSLContextFactory instead.", "twisted.mail.protocols", "SSLContextFactory")
     220
     221
    216222    def __init__(self, filename):
    217223        self.filename = filename
    218224