コード例 #1
0
    def test_gateway_accepts_valid_email(self):
        """
        Test if SMTP server responds correctly for valid interaction.
        """

        SMTP_ANSWERS = [
            '220 ' + IP_OR_HOST_REGEX + ' NO UCE NO UBE NO RELAY PROBES',
            '250 ' + IP_OR_HOST_REGEX + ' Hello ' + IP_OR_HOST_REGEX +
            ', nice to meet you', '250 Sender address accepted',
            '250 Recipient address accepted', '354 Continue'
        ]

        # XXX this bit can be refactored away in a helper
        # method...
        proto = SMTPFactory(u'*****@*****.**', self._km,
                            self._config['host'], self._config['port'],
                            self._config['cert'], self._config['key'],
                            self._config['encrypted_only']).buildProtocol(
                                ('127.0.0.1', 0))
        # snip...
        transport = proto_helpers.StringTransport()
        proto.makeConnection(transport)
        for i, line in enumerate(self.EMAIL_DATA):
            proto.lineReceived(line + '\r\n')
            self.assertMatch(transport.value(),
                             '\r\n'.join(SMTP_ANSWERS[0:i + 1]),
                             'Did not get expected answer from gateway.')
        proto.setTimeout(None)
コード例 #2
0
    def test_gateway_accepts_valid_email(self):
        """
        Test if SMTP server responds correctly for valid interaction.
        """

        SMTP_ANSWERS = ['220 ' + IP_OR_HOST_REGEX +
                        ' NO UCE NO UBE NO RELAY PROBES',
                        '250 ' + IP_OR_HOST_REGEX + ' Hello ' +
                        IP_OR_HOST_REGEX + ', nice to meet you',
                        '250 Sender address accepted',
                        '250 Recipient address accepted',
                        '354 Continue']

        # XXX this bit can be refactored away in a helper
        # method...
        proto = SMTPFactory(
            u'*****@*****.**',
            self._km, self._config['host'],
            self._config['port'],
            self._config['cert'], self._config['key'],
            self._config['encrypted_only']).buildProtocol(('127.0.0.1', 0))
        # snip...
        transport = proto_helpers.StringTransport()
        proto.makeConnection(transport)
        for i, line in enumerate(self.EMAIL_DATA):
            proto.lineReceived(line + '\r\n')
            self.assertMatch(transport.value(),
                             '\r\n'.join(SMTP_ANSWERS[0:i + 1]),
                             'Did not get expected answer from gateway.')
        proto.setTimeout(None)
コード例 #3
0
 def test_missing_key_accepts_address(self):
     """
     Test if server accepts to send unencrypted when 'encrypted_only' is
     False.
     """
     # remove key from key manager
     pubkey = self._km.get_key(ADDRESS, openpgp.OpenPGPKey)
     pgp = openpgp.OpenPGPScheme(self._soledad,
                                 gpgbinary=self.GPG_BINARY_PATH)
     pgp.delete_key(pubkey)
     # mock the key fetching
     self._km.fetch_keys_from_server = Mock(return_value=[])
     # prepare the SMTP factory with encrypted only equal to false
     proto = SMTPFactory(u'*****@*****.**', self._km,
                         self._config['host'], self._config['port'],
                         self._config['cert'], self._config['key'],
                         False).buildProtocol(('127.0.0.1', 0))
     transport = proto_helpers.StringTransport()
     proto.makeConnection(transport)
     proto.lineReceived(self.EMAIL_DATA[0] + '\r\n')
     proto.lineReceived(self.EMAIL_DATA[1] + '\r\n')
     proto.lineReceived(self.EMAIL_DATA[2] + '\r\n')
     # ensure the address was accepted
     lines = transport.value().rstrip().split('\n')
     self.assertEqual(
         '250 Recipient address accepted', lines[-1],
         'Address should have been accepted with appropriate message.')
コード例 #4
0
 def test_missing_key_accepts_address(self):
     """
     Test if server accepts to send unencrypted when 'encrypted_only' is
     False.
     """
     # remove key from key manager
     pubkey = self._km.get_key(ADDRESS, openpgp.OpenPGPKey)
     pgp = openpgp.OpenPGPScheme(
         self._soledad, gpgbinary=self.GPG_BINARY_PATH)
     pgp.delete_key(pubkey)
     # mock the key fetching
     self._km.fetch_keys_from_server = Mock(return_value=[])
     # prepare the SMTP factory with encrypted only equal to false
     proto = SMTPFactory(
         u'*****@*****.**',
         self._km, self._config['host'],
         self._config['port'],
         self._config['cert'], self._config['key'],
         False).buildProtocol(('127.0.0.1', 0))
     transport = proto_helpers.StringTransport()
     proto.makeConnection(transport)
     proto.lineReceived(self.EMAIL_DATA[0] + '\r\n')
     proto.lineReceived(self.EMAIL_DATA[1] + '\r\n')
     proto.lineReceived(self.EMAIL_DATA[2] + '\r\n')
     # ensure the address was accepted
     lines = transport.value().rstrip().split('\n')
     self.assertEqual(
         '250 Recipient address accepted',
         lines[-1],
         'Address should have been accepted with appropriate message.')