1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-22 17:02:17 -05:00

unit test for encrypted sending works again

This commit is contained in:
Tankred Hase 2013-08-27 19:04:26 +02:00
parent c41bc334b2
commit 8dbc5d87e4
2 changed files with 35 additions and 8 deletions

View File

@ -105,7 +105,8 @@ define(function(require) {
* Send an email client side via STMP.
*/
EmailDAO.prototype.smtpSend = function(email, callback) {
var self = this;
var self = this,
invalidRecipient;
// validate the email input
if (!email.to || !email.from || !email.to[0].address || !email.from[0].address) {
@ -116,7 +117,6 @@ define(function(require) {
}
// validate email addresses
var invalidRecipient;
_.each(email.to, function(i) {
if (!validateEmail(i.address)) {
invalidRecipient = i.address;
@ -139,10 +139,8 @@ define(function(require) {
email.id = util.UUID();
// only support single recipient for e-2-e encryption
var recipient = email.to[0].address;
// check if receiver has a public key
self._keychain.getReveiverPublicKey(recipient, function(err, receiverPubkey) {
self._keychain.getReveiverPublicKey(email.to[0].address, function(err, receiverPubkey) {
if (err) {
callback(err);
return;
@ -169,10 +167,10 @@ define(function(require) {
from = email.from[0].name || email.from[0].address;
var NEW_SUBJECT = '[whiteout] Encrypted message';
var MESSAGE = 'Hi ' + to + ',\n\nthis is a private conversation just between the two of us. To read the encrypted message below, simply install Whiteout Mail for Chrome and encrypt your emails instantly: https://chrome.google.com/webstore/detail/whiteout-mail/jjgghafhamholjigjoghcfcekhkonijg\n\n\n';
var MESSAGE = 'Hi ' + to + ',\n\nthis is a private conversation just between the two of us. To read the encrypted message below, simply install Whiteout Mail for Chrome and encrypt your emails without any hassle: https://chrome.google.com/webstore/detail/whiteout-mail/jjgghafhamholjigjoghcfcekhkonijg\n\n\n';
var PREFIX = '-----BEGIN ENCRYPTED MESSAGE-----\n';
var SUFFIX = '\n-----END ENCRYPTED MESSAGE-----';
var SIGNATURE = '\n\n\nSent with whiteout mail, for easy end-to-end encrypted messaging\nhttp://whiteout.io\n\n';
var SIGNATURE = '\n\n\nSent from whiteout mail, for easy end-to-end encrypted messaging\nhttp://whiteout.io\n\n';
// encrypt the email
crypto.encryptListForUser(ptItems, receiverPubkeys, function(err, encryptedList) {

View File

@ -109,17 +109,46 @@ define(function(require) {
});
describe('SMTP: send email', function() {
it('should fail due to back input', function(done) {
it('should fail due to bad input', function(done) {
emailDao.smtpSend({}, function(err) {
expect(smtpClientStub.send.called).to.be.false;
expect(keychainStub.getReveiverPublicKey.called).to.be.false;
expect(err).to.exist;
done();
});
});
it('should fail due to invalid email address input', function(done) {
var badMail = {
from: [{
name: 'Whiteout Test',
address: 'whiteout.test@t-online.de'
}], // sender address
to: [{
address: 'asfd'
}], // list of receivers
subject: "Hello", // Subject line
body: "Hello world" // plaintext body
};
emailDao.smtpSend(badMail, function(err) {
expect(smtpClientStub.send.called).to.be.false;
expect(keychainStub.getReveiverPublicKey.called).to.be.false;
expect(err).to.exist;
done();
});
});
it('should work', function(done) {
var publicKey = "-----BEGIN PUBLIC KEY-----\r\n" + "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCxy+Te5dyeWd7g0P+8LNO7fZDQ\r\n" + "g96xTb1J6pYE/pPTMlqhB6BRItIYjZ1US5q2vk5Zk/5KasBHAc9RbCqvh9v4XFEY\r\n" + "JVmTXC4p8ft1LYuNWIaDk+R3dyYXmRNct/JC4tks2+8fD3aOvpt0WNn3R75/FGBt\r\n" + "h4BgojAXDE+PRQtcVQIDAQAB\r\n" + "-----END PUBLIC KEY-----";
keychainStub.getReveiverPublicKey.yields(null, {
_id: "fcf8b4aa-5d09-4089-8b4f-e3bc5091daf3",
userId: "safewithme.testuser@gmail.com",
publicKey: publicKey
});
smtpClientStub.send.yields();
emailDao.smtpSend(dummyMail, function(err) {
expect(keychainStub.getReveiverPublicKey.calledOnce).to.be.true;
expect(smtpClientStub.send.calledOnce).to.be.true;
expect(err).to.not.exist;
done();