Test lawnchair dao

Test pgp promise api
This commit is contained in:
Tankred Hase 2014-12-10 14:16:53 +01:00
parent 502c6b7467
commit 7aa0d2cf4a
6 changed files with 182 additions and 202 deletions

View File

@ -43,7 +43,8 @@
"forge",
"Lawnchair",
"_",
"openpgp"
"openpgp",
"qMock"
],
"globals": {

View File

@ -19,25 +19,32 @@ function PGP($q) {
/**
* Generate a key pair for the user
* @return {Promise}
*/
PGP.prototype.generateKeys = function(options) {
var userId, passphrase;
return this._q(function(resolve) {
var userId, passphrase;
if (!util.emailRegEx.test(options.emailAddress) || !options.keySize) {
return this._q(function(resolve, reject) {
reject(new Error('Crypto init failed. Not all options set!'));
if (!util.emailRegEx.test(options.emailAddress) || !options.keySize) {
throw new Error('Crypto init failed. Not all options set!');
}
// generate keypair
userId = 'Whiteout User <' + options.emailAddress + '>';
passphrase = (options.passphrase) ? options.passphrase : undefined;
resolve({
userId: userId,
passphrase: passphrase
});
}
// generate keypair
userId = 'Whiteout User <' + options.emailAddress + '>';
passphrase = (options.passphrase) ? options.passphrase : undefined;
return openpgp.generateKeyPair({
keyType: 1, // (keytype 1=RSA)
numBits: options.keySize,
userId: userId,
passphrase: passphrase
}).then(function(res) {
return openpgp.generateKeyPair({
keyType: 1, // (keytype 1=RSA)
numBits: options.keySize,
userId: res.userId,
passphrase: res.passphrase
});
}).then(function(keys) {
return {
keyId: keys.key.primaryKey.getKeyId().toHex().toUpperCase(),
@ -145,16 +152,16 @@ PGP.prototype.extractPublicKey = function(privateKeyArmored) {
/**
* Import the user's key pair
* @return {Promise}
*/
PGP.prototype.importKeys = function(options) {
var self = this;
return self._q(function(resolve, reject) {
return self._q(function(resolve) {
var pubKeyId, privKeyId;
// check options
if (!options.privateKeyArmored || !options.publicKeyArmored) {
reject(new Error('Importing keys failed. Not all options set!'));
return;
throw new Error('Importing keys failed. Not all options set!');
}
function resetKeys() {
@ -168,15 +175,13 @@ PGP.prototype.importKeys = function(options) {
self._privateKey = openpgp.key.readArmored(options.privateKeyArmored).keys[0];
} catch (e) {
resetKeys();
reject(new Error('Importing keys failed. Parsing error!'));
return;
throw new Error('Importing keys failed. Parsing error!');
}
// decrypt private key with passphrase
if (!self._privateKey.decrypt(options.passphrase)) {
resetKeys();
reject(new Error('Incorrect passphrase!'));
return;
throw new Error('Incorrect passphrase!');
}
// check if keys have the same id
@ -184,8 +189,7 @@ PGP.prototype.importKeys = function(options) {
privKeyId = self._privateKey.primaryKey.getKeyId().toHex();
if (!pubKeyId || !privKeyId || pubKeyId !== privKeyId) {
resetKeys();
reject(new Error('Key IDs dont match!'));
return;
throw new Error('Key IDs dont match!');
}
resolve();
@ -194,13 +198,13 @@ PGP.prototype.importKeys = function(options) {
/**
* Export the user's key pair
* @return {Promise}
*/
PGP.prototype.exportKeys = function() {
var self = this;
return self._q(function(resolve, reject) {
return self._q(function(resolve) {
if (!self._publicKey || !self._privateKey) {
reject(new Error('Could not export keys!'));
return;
throw new Error('Could not export keys!');
}
resolve({
@ -213,37 +217,34 @@ PGP.prototype.exportKeys = function() {
/**
* Change the passphrase of an ascii armored private key.
* @return {Promise}
*/
PGP.prototype.changePassphrase = function(options) {
return this._q(function(resolve, reject) {
return this._q(function(resolve) {
var privKey, packets, newPassphrase, newKeyArmored;
// set undefined instead of empty string as passphrase
newPassphrase = (options.newPassphrase) ? options.newPassphrase : undefined;
if (!options.privateKeyArmored) {
reject(new Error('Private key must be specified to change passphrase!'));
return;
throw new Error('Private key must be specified to change passphrase!');
}
if (options.oldPassphrase === newPassphrase ||
(!options.oldPassphrase && !newPassphrase)) {
reject(new Error('New and old passphrase are the same!'));
return;
throw new Error('New and old passphrase are the same!');
}
// read armored key
try {
privKey = openpgp.key.readArmored(options.privateKeyArmored).keys[0];
} catch (e) {
reject(new Error('Importing key failed. Parsing error!'));
return;
throw new Error('Importing key failed. Parsing error!');
}
// decrypt private key with passphrase
if (!privKey.decrypt(options.oldPassphrase)) {
reject(new Error('Old passphrase incorrect!'));
return;
throw new Error('Old passphrase incorrect!');
}
// encrypt key with new passphrase
@ -254,14 +255,12 @@ PGP.prototype.changePassphrase = function(options) {
}
newKeyArmored = privKey.armor();
} catch (e) {
reject(new Error('Setting new passphrase failed!'));
return;
throw new Error('Setting new passphrase failed!');
}
// check if new passphrase really works
if (!privKey.decrypt(newPassphrase)) {
reject(new Error('Decrypting key with new passphrase failed!'));
return;
throw new Error('Decrypting key with new passphrase failed!');
}
resolve(newKeyArmored);
@ -270,16 +269,16 @@ PGP.prototype.changePassphrase = function(options) {
/**
* Encrypt and sign a pgp message for a list of receivers
* @return {Promise}
*/
PGP.prototype.encrypt = function(plaintext, publicKeysArmored) {
var self = this;
return self._q(function(resolve, reject) {
return self._q(function(resolve) {
var publicKeys;
// check keys
if (!self._privateKey) {
reject(new Error('Error encrypting. Keys must be set!'));
return;
throw new Error('Error encrypting. Keys must be set!');
}
// parse armored public keys
try {
@ -290,8 +289,7 @@ PGP.prototype.encrypt = function(plaintext, publicKeysArmored) {
});
}
} catch (err) {
reject(new Error('Error encrypting plaintext!'));
return;
throw new Error('Error encrypting plaintext!');
}
resolve(publicKeys);
@ -311,16 +309,16 @@ PGP.prototype.encrypt = function(plaintext, publicKeysArmored) {
* @param {String} ciphertext The encrypted PGP message block
* @param {String} publicKeyArmored The public key used to sign the message
* @param {Function} callback(error, plaintext, signaturesValid) signaturesValid is undefined in case there are no signature, null in case there are signatures but the wrong public key or no key was used to verify, true if the signature was successfully verified, or false if the signataure verification failed.
* @return {Promise}
*/
PGP.prototype.decrypt = function(ciphertext, publicKeyArmored) {
var self = this;
return self._q(function(resolve, reject) {
return self._q(function(resolve) {
var publicKeys, message;
// check keys
if (!self._privateKey) {
reject(new Error('Error decrypting. Keys must be set!'));
return;
throw new Error('Error decrypting. Keys must be set!');
}
// read keys and ciphertext message
try {
@ -333,14 +331,16 @@ PGP.prototype.decrypt = function(ciphertext, publicKeyArmored) {
}
message = openpgp.message.readArmored(ciphertext);
} catch (err) {
reject(new Error('Error parsing encrypted PGP message!'));
return;
throw new Error('Error parsing encrypted PGP message!');
}
resolve(publicKeys, message);
resolve({
publicKeys: publicKeys,
message: message
});
}).then(function(publicKeys, message) {
}).then(function(res) {
// decrypt and verify pgp message
return openpgp.decryptAndVerifyMessage(self._privateKey, publicKeys, message);
return openpgp.decryptAndVerifyMessage(self._privateKey, res.publicKeys, res.message);
}).then(function(decrypted) {
// return decrypted plaintext
return {
@ -355,16 +355,16 @@ PGP.prototype.decrypt = function(ciphertext, publicKeyArmored) {
* @param {String} clearSignedText The clearsigned text, usually from a signed pgp/inline message
* @param {String} publicKeyArmored The public key used to signed the message
* @param {Function} callback(error, signaturesValid) signaturesValid is undefined in case there are no signature, null in case there are signatures but the wrong public key or no key was used to verify, true if the signature was successfully verified, or false if the signataure verification failed.
* @return {Promise}
*/
PGP.prototype.verifyClearSignedMessage = function(clearSignedText, publicKeyArmored) {
var self = this;
return self._q(function(resolve, reject) {
return self._q(function(resolve) {
var publicKeys, message;
// check keys
if (!self._privateKey) {
reject(new Error('Error verifying signed PGP message. Keys must be set!'));
return;
throw new Error('Error verifying signed PGP message. Keys must be set!');
}
// read keys and ciphertext message
try {
@ -377,13 +377,15 @@ PGP.prototype.verifyClearSignedMessage = function(clearSignedText, publicKeyArmo
}
message = openpgp.cleartext.readArmored(clearSignedText);
} catch (err) {
reject(new Error('Error verifying signed PGP message!'));
return;
throw new Error('Error verifying signed PGP message!');
}
resolve(publicKeys, message);
resolve({
publicKeys: publicKeys,
message: message
});
}).then(function(publicKeys, message) {
return openpgp.verifyClearSignedMessage(publicKeys, message);
}).then(function(res) {
return openpgp.verifyClearSignedMessage(res.publicKeys, res.message);
}).then(function(result) {
return checkSignatureValidity(result.signatures);
});
@ -395,16 +397,16 @@ PGP.prototype.verifyClearSignedMessage = function(clearSignedText, publicKeyArmo
* @param {String} pgpSignature The detached signature, usually from a signed pgp/mime message
* @param {String} publicKeyArmored The public key used to signed the message
* @param {Function} callback(error, signaturesValid) signaturesValid is undefined in case there are no signature, null in case there are signatures but the wrong public key or no key was used to verify, true if the signature was successfully verified, or false if the signataure verification failed.
* @return {Promise}
*/
PGP.prototype.verifySignedMessage = function(message, pgpSignature, publicKeyArmored) {
var self = this;
return self._q(function(resolve, reject) {
return self._q(function(resolve) {
var publicKeys, signatures;
// check keys
if (!self._privateKey) {
reject(new Error('Error verifying signed PGP message. Keys must be set!'));
return;
throw new Error('Error verifying signed PGP message. Keys must be set!');
}
// read keys and ciphertext message
try {
@ -416,16 +418,14 @@ PGP.prototype.verifySignedMessage = function(message, pgpSignature, publicKeyArm
publicKeys = [self._publicKey];
}
} catch (err) {
reject(new Error('Error verifying signed PGP message!'));
return;
throw new Error('Error verifying signed PGP message!');
}
// check signatures
try {
var msg = openpgp.message.readSignedContent(message, pgpSignature);
signatures = msg.verify(publicKeys);
} catch (err) {
reject(new Error('Error verifying signed PGP message!'));
return;
throw new Error('Error verifying signed PGP message!');
}
resolve(checkSignatureValidity(signatures));

View File

@ -15,23 +15,30 @@ function LawnchairDAO($q) {
/**
* Initialize the lawnchair database
* @param {String} dbName The name of the database
* @return {Promise}
*/
LawnchairDAO.prototype.init = function(dbName, callback) {
LawnchairDAO.prototype.init = function(dbName) {
var self = this;
return self._q(function(resolve, reject) {
if (!dbName) {
reject(new Error('Lawnchair DB name must be specified!'));
}
if (!dbName) {
return callback(new Error('Lawnchair DB name must be specified!'));
}
self._db = new Lawnchair({
name: dbName
}, function(success) {
callback(success ? undefined : new Error('Lawnchair initialization ' + dbName + ' failed!'));
self._db = new Lawnchair({
name: dbName
}, function(success) {
if (success) {
resolve();
} else {
reject(new Error('Lawnchair initialization ' + dbName + ' failed!'));
}
});
});
};
/**
* Create or update an object
* @return {Promise}
*/
LawnchairDAO.prototype.persist = function(key, object) {
var self = this;
@ -57,6 +64,7 @@ LawnchairDAO.prototype.persist = function(key, object) {
/**
* Persist a bunch of items at once
* @return {Promise}
*/
LawnchairDAO.prototype.batch = function(list) {
var self = this;
@ -79,6 +87,7 @@ LawnchairDAO.prototype.batch = function(list) {
/**
* Read a single item by its key
* @return {Promise}
*/
LawnchairDAO.prototype.read = function(key) {
var self = this;
@ -103,6 +112,7 @@ LawnchairDAO.prototype.read = function(key) {
* @param type [String] The type of item e.g. 'email'
* @param offset [Number] The offset of items to fetch (0 is the last stored item)
* @param num [Number] The number of items to fetch (null means fetch all)
* @return {Promise}
*/
LawnchairDAO.prototype.list = function(type, offset, num) {
var self = this;
@ -162,6 +172,7 @@ LawnchairDAO.prototype.list = function(type, offset, num) {
/**
* Removes an object liter from local storage by its key (delete)
* @return {Promise}
*/
LawnchairDAO.prototype.remove = function(key) {
var self = this;
@ -178,6 +189,7 @@ LawnchairDAO.prototype.remove = function(key) {
/**
* Removes an object liter from local storage by its key (delete)
* @return {Promise}
*/
LawnchairDAO.prototype.removeList = function(type) {
var self = this;
@ -216,6 +228,7 @@ LawnchairDAO.prototype.removeList = function(type) {
/**
* Clears the whole local storage cache
* @return {Promise}
*/
LawnchairDAO.prototype.clear = function() {
var self = this;

View File

@ -43,4 +43,12 @@ require('../src/js/app-config');
require('../src/js/util');
require('../src/js/crypto');
require('../src/js/service');
require('../src/js/email');
require('../src/js/email');
//
// Global mocks
//
window.qMock = function(res, rej) {
return new Promise(res, rej);
};

View File

@ -39,7 +39,7 @@ describe('PGP Crypto Api unit tests', function() {
'-----END PGP PRIVATE KEY BLOCK-----\r\n';
beforeEach(function() {
pgp = new PGP();
pgp = new PGP(qMock);
});
afterEach(function() {});
@ -50,9 +50,8 @@ describe('PGP Crypto Api unit tests', function() {
emailAddress: 'whiteout.test@t-onlinede',
keySize: keySize,
passphrase: passphrase
}, function(err, keys) {
expect(err).to.exist;
expect(keys).to.not.exist;
}).catch(function(err) {
expect(err.message).to.match(/options/);
done();
});
});
@ -61,76 +60,69 @@ describe('PGP Crypto Api unit tests', function() {
emailAddress: 'whiteout.testt-online.de',
keySize: keySize,
passphrase: passphrase
}, function(err, keys) {
expect(err).to.exist;
expect(keys).to.not.exist;
}).catch(function(err) {
expect(err.message).to.match(/options/);
done();
});
});
it('should work with passphrase', function(done) {
var keyObject;
pgp.generateKeys({
emailAddress: user,
keySize: keySize,
passphrase: passphrase
}, function(err, keys) {
expect(err).to.not.exist;
}).then(function(keys) {
expect(keys.keyId).to.exist;
expect(keys.privateKeyArmored).to.exist;
expect(keys.publicKeyArmored).to.exist;
keyObject = keys;
// test encrypt/decrypt
pgp.importKeys({
return pgp.importKeys({
passphrase: passphrase,
privateKeyArmored: keys.privateKeyArmored,
publicKeyArmored: keys.publicKeyArmored
}, function(err) {
expect(err).to.not.exist;
pgp.encrypt('secret', [keys.publicKeyArmored], function(err, ct) {
expect(err).to.not.exist;
expect(ct).to.exist;
pgp.decrypt(ct, keys.publicKeyArmored, function(err, pt, signValid) {
expect(err).to.not.exist;
expect(pt).to.equal('secret');
expect(signValid).to.be.true;
done();
});
});
});
}).then(function() {
return pgp.encrypt('secret', [keyObject.publicKeyArmored]);
}).then(function(ct) {
expect(ct).to.exist;
return pgp.decrypt(ct, keyObject.publicKeyArmored);
}).then(function(pt) {
expect(pt.decrypted).to.equal('secret');
expect(pt.signaturesValid).to.be.true;
done();
});
});
it('should work without passphrase', function(done) {
var keyObject;
pgp.generateKeys({
emailAddress: user,
keySize: keySize,
passphrase: ''
}, function(err, keys) {
expect(err).to.not.exist;
}).then(function(keys) {
expect(keys.keyId).to.exist;
expect(keys.privateKeyArmored).to.exist;
expect(keys.publicKeyArmored).to.exist;
keyObject = keys;
// test encrypt/decrypt
pgp.importKeys({
passphrase: undefined,
return pgp.importKeys({
passphrase: passphrase,
privateKeyArmored: keys.privateKeyArmored,
publicKeyArmored: keys.publicKeyArmored
}, function(err) {
expect(err).to.not.exist;
pgp.encrypt('secret', [keys.publicKeyArmored], function(err, ct) {
expect(err).to.not.exist;
expect(ct).to.exist;
pgp.decrypt(ct, keys.publicKeyArmored, function(err, pt, signValid) {
expect(err).to.not.exist;
expect(pt).to.equal('secret');
expect(signValid).to.be.true;
done();
});
});
});
}).then(function() {
return pgp.encrypt('secret', [keyObject.publicKeyArmored]);
}).then(function(ct) {
expect(ct).to.exist;
return pgp.decrypt(ct, keyObject.publicKeyArmored);
}).then(function(pt) {
expect(pt.decrypted).to.equal('secret');
expect(pt.signaturesValid).to.be.true;
done();
});
});
});
@ -141,15 +133,13 @@ describe('PGP Crypto Api unit tests', function() {
passphrase: 'asd',
privateKeyArmored: privkey,
publicKeyArmored: pubkey
}, function(err) {
}).catch(function(err) {
expect(err).to.exist;
expect(err.message).to.equal('Incorrect passphrase!');
pgp.exportKeys(function(err, keys) {
expect(err).to.exist;
expect(keys).to.not.exist;
done();
});
return pgp.exportKeys();
}).catch(function(err) {
expect(err).to.exist;
done();
});
});
it('should work', function(done) {
@ -157,16 +147,13 @@ describe('PGP Crypto Api unit tests', function() {
passphrase: passphrase,
privateKeyArmored: privkey,
publicKeyArmored: pubkey
}, function(err) {
expect(err).to.not.exist;
pgp.exportKeys(function(err, keys) {
expect(err).to.not.exist;
expect(keys.keyId).to.equal(keyId);
expect(keys.privateKeyArmored.replace(/\r/g, '')).to.equal(privkey.replace(/\r/g, ''));
expect(keys.publicKeyArmored.replace(/\r/g, '')).to.equal(pubkey.replace(/\r/g, ''));
done();
});
}).then(function() {
return pgp.exportKeys();
}).then(function(keys) {
expect(keys.keyId).to.equal(keyId);
expect(keys.privateKeyArmored.replace(/\r/g, '')).to.equal(privkey.replace(/\r/g, ''));
expect(keys.publicKeyArmored.replace(/\r/g, '')).to.equal(pubkey.replace(/\r/g, ''));
done();
});
});
});
@ -177,47 +164,38 @@ describe('PGP Crypto Api unit tests', function() {
privateKeyArmored: privkey,
oldPassphrase: passphrase,
newPassphrase: 'yxcv'
}, function(err, reEncryptedKey) {
expect(err).to.not.exist;
}).then(function(reEncryptedKey) {
expect(reEncryptedKey).to.exist;
pgp.importKeys({
return pgp.importKeys({
passphrase: 'yxcv',
privateKeyArmored: reEncryptedKey,
publicKeyArmored: pubkey
}, function(err) {
expect(err).to.not.exist;
done();
});
});
}).then(done);
});
it('should work with empty passphrase', function(done) {
pgp.changePassphrase({
privateKeyArmored: privkey,
oldPassphrase: passphrase,
newPassphrase: undefined
}, function(err, reEncryptedKey) {
expect(err).to.not.exist;
}).then(function(reEncryptedKey) {
expect(reEncryptedKey).to.exist;
pgp.importKeys({
return pgp.importKeys({
passphrase: undefined,
privateKeyArmored: reEncryptedKey,
publicKeyArmored: pubkey
}, function(err) {
expect(err).to.not.exist;
done();
});
});
}).then(done);
});
it('should fail when passphrases are equal', function(done) {
pgp.changePassphrase({
privateKeyArmored: privkey,
oldPassphrase: passphrase,
newPassphrase: passphrase
}, function(err, reEncryptedKey) {
}).catch(function(err) {
expect(err).to.exist;
expect(reEncryptedKey).to.not.exist;
done();
});
});
@ -226,9 +204,8 @@ describe('PGP Crypto Api unit tests', function() {
privateKeyArmored: privkey,
oldPassphrase: 'asd',
newPassphrase: 'yxcv'
}, function(err, reEncryptedKey) {
}).catch(function(err) {
expect(err).to.exist;
expect(reEncryptedKey).to.not.exist;
done();
});
});
@ -247,10 +224,7 @@ describe('PGP Crypto Api unit tests', function() {
passphrase: passphrase,
privateKeyArmored: privkey,
publicKeyArmored: pubkey
}, function(err) {
expect(err).to.not.exist;
done();
});
}).then(done);
});
describe('Get KeyId', function() {
@ -311,22 +285,19 @@ describe('PGP Crypto Api unit tests', function() {
it('should fail', function(done) {
var input = null;
pgp.encrypt(input, [pubkey], function(err, ct) {
pgp.encrypt(input, [pubkey]).catch(function(err) {
expect(err).to.exist;
expect(ct).to.not.exist;
done();
});
});
it('should work', function(done) {
pgp.encrypt(message, [pubkey], function(err, ct) {
expect(err).to.not.exist;
pgp.encrypt(message, [pubkey]).then(function(ct) {
expect(ct).to.exist;
done();
});
});
it('should encrypt to myself if public keys are empty', function(done) {
pgp.encrypt(message, undefined, function(err, ct) {
expect(err).to.not.exist;
pgp.encrypt(message, undefined).then(function(ct) {
expect(ct).to.exist;
done();
});
@ -337,8 +308,7 @@ describe('PGP Crypto Api unit tests', function() {
var ciphertext;
beforeEach(function(done) {
pgp.encrypt(message, [pubkey], function(err, ct) {
expect(err).to.not.exist;
pgp.encrypt(message, [pubkey]).then(function(ct) {
expect(ct).to.exist;
ciphertext = ct;
done();
@ -348,45 +318,40 @@ describe('PGP Crypto Api unit tests', function() {
it('should fail', function(done) {
var input = 'asdfa\rsdf';
pgp.decrypt(input, pubkey, function(err, pt) {
pgp.decrypt(input, pubkey).catch(function(err) {
expect(err).to.exist;
expect(pt).to.not.exist;
done();
});
});
it('should work', function(done) {
pgp.decrypt(ciphertext, pubkey, function(err, pt, signValid) {
expect(err).to.not.exist;
expect(pt).to.equal(message);
expect(signValid).to.be.true;
pgp.decrypt(ciphertext, pubkey).then(function(pt) {
expect(pt.decrypted).to.equal(message);
expect(pt.signaturesValid).to.be.true;
done();
});
});
it('should work without signature', function(done) {
openpgp.encryptMessage([pgp._publicKey], message).then(function(ct) {
pgp.decrypt(ct, undefined, function(err, pt, signValid) {
expect(err).to.not.exist;
expect(pt).to.equal(message);
expect(signValid).to.be.undefined;
done();
});
return pgp.decrypt(ct, undefined);
}).then(function(pt) {
expect(pt.decrypted).to.equal(message);
expect(pt.signaturesValid).to.be.undefined;
done();
});
});
it('should fail to verify if public keys are empty', function(done) {
// setup another public key so that signature verification fails
pgp._publicKey = openpgp.key.readArmored(wrongPubkey).keys[0];
pgp.decrypt(ciphertext, undefined, function(err, pt, signValid) {
expect(err).to.not.exist;
expect(pt).to.equal(message);
expect(signValid).to.be.null;
pgp.decrypt(ciphertext, undefined).then(function(pt) {
expect(pt.decrypted).to.equal(message);
expect(pt.signaturesValid).to.be.null;
done();
});
});
it('should decrypt but signValid should be null for wrong public key', function(done) {
pgp.decrypt(ciphertext, wrongPubkey, function(err, pt, signValid) {
expect(err).to.not.exist;
expect(pt).to.equal(message);
expect(signValid).to.be.null;
pgp.decrypt(ciphertext, wrongPubkey).then(function(pt) {
expect(pt.decrypted).to.equal(message);
expect(pt.signaturesValid).to.be.null;
done();
});
});
@ -403,23 +368,20 @@ describe('PGP Crypto Api unit tests', function() {
});
it('should work', function(done) {
pgp.verifyClearSignedMessage(clearsigned, pubkey, function(err, signaturesValid) {
expect(err).to.not.exist;
pgp.verifyClearSignedMessage(clearsigned, pubkey).then(function(signaturesValid) {
expect(signaturesValid).to.be.true;
done();
});
});
it('should fail', function(done) {
pgp.verifyClearSignedMessage(clearsigned.replace('clearsigned', 'invalid'), pubkey, function(err, signaturesValid) {
expect(err).to.not.exist;
pgp.verifyClearSignedMessage(clearsigned.replace('clearsigned', 'invalid'), pubkey).then(function(signaturesValid) {
expect(signaturesValid).to.be.false;
done();
});
});
it('should be null for wrong public key', function(done) {
pgp.verifyClearSignedMessage(clearsigned, wrongPubkey, function(err, signaturesValid) {
expect(err).to.not.exist;
pgp.verifyClearSignedMessage(clearsigned, wrongPubkey).then(function(signaturesValid) {
expect(signaturesValid).to.be.null;
done();
});
@ -439,23 +401,20 @@ describe('PGP Crypto Api unit tests', function() {
});
it('should work', function(done) {
pgp.verifySignedMessage(signedMessage, signature, pubkey, function(err, signaturesValid) {
expect(err).to.not.exist;
pgp.verifySignedMessage(signedMessage, signature, pubkey).then(function(signaturesValid) {
expect(signaturesValid).to.be.true;
done();
});
});
it('should fail', function(done) {
pgp.verifySignedMessage(signedMessage.replace('signed', 'invalid'), signature, pubkey, function(err, signaturesValid) {
expect(err).to.not.exist;
pgp.verifySignedMessage(signedMessage.replace('signed', 'invalid'), signature, pubkey).then(function(signaturesValid) {
expect(signaturesValid).to.be.false;
done();
});
});
it('should be null for wrong public key', function(done) {
pgp.verifySignedMessage(signedMessage, signature, wrongPubkey, function(err, signaturesValid) {
expect(err).to.not.exist;
pgp.verifySignedMessage(signedMessage, signature, wrongPubkey).then(function(signaturesValid) {
expect(signaturesValid).to.be.null;
done();
});

View File

@ -21,9 +21,8 @@ describe('Lawnchair DAO unit tests', function() {
var lawnchairDao;
beforeEach(function(done) {
lawnchairDao = new LawnchairDAO();
lawnchairDao.init(dbName, function(err) {
expect(err).to.not.exist;
lawnchairDao = new LawnchairDAO(qMock);
lawnchairDao.init(dbName).then(function() {
expect(lawnchairDao._db).to.exist;
done();
});