add bad test case

This commit is contained in:
Tankred Hase 2013-10-11 22:10:50 +02:00
parent 95f815de91
commit d6ed270c02
2 changed files with 26 additions and 8 deletions

View File

@ -51,6 +51,7 @@ define(function(require) {
// unlock and import private key
if (!openpgp.keyring.importPrivateKey(options.privateKeyArmored, options.passphrase)) {
openpgp.keyring.init();
callback({
errMsg: 'Incorrect passphrase!'
});
@ -81,19 +82,21 @@ define(function(require) {
var publicKey, privateKey;
privateKey = openpgp.keyring.exportPrivateKey(0);
publicKey = openpgp.keyring.getPublicKeysForKeyId(privateKey.keyId)[0];
if (privateKey && privateKey.keyId) {
publicKey = openpgp.keyring.getPublicKeysForKeyId(privateKey.keyId)[0];
}
if (privateKey && privateKey.keyId && privateKey.armored && publicKey && publicKey.armored) {
callback(null, {
keyId: util.hexstrdump(privateKey.keyId).toUpperCase(),
privateKeyArmored: privateKey.armored,
publicKeyArmored: publicKey.armored
if (!privateKey || !privateKey.keyId || !privateKey.armored || !publicKey || !publicKey.armored) {
callback({
errMsg: 'Could not export keys!'
});
return;
}
callback({
errMsg: 'Could not export keys!'
callback(null, {
keyId: util.hexstrdump(privateKey.keyId).toUpperCase(),
privateKeyArmored: privateKey.armored,
publicKeyArmored: publicKey.armored
});
};

View File

@ -83,6 +83,21 @@ define(function(require) {
});
describe('Import/Export key pair', function() {
it('should fail', function(done) {
pgp.importKeys({
passphrase: 'asd',
privateKeyArmored: privkey,
publicKeyArmored: pubkey
}, function(err) {
expect(err).to.exist;
pgp.exportKeys(function(err, keys) {
expect(err).to.exist;
expect(keys).to.not.exist;
done();
});
});
});
it('should work', function(done) {
pgp.importKeys({
passphrase: passphrase,