Beispiel #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['encrypted_only'],
            outgoing_mail=Mock()).buildProtocol(('127.0.0.1', 0))
        # snip...
        transport = proto_helpers.StringTransport()
        proto.makeConnection(transport)
        reply = ""
        for i, line in enumerate(self.EMAIL_DATA):
            reply += yield self.getReply(line + '\r\n', proto, transport)
        self.assertMatch(reply, '\r\n'.join(SMTP_ANSWERS),
                         'Did not get expected answer from gateway.')
        proto.setTimeout(None)
Beispiel #2
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 = yield self._km.get_key(ADDRESS, openpgp.OpenPGPKey)
     pgp = openpgp.OpenPGPScheme(
         self._soledad, gpgbinary=self.GPG_BINARY_PATH)
     yield pgp.delete_key(pubkey)
     # mock the key fetching
     self._km._fetch_keys_from_server = Mock(
         return_value=fail(errors.KeyNotFound()))
     # prepare the SMTP factory with encrypted only equal to false
     proto = SMTPFactory(
         u'*****@*****.**',
         self._km,
         False, outgoing_mail=Mock()).buildProtocol(('127.0.0.1', 0))
     transport = proto_helpers.StringTransport()
     proto.makeConnection(transport)
     yield self.getReply(self.EMAIL_DATA[0] + '\r\n', proto, transport)
     yield self.getReply(self.EMAIL_DATA[1] + '\r\n', proto, transport)
     reply = yield self.getReply(self.EMAIL_DATA[2] + '\r\n',
                                 proto, transport)
     # ensure the address was accepted
     self.assertEqual(
         '250 Recipient address accepted\r\n',
         reply,
         'Address should have been accepted with appropriate message.')
     proto.setTimeout(None)
Beispiel #3
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)
Beispiel #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.')
 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.')
Beispiel #6
0
 def test_missing_key_rejects_address(self):
     """
     Test if server rejects to send unencrypted when 'encrypted_only' is
     True.
     """
     # remove key from key manager
     pubkey = yield self._km.get_key(ADDRESS, openpgp.OpenPGPKey)
     pgp = openpgp.OpenPGPScheme(self._soledad,
                                 gpgbinary=self.GPG_BINARY_PATH)
     yield pgp.delete_key(pubkey)
     # mock the key fetching
     self._km._fetch_keys_from_server = Mock(
         return_value=fail(errors.KeyNotFound()))
     # prepare the SMTP factory
     proto = SMTPFactory(u'*****@*****.**',
                         self._km,
                         self._config['encrypted_only'],
                         outgoing_mail=Mock()).buildProtocol(
                             ('127.0.0.1', 0))
     transport = proto_helpers.StringTransport()
     proto.makeConnection(transport)
     yield self.getReply(self.EMAIL_DATA[0] + '\r\n', proto, transport)
     yield self.getReply(self.EMAIL_DATA[1] + '\r\n', proto, transport)
     reply = yield self.getReply(self.EMAIL_DATA[2] + '\r\n', proto,
                                 transport)
     # ensure the address was rejected
     self.assertEqual(
         '550 Cannot receive for specified address\r\n', reply,
         'Address should have been rejecetd with appropriate message.')
     proto.setTimeout(None)