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) 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())) user = TEST_USER proto = getSMTPFactory({user: None}, {user: self.km}, {user: None}, encrypted_only=True) 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 rejected with appropriate message.') proto.setTimeout(None)
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) 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_and_store_local = Mock( return_value=fail(errors.KeyNotFound())) user = TEST_USER proto = getSMTPFactory({user: OutgoingMail(user, self.km)}, {user: None}) 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)
def init_outgoing_and_proto(_): self.outgoing_mail = OutgoingMail( self.fromAddr, self.km, opts.cert, opts.key, opts.hostname, opts.port) user = TEST_USER # TODO -- this shouldn't need SMTP to be tested!? or does it? self.proto = getSMTPFactory( {user: None}, {user: self.km}, {user: None}) self.dest = User(ADDRESS, 'gateway.leap.se', self.proto, ADDRESS_2)
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' ] user = TEST_USER proto = getSMTPFactory({user: None}, {user: self.km}, {user: None}) 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)