예제 #1
0
 def _endpointTest(self, service):
     """
     Use L{Options} to parse a single service configuration parameter and
     verify that an endpoint of the correct type is added to the list for
     that service.
     """
     options = Options()
     options.parseOptions(['--' + service, 'tcp:1234'])
     self.assertEqual(len(options[service]), 1)
     self.assertIsInstance(options[service][0],
                           endpoints.TCP4ServerEndpoint)
예제 #2
0
 def _endpointTest(self, service):
     """
     Use L{Options} to parse a single service configuration parameter and
     verify that an endpoint of the correct type is added to the list for
     that service.
     """
     options = Options()
     options.parseOptions(['--' + service, 'tcp:1234'])
     self.assertEqual(len(options[service]), 1)
     self.assertIsInstance(
         options[service][0], endpoints.TCP4ServerEndpoint)
예제 #3
0
 def testPasswordfileDeprecation(self):
     """
     Test that the --passwordfile option will emit a correct warning.
     """
     options = Options()
     options.opt_passwordfile('/dev/null')
     warnings = self.flushWarnings([self.testPasswordfileDeprecation])
     self.assertEquals(warnings[0]['category'], DeprecationWarning)
     self.assertEquals(len(warnings), 1)
     msg = deprecate.getDeprecationWarningString(options.opt_passwordfile,
                          versions.Version('twisted.mail', 11, 0, 0))
     self.assertEquals(warnings[0]['message'], msg)
예제 #4
0
    def test_protoDefaults(self):
        """
        POP3 and SMTP each listen on a TCP4ServerEndpoint by default.
        """
        options = Options()
        options.parseOptions([])

        self.assertEqual(len(options['pop3']), 1)
        self.assertIsInstance(options['pop3'][0], endpoints.TCP4ServerEndpoint)

        self.assertEqual(len(options['smtp']), 1)
        self.assertIsInstance(options['smtp'][0], endpoints.TCP4ServerEndpoint)
예제 #5
0
 def test_auth(self):
     """
     Tests that the --auth option registers a checker.
     """
     options = Options()
     options.parseOptions(['--auth', 'memory:admin:admin:bob:password'])
     self.assertEqual(len(options['credCheckers']), 1)
     checker = options['credCheckers'][0]
     interfaces = checker.credentialInterfaces
     registered_checkers = options.service.smtpPortal.checkers
     for iface in interfaces:
         self.assertEqual(checker, registered_checkers[iface])
예제 #6
0
 def test_auth(self):
     """
     Tests that the --auth option registers a checker.
     """
     options = Options()
     options.parseOptions(['--auth', 'memory:admin:admin:bob:password'])
     self.assertEqual(len(options['credCheckers']), 1)
     checker = options['credCheckers'][0]
     interfaces = checker.credentialInterfaces
     registered_checkers = options.service.smtpPortal.checkers
     for iface in interfaces:
         self.assertEqual(checker, registered_checkers[iface])
예제 #7
0
    def test_protoDisable(self):
        """
        The I{--no-pop3} and I{--no-smtp} options disable POP3 and SMTP
        respectively.
        """
        options = Options()
        options.parseOptions(['--no-pop3'])
        self.assertEqual(options._getEndpoints(None, 'pop3'), [])
        self.assertNotEquals(options._getEndpoints(None, 'smtp'), [])

        options = Options()
        options.parseOptions(['--no-smtp'])
        self.assertNotEquals(options._getEndpoints(None, 'pop3'), [])
        self.assertEqual(options._getEndpoints(None, 'smtp'), [])
예제 #8
0
    def test_protoDefaults(self):
        """
        POP3 and SMTP each listen on a TCP4ServerEndpoint by default.
        """
        options = Options()
        options.parseOptions([])

        self.assertEqual(len(options['pop3']), 1)
        self.assertIsInstance(
            options['pop3'][0], endpoints.TCP4ServerEndpoint)

        self.assertEqual(len(options['smtp']), 1)
        self.assertIsInstance(
            options['smtp'][0], endpoints.TCP4ServerEndpoint)
예제 #9
0
 def testPasswordfileDeprecation(self):
     """
     Test that the --passwordfile option will emit a correct warning.
     """
     passwd = FilePath(self.mktemp())
     passwd.setContent("")
     options = Options()
     options.opt_passwordfile(passwd.path)
     warnings = self.flushWarnings([self.testPasswordfileDeprecation])
     self.assertEqual(warnings[0]['category'], DeprecationWarning)
     self.assertEqual(len(warnings), 1)
     msg = deprecate.getDeprecationWarningString(options.opt_passwordfile,
                          versions.Version('twisted.mail', 11, 0, 0))
     self.assertEqual(warnings[0]['message'], msg)
예제 #10
0
 def testPasswordfileDeprecation(self):
     """
     Test that the --passwordfile option will emit a correct warning.
     """
     passwd = FilePath(self.mktemp())
     passwd.setContent("")
     options = Options()
     options.opt_passwordfile(passwd.path)
     warnings = self.flushWarnings([self.testPasswordfileDeprecation])
     self.assertEqual(warnings[0]['category'], DeprecationWarning)
     self.assertEqual(len(warnings), 1)
     msg = deprecate.getDeprecationWarningString(options.opt_passwordfile,
                          versions.Version('twisted.mail', 11, 0, 0))
     self.assertEqual(warnings[0]['message'], msg)
예제 #11
0
 def test_barePort(self):
     """
     A bare port passed to I{--pop3} results in deprecation warning in
     addition to a TCP4ServerEndpoint.
     """
     options = Options()
     options.parseOptions(['--pop3', '8110'])
     self.assertEqual(len(options['pop3']), 1)
     self.assertIsInstance(options['pop3'][0], endpoints.TCP4ServerEndpoint)
     warnings = self.flushWarnings([options.opt_pop3])
     self.assertEqual(len(warnings), 1)
     self.assertEqual(warnings[0]['category'], DeprecationWarning)
     self.assertEqual(
         warnings[0]['message'],
         "Specifying plain ports and/or a certificate is deprecated since "
         "Twisted 11.0; use endpoint descriptions instead.")
예제 #12
0
 def test_allProtosDisabledError(self):
     """
     If all protocols are disabled, L{UsageError} is raised.
     """
     options = Options()
     self.assertRaises(UsageError, options.parseOptions,
                       (['--no-pop3', '--no-smtp']))
예제 #13
0
 def testAliases(self):
     """
     Test that adding an aliases(5) file to an IAliasableDomain at least
     doesn't raise an unhandled exception.
     """
     Options().parseOptions([
         '--maildirdbmdomain', 'example.com=example.com',
         '--aliases', self.aliasFilename])
예제 #14
0
 def test_esmtpWithoutHostname(self):
     """
     If I{--esmtp} is given without I{--hostname}, L{Options.parseOptions}
     raises L{UsageError}.
     """
     options = Options()
     exc = self.assertRaises(UsageError, options.parseOptions, ['--esmtp'])
     self.assertEqual("--esmtp requires --hostname", str(exc))
예제 #15
0
 def test_barePort(self):
     """
     A bare port passed to I{--pop3} results in deprecation warning in
     addition to a TCP4ServerEndpoint.
     """
     options = Options()
     options.parseOptions(['--pop3', '8110'])
     self.assertEqual(len(options['pop3']), 1)
     self.assertIsInstance(
         options['pop3'][0], endpoints.TCP4ServerEndpoint)
     warnings = self.flushWarnings([options.opt_pop3])
     self.assertEqual(len(warnings), 1)
     self.assertEqual(warnings[0]['category'], DeprecationWarning)
     self.assertEqual(
         warnings[0]['message'],
         "Specifying plain ports and/or a certificate is deprecated since "
         "Twisted 11.0; use endpoint descriptions instead.")
예제 #16
0
 def testAliasesWithoutDomain(self):
     """
     Test that adding an aliases(5) file before adding a domain raises a
     UsageError.
     """
     self.assertRaises(UsageError,
                       Options().parseOptions,
                       ['--aliases', self.aliasFilename])
예제 #17
0
    def test_pop3sBackwardCompatibility(self):
        """
        The deprecated I{--pop3s} and I{--certificate} options set up a POP3 SSL
        server.
        """
        cert = FilePath(__file__).sibling("server.pem")
        options = Options()
        options.parseOptions(['--pop3s', '8995', '--certificate', cert.path])
        self.assertEqual(len(options['pop3']), 2)
        self.assertIsInstance(options['pop3'][0], endpoints.SSL4ServerEndpoint)
        self.assertIsInstance(options['pop3'][1], endpoints.TCP4ServerEndpoint)

        warnings = self.flushWarnings([options.postOptions])
        self.assertEqual(len(warnings), 1)
        self.assertEqual(warnings[0]['category'], DeprecationWarning)
        self.assertEqual(
            warnings[0]['message'],
            "Specifying plain ports and/or a certificate is deprecated since "
            "Twisted 11.0; use endpoint descriptions instead.")
예제 #18
0
    def test_pop3sBackwardCompatibility(self):
        """
        The deprecated I{--pop3s} and I{--certificate} options set up a POP3 SSL
        server.
        """
        cert = FilePath(__file__).sibling("server.pem")
        options = Options()
        options.parseOptions(['--pop3s', '8995',
                              '--certificate', cert.path])
        self.assertEqual(len(options['pop3']), 2)
        self.assertIsInstance(
            options['pop3'][0], endpoints.SSL4ServerEndpoint)
        self.assertIsInstance(
            options['pop3'][1], endpoints.TCP4ServerEndpoint)

        warnings = self.flushWarnings([options.postOptions])
        self.assertEqual(len(warnings), 1)
        self.assertEqual(warnings[0]['category'], DeprecationWarning)
        self.assertEqual(
            warnings[0]['message'],
            "Specifying plain ports and/or a certificate is deprecated since "
            "Twisted 11.0; use endpoint descriptions instead.")
예제 #19
0
 def _endpointServerTest(self, key, factoryClass):
     """
     Configure a service with two endpoints for the protocol associated with
     C{key} and verify that when the service is started a factory of type
     C{factoryClass} is used to listen on each of them.
     """
     cleartext = SpyEndpoint()
     secure = SpyEndpoint()
     config = Options()
     config[key] = [cleartext, secure]
     service = makeService(config)
     service.privilegedStartService()
     service.startService()
     self.addCleanup(service.stopService)
     self.assertIsInstance(cleartext.listeningWith, factoryClass)
     self.assertIsInstance(secure.listeningWith, factoryClass)
예제 #20
0
    def test_protoDisable(self):
        """
        The I{--no-pop3} and I{--no-smtp} options disable POP3 and SMTP
        respectively.
        """
        options = Options()
        options.parseOptions(['--no-pop3'])
        self.assertEqual(options._getEndpoints(None, 'pop3'), [])
        self.assertNotEquals(options._getEndpoints(None, 'smtp'), [])

        options = Options()
        options.parseOptions(['--no-smtp'])
        self.assertNotEquals(options._getEndpoints(None, 'pop3'), [])
        self.assertEqual(options._getEndpoints(None, 'smtp'), [])