add tests

This commit is contained in:
Sanjana Rajan 2017-03-06 10:15:01 -08:00
parent 57d07091e8
commit 7b58cd9200
2 changed files with 27 additions and 3 deletions

View File

@ -32,7 +32,7 @@ import enums from './enums.js';
import armor from './encoding/armor.js';
import config from './config';
import crypto from './crypto';
import signature from './signature.js';
import * as sigModule from './signature.js';
import * as keyModule from './key.js';
/**
@ -376,7 +376,7 @@ Message.prototype.signDetached = function(privateKeys) {
packetlist.push(signaturePacket);
}
return new signature.Signature(packetlist);
return new sigModule.Signature(packetlist);
};

View File

@ -595,7 +595,7 @@ describe("Signature", function() {
expect(pubKey.users[0].selfCertifications).to.eql(pubKey2.users[0].selfCertifications);
});
it('Verify a detached signature', function() {
it('Verify a detached signature using readSignedContent', function() {
var detachedSig = ['-----BEGIN PGP SIGNATURE-----',
'Version: GnuPG v1.4.13 (Darwin)',
'Comment: GPGTools - https://gpgtools.org',
@ -641,6 +641,30 @@ describe("Signature", function() {
expect(result[0].valid).to.be.true;
});
it('Detached signature signing and verification cleartext', function () {
var msg = openpgp.message.fromText('hello');
var pubKey2 = openpgp.key.readArmored(pub_key_arm2).keys[0];
var privKey2 = openpgp.key.readArmored(priv_key_arm2).keys[0];
privKey2.decrypt('hello world');
var detachedSig = msg.signDetached([privKey2]);
var result = msg.verifyDetached(detachedSig, [pubKey2]);
expect(result[0].valid).to.be.true;
});
it('Detached signature signing and verification encrypted', function () {
var msg = openpgp.message.fromText('hello');
var pubKey2 = openpgp.key.readArmored(pub_key_arm2).keys[0];
var privKey2 = openpgp.key.readArmored(priv_key_arm2).keys[0];
privKey2.decrypt('hello world');
msg.encrypt({keys: [pubKey2] });
var detachedSig = msg.signDetached([privKey2]);
var result = msg.verifyDetached(detachedSig, [pubKey2]);
expect(result[0].valid).to.be.true;
});
it('Sign message with key without password', function(done) {
var opt = {numBits: 512, userIds: { name:'test', email:'a@b.com' }, passphrase: null};
if (openpgp.util.getWebCryptoAll()) { opt.numBits = 2048; } // webkit webcrypto accepts minimum 2048 bit keys