Eliminate previous ci tests.
Merge ci keyring tests to unittests, the other ci tests just duplicate other unit tests. Change Makefile to just run grunt and npm tasks.
This commit is contained in:
parent
598618ec8a
commit
28ba64c11d
18
Gruntfile.js
18
Gruntfile.js
|
@ -42,21 +42,11 @@ module.exports = function(grunt) {
|
|||
},
|
||||
unittests: {
|
||||
files: {
|
||||
'test/lib/test-bundle.js': []
|
||||
'test/lib/unittests-bundle.js': []
|
||||
},
|
||||
options: {
|
||||
debug: true,
|
||||
alias: './test/test-all.js:unittests',
|
||||
external: [ 'openpgp', 'keyring' ]
|
||||
}
|
||||
},
|
||||
ci_tests: {
|
||||
files: {
|
||||
'test/lib/ci-tests-bundle.js': []
|
||||
},
|
||||
options: {
|
||||
debug: true,
|
||||
alias: './test/ci-tests-all.js:ci-tests',
|
||||
alias: './test/unittests.js:unittests',
|
||||
external: [ 'openpgp', 'keyring' ]
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +110,7 @@ module.exports = function(grunt) {
|
|||
expand: true,
|
||||
flatten: true,
|
||||
cwd: 'node_modules/',
|
||||
src: ['mocha/mocha.css', 'mocha/mocha.js', 'chai/chai.js', 'sinon/pkg/sinon.js'],
|
||||
src: ['mocha/mocha.css', 'mocha/mocha.js', 'chai/chai.js'],
|
||||
dest: 'test/lib/'
|
||||
}
|
||||
}
|
||||
|
@ -147,7 +137,7 @@ module.exports = function(grunt) {
|
|||
// Alias the `mocha_phantomjs` task to run `mocha-phantomjs`
|
||||
grunt.registerTask('mocha_phantomjs', 'mocha-phantomjs', function () {
|
||||
var done = this.async();
|
||||
var mocha = require('child_process').exec('node_modules/mocha-phantomjs/bin/mocha-phantomjs ./test/ci-tests.html', function (err) {
|
||||
var mocha = require('child_process').exec('node_modules/mocha-phantomjs/bin/mocha-phantomjs ./test/unittests.html', function (err) {
|
||||
done(err);
|
||||
});
|
||||
mocha.stdout.pipe(process.stdout);
|
||||
|
|
37
Makefile
37
Makefile
|
@ -2,11 +2,10 @@ default: help
|
|||
|
||||
help:
|
||||
@echo "update - get latest sources"
|
||||
@echo "minify - makes JavaScript download and run faster"
|
||||
@echo "bundle - makes JavaScript download and run faster"
|
||||
@echo "lint - checks JavaScript files for style issues"
|
||||
@echo "test - runs JavaScript unit tests"
|
||||
@echo "example - creates a simple example"
|
||||
@echo "ext-chr-gmail - creates the Google Chrome / Google Mail extension"
|
||||
@echo "documentation - generates documentation. Requires jsdoc (3.2) in PATH"
|
||||
|
||||
update: update-me update-deps
|
||||
|
@ -17,34 +16,20 @@ update-me:
|
|||
update-deps:
|
||||
@git submodule foreach git pull
|
||||
|
||||
bundle:
|
||||
@grunt
|
||||
|
||||
lint:
|
||||
@grunt jshint
|
||||
|
||||
test:
|
||||
@npm test
|
||||
|
||||
example:
|
||||
@mkdir -p build
|
||||
@rm -f build/openpgpjs-0.x.zip
|
||||
@zip -j build/openpgpjs-0.x.zip resources/example.* resources/openpgp.min.js resources/jquery.min.js
|
||||
@echo "Have a look at build/openpgpjs-0.x.zip"
|
||||
|
||||
ext-chr-gmail:
|
||||
@./scripts/create_extension.sh
|
||||
|
||||
lint:
|
||||
@echo See http://code.google.com/closure/utilities/
|
||||
@./scripts/lint.sh
|
||||
|
||||
bundle:
|
||||
@browserify -d -r ./src/:openpgp > ./resources/openpgp.js
|
||||
@browserify -r ./src/:openpgp > ./resources/openpgp_nodebug.js
|
||||
@browserify -d -x openpgp -r ./src/keyring/:keyring > ./resources/keyring.js
|
||||
@browserify -x openpgp -r ./src/keyring/:keyring > ./resources/keyring_nodebug.js
|
||||
|
||||
bundle-test:
|
||||
@browserify -d -x openpgp -x keyring -r ./test/test-all.js:unittests > ./test/lib/test-bundle.js
|
||||
|
||||
bundle-ci-test:
|
||||
@browserify -d -x openpgp -x keyring -r ./test/ci-tests-all.js:ci-tests > ./test/lib/ci-tests-bundle.js
|
||||
|
||||
test:
|
||||
@echo to be implemented
|
||||
@echo Open test/index.html instead
|
||||
|
||||
documentation:
|
||||
@jsdoc src -r -d doc
|
||||
@grunt jsdoc
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
"mocha-phantomjs": "~3.1.6",
|
||||
"phantomjs": "~1.9.2-5",
|
||||
"chai": "~1.8.1",
|
||||
"sinon": "~1.7.3",
|
||||
"grunt-contrib-copy": "~0.4.1",
|
||||
"grunt-browserify": "~1.2.11",
|
||||
"grunt-contrib-uglify": "*",
|
||||
|
|
237
test/ci-quick.js
237
test/ci-quick.js
|
@ -1,237 +0,0 @@
|
|||
var openpgp = require('openpgp');
|
||||
|
||||
'use strict';
|
||||
|
||||
var expect = chai.expect;
|
||||
|
||||
describe('Openpgp integration tests', function() {
|
||||
var user = 'test@t-online.de',
|
||||
passphrase = 'asdf',
|
||||
keySize = 512,
|
||||
keyId = 'F6F60E9B42CDFF4C',
|
||||
pubkey = '-----BEGIN PGP PUBLIC KEY BLOCK-----\n' +
|
||||
'Version: OpenPGP.js v.1.20131011\n' +
|
||||
'Comment: http://openpgpjs.org\n' +
|
||||
'\n' +
|
||||
'xk0EUlhMvAEB/2MZtCUOAYvyLFjDp3OBMGn3Ev8FwjzyPbIF0JUw+L7y2XR5\n' +
|
||||
'RVGvbK88unV3cU/1tOYdNsXI6pSp/Ztjyv7vbBUAEQEAAc0pV2hpdGVvdXQg\n' +
|
||||
'VXNlciA8d2hpdGVvdXQudGVzdEB0LW9ubGluZS5kZT7CXAQQAQgAEAUCUlhM\n' +
|
||||
'vQkQ9vYOm0LN/0wAAAW4Af9C+kYW1AvNWmivdtr0M0iYCUjM9DNOQH1fcvXq\n' +
|
||||
'IiN602mWrkd8jcEzLsW5IUNzVPLhrFIuKyBDTpLnC07Loce1\n' +
|
||||
'=6XMW\n' +
|
||||
'-----END PGP PUBLIC KEY BLOCK-----',
|
||||
privkey = '-----BEGIN PGP PRIVATE KEY BLOCK-----\n' +
|
||||
'Version: OpenPGP.js v.1.20131011\n' +
|
||||
'Comment: http://openpgpjs.org\n' +
|
||||
'\n' +
|
||||
'xcBeBFJYTLwBAf9jGbQlDgGL8ixYw6dzgTBp9xL/BcI88j2yBdCVMPi+8tl0\n' +
|
||||
'eUVRr2yvPLp1d3FP9bTmHTbFyOqUqf2bY8r+72wVABEBAAH+AwMIhNB4ivtv\n' +
|
||||
'Y2xg6VeMcjjHxZayESHACV+nQx5Tx6ev6xzIF1Qh72fNPDppLhFSFOuTTMsU\n' +
|
||||
'kTN4c+BVYt29spH+cA1jcDAxQ2ULrNAXo+hheOqhpedTs8aCbcLFkJAS16hk\n' +
|
||||
'YSk4OnJgp/z24rVju1SHRSFbgundPzmNgXeX9e8IkviGhhQ11Wc5YwVkx03t\n' +
|
||||
'Z3MdDMF0jyhopbPIoBdyJB0dhvBh98w3JmwpYh9wjUA9MBHD1tvHpRmSZ3BM\n' +
|
||||
'UCmATn2ZLWBRWiYqFbgDnL1GM80pV2hpdGVvdXQgVXNlciA8d2hpdGVvdXQu\n' +
|
||||
'dGVzdEB0LW9ubGluZS5kZT7CXAQQAQgAEAUCUlhMvQkQ9vYOm0LN/0wAAAW4\n' +
|
||||
'Af9C+kYW1AvNWmivdtr0M0iYCUjM9DNOQH1fcvXqIiN602mWrkd8jcEzLsW5\n' +
|
||||
'IUNzVPLhrFIuKyBDTpLnC07Loce1\n' +
|
||||
'=ULta\n' +
|
||||
'-----END PGP PRIVATE KEY BLOCK-----';
|
||||
var keyringClass = require('keyring');
|
||||
var keyring = new keyringClass();
|
||||
|
||||
describe('Generate key pair', function() {
|
||||
it('should work', function(done) {
|
||||
// generate keypair (keytype 1=RSA)
|
||||
var errMsg, err;
|
||||
var keys = null;
|
||||
|
||||
try {
|
||||
var userId = 'Whiteout User <' + user + '>';
|
||||
var keys = openpgp.generateKeyPair(1, keySize, userId, passphrase);
|
||||
var keyId = openpgp.util.hexstrdump(keys.key.getKeyPacket().getKeyId()).toUpperCase();
|
||||
expect(keyId).to.exist;
|
||||
expect(keys.privateKeyArmored).to.exist;
|
||||
expect(keys.publicKeyArmored).to.exist;
|
||||
} catch (e) {
|
||||
errMsg = 'Keygeneration failed!';
|
||||
err = e;
|
||||
}
|
||||
|
||||
expect(err).to.not.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Keyring', function() {
|
||||
describe('Import key pair', function() {
|
||||
it('should work', function(done) {
|
||||
// clear any keypair already in the keychain
|
||||
keyring.clear();
|
||||
keyring.importKey(privkey);
|
||||
keyring.importKey(pubkey);
|
||||
done();
|
||||
});
|
||||
});
|
||||
describe('Retrieve keys', function() {
|
||||
it('getPublicKeyForAddress() - unknown address', function(done) {
|
||||
var key = keyring.getPublicKeyForAddress('nobody@example.com');
|
||||
expect(key).to.be.empty;
|
||||
done();
|
||||
});
|
||||
it('getPublicKeyForAddress() - valid address', function(done) {
|
||||
var key = keyring.getPublicKeyForAddress(user);
|
||||
expect(key).to.exist;
|
||||
done();
|
||||
});
|
||||
it('getPrivateKeyForAddress() - unknown address', function(done) {
|
||||
var key = keyring.getPrivateKeyForAddress('nobody@example.com');
|
||||
expect(key).to.be.empty;
|
||||
done();
|
||||
});
|
||||
it('getPrivateKeyForAddress() - valid address', function(done) {
|
||||
var key = keyring.getPrivateKeyForAddress(user);
|
||||
expect(key).to.exist;
|
||||
done();
|
||||
});
|
||||
it('getKeysForKeyId() - unknown id', function(done) {
|
||||
var keys = keyring.getKeysForKeyId('000102030405060708');
|
||||
expect(keys).to.be.empty;
|
||||
done();
|
||||
});
|
||||
it('getKeysForKeyId() - valid id', function(done) {
|
||||
var keys = keyring.getKeysForKeyId(keyId.toLowerCase());
|
||||
expect(keys).to.exist.and.have.length(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Encryption', function() {
|
||||
var message = 'asdfs\n\nThursday, Nov 21, 2013 7:38 PM asdf@example.com wrote:\n' +
|
||||
'> asdf\n' +
|
||||
'> \n' +
|
||||
'> Thursday, Nov 21, 2013 7:32 PM asdf@example.com wrote:\n' +
|
||||
'> > secret 3',
|
||||
ciphertext;
|
||||
|
||||
describe('Encrypt and Sign', function() {
|
||||
it('should work', function(done) {
|
||||
var signkey = openpgp.key.readArmored(privkey).keys[0];
|
||||
expect(signkey).to.exist;
|
||||
var encryptkey = openpgp.key.readArmored(pubkey).keys[0];
|
||||
expect(encryptkey).to.exist;
|
||||
expect(signkey.decrypt(passphrase)).to.be.true;
|
||||
ciphertext = openpgp.signAndEncryptMessage([encryptkey], signkey, message);
|
||||
expect(ciphertext).to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Decrypt and Verify', function() {
|
||||
it('should work', function(done) {
|
||||
var decryptkey = openpgp.key.readArmored(privkey).keys[0];
|
||||
expect(decryptkey, 'decryptkey').to.exist;
|
||||
var verifykey = openpgp.key.readArmored(pubkey).keys[0];
|
||||
expect(verifykey, 'verifykey').to.exist;
|
||||
var pgpmsg = openpgp.message.readArmored(ciphertext);
|
||||
expect(pgpmsg, 'pgpmsg').to.exist;
|
||||
var keyids = pgpmsg.getEncryptionKeyIds();
|
||||
expect(keyids, 'keyids').to.exist;
|
||||
expect(decryptkey.decryptKeyPacket(keyids, passphrase), 'decryptKeyPacket()').to.be.true;
|
||||
var result = openpgp.decryptAndVerifyMessage(decryptkey, [verifykey], pgpmsg);
|
||||
expect(result, 'decryptAndVerifyMessage() result').to.exist;
|
||||
expect(result.text, 'decryptAndVerifyMessage() result.text').to.exist.and.equal(message);
|
||||
expect(result.signatures, 'decryptAndVerifyMessage() result.signatures').to.exist.and.not.be.empty;
|
||||
expect(result.signatures[0].valid, 'decryptAndVerifyMessage() result.signatures[0].valid').to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Verify clearsign from gpg', function() {
|
||||
describe('Verify V3 signature', function() {
|
||||
var v3_clearsign_msg = '-----BEGIN PGP SIGNED MESSAGE-----\r\n' +
|
||||
'Hash: SHA1\r\n' +
|
||||
'\r\n' +
|
||||
'This is a test message.\r\n' +
|
||||
'\r\n' +
|
||||
'This paragraph is separated form the next by a line of dashes.\r\n' +
|
||||
'\r\n' +
|
||||
'- --------------------------------------------------------------------------\r\n' +
|
||||
'\r\n' +
|
||||
'The next paragraph has a number of blank lines between this one and it.\r\n' +
|
||||
'\r\n' +
|
||||
'\r\n' +
|
||||
'\r\n' +
|
||||
'\r\n' +
|
||||
'\r\n' +
|
||||
'\r\n' +
|
||||
'This is the last paragraph.\r\n' +
|
||||
'\r\n' +
|
||||
'- --\r\n' +
|
||||
'\r\n' +
|
||||
'Joe Test\r\n' +
|
||||
'-----BEGIN PGP SIGNATURE-----\r\n' +
|
||||
'Version: GnuPG v1.4.15 (GNU/Linux)\r\n' +
|
||||
'\r\n' +
|
||||
'iQBVAwUBUp/7GPb2DptCzf9MAQKviQH6A6Pqa63kxWI+atMiaSXz5uifgsBoiOof\r\n' +
|
||||
'E3/oVTIGyGTgB7KnwZiFkDMFrUNREJVSQGt6+4nxje8gARcuYpMnWw==\r\n' +
|
||||
'=lOCC\r\n' +
|
||||
'-----END PGP SIGNATURE-----\r\n';
|
||||
it('should work', function(done) {
|
||||
var cleartext = openpgp.cleartext.readArmored(v3_clearsign_msg);
|
||||
expect(cleartext).to.exist;
|
||||
var verifykey = openpgp.key.readArmored(pubkey).keys[0];
|
||||
expect(verifykey, 'verifykey').to.exist;
|
||||
var result = cleartext.verify([verifykey])
|
||||
expect(result, 'verify() result').to.exist.and.not.be.empty;
|
||||
expect(result[0].keyid, 'verify() result[0].keyid').to.exist;
|
||||
expect(result[0].valid, 'verify() result[0].valid').to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Verify V4 signature', function() {
|
||||
var v4_clearsign_msg = '-----BEGIN PGP SIGNED MESSAGE-----\r\n' +
|
||||
'Hash: SHA1\r\n' +
|
||||
'\r\n' +
|
||||
'This is a test message.\r\n' +
|
||||
'\r\n' +
|
||||
'This paragraph is separated form the next by a line of dashes.\r\n' +
|
||||
'\r\n' +
|
||||
'- --------------------------------------------------------------------------\r\n' +
|
||||
'\r\n' +
|
||||
'The next paragraph has a number of blank lines between this one and it.\r\n' +
|
||||
'\r\n' +
|
||||
'\r\n' +
|
||||
'\r\n' +
|
||||
'\r\n' +
|
||||
'\r\n' +
|
||||
'\r\n' +
|
||||
'This is the last paragraph.\r\n' +
|
||||
'\r\n' +
|
||||
'- --\r\n' +
|
||||
'\r\n' +
|
||||
'Joe Test\r\n' +
|
||||
'-----BEGIN PGP SIGNATURE-----\r\n' +
|
||||
'Version: GnuPG v1.4.15 (GNU/Linux)\r\n' +
|
||||
'\r\n' +
|
||||
'iFwEAQECAAYFAlKf5LcACgkQ9vYOm0LN/0ybVwH8CItdDh4kWKVcyUx3Q3hWZnWd\r\n' +
|
||||
'zP9CUbIa9uToIPABjV3GOTDM3ZgiP0/SE6Al5vG8hlx+/u2piVojoLovk/4LnA==\r\n' +
|
||||
'=i6ew\r\n' +
|
||||
'-----END PGP SIGNATURE-----\r\n';
|
||||
|
||||
it('should work', function(done) {
|
||||
var cleartext = openpgp.cleartext.readArmored(v4_clearsign_msg);
|
||||
expect(cleartext).to.exist;
|
||||
var verifykey = openpgp.key.readArmored(pubkey).keys[0];
|
||||
expect(verifykey, 'verifykey').to.exist;
|
||||
var result = cleartext.verify([verifykey])
|
||||
expect(result, 'verify() result').to.exist.and.not.be.empty;
|
||||
expect(result[0].keyid, 'verify() result[0].keyid').to.exist;
|
||||
expect(result[0].valid, 'verify() result[0].valid').to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,3 +0,0 @@
|
|||
require('./ci-quick.js');
|
||||
require('./general');
|
||||
require('./crypto');
|
|
@ -1,65 +1,78 @@
|
|||
var openpgp = require('openpgp');
|
||||
|
||||
'use strict';
|
||||
|
||||
var expect = chai.expect;
|
||||
var openpgp = require('openpgp'),
|
||||
keyring = new (new require('keyring'))(),
|
||||
expect = chai.expect;
|
||||
|
||||
describe("Keyring", function() {
|
||||
var keyring = new (new require('keyring'))();
|
||||
var user = 'test@t-online.de',
|
||||
passphrase = 'asdf',
|
||||
keySize = 512,
|
||||
keyId = 'F6F60E9B42CDFF4C',
|
||||
pubkey = '-----BEGIN PGP PUBLIC KEY BLOCK-----\n' +
|
||||
'Version: OpenPGP.js v.1.20131011\n' +
|
||||
'Comment: http://openpgpjs.org\n' +
|
||||
'\n' +
|
||||
'xk0EUlhMvAEB/2MZtCUOAYvyLFjDp3OBMGn3Ev8FwjzyPbIF0JUw+L7y2XR5\n' +
|
||||
'RVGvbK88unV3cU/1tOYdNsXI6pSp/Ztjyv7vbBUAEQEAAc0pV2hpdGVvdXQg\n' +
|
||||
'VXNlciA8d2hpdGVvdXQudGVzdEB0LW9ubGluZS5kZT7CXAQQAQgAEAUCUlhM\n' +
|
||||
'vQkQ9vYOm0LN/0wAAAW4Af9C+kYW1AvNWmivdtr0M0iYCUjM9DNOQH1fcvXq\n' +
|
||||
'IiN602mWrkd8jcEzLsW5IUNzVPLhrFIuKyBDTpLnC07Loce1\n' +
|
||||
'=6XMW\n' +
|
||||
'-----END PGP PUBLIC KEY BLOCK-----',
|
||||
privkey = '-----BEGIN PGP PRIVATE KEY BLOCK-----\n' +
|
||||
'Version: OpenPGP.js v.1.20131011\n' +
|
||||
'Comment: http://openpgpjs.org\n' +
|
||||
'\n' +
|
||||
'xcBeBFJYTLwBAf9jGbQlDgGL8ixYw6dzgTBp9xL/BcI88j2yBdCVMPi+8tl0\n' +
|
||||
'eUVRr2yvPLp1d3FP9bTmHTbFyOqUqf2bY8r+72wVABEBAAH+AwMIhNB4ivtv\n' +
|
||||
'Y2xg6VeMcjjHxZayESHACV+nQx5Tx6ev6xzIF1Qh72fNPDppLhFSFOuTTMsU\n' +
|
||||
'kTN4c+BVYt29spH+cA1jcDAxQ2ULrNAXo+hheOqhpedTs8aCbcLFkJAS16hk\n' +
|
||||
'YSk4OnJgp/z24rVju1SHRSFbgundPzmNgXeX9e8IkviGhhQ11Wc5YwVkx03t\n' +
|
||||
'Z3MdDMF0jyhopbPIoBdyJB0dhvBh98w3JmwpYh9wjUA9MBHD1tvHpRmSZ3BM\n' +
|
||||
'UCmATn2ZLWBRWiYqFbgDnL1GM80pV2hpdGVvdXQgVXNlciA8d2hpdGVvdXQu\n' +
|
||||
'dGVzdEB0LW9ubGluZS5kZT7CXAQQAQgAEAUCUlhMvQkQ9vYOm0LN/0wAAAW4\n' +
|
||||
'Af9C+kYW1AvNWmivdtr0M0iYCUjM9DNOQH1fcvXqIiN602mWrkd8jcEzLsW5\n' +
|
||||
'IUNzVPLhrFIuKyBDTpLnC07Loce1\n' +
|
||||
'=ULta\n' +
|
||||
'-----END PGP PRIVATE KEY BLOCK-----';
|
||||
|
||||
keyring.importKey([
|
||||
'-----BEGIN PGP PUBLIC KEY BLOCK-----',
|
||||
'Version: GnuPG v1.4.11 (GNU/Linux)',
|
||||
'',
|
||||
'mQGiBFERvI4RBAD0M/HGglCtVNXPF72ehT8riAXrl0rSec4RJC61Bh+UAOhxn5+U',
|
||||
'fDgos5p1SpIzYmn+M87JoSSVLAjfakFk0gHgR9I3bu7SIwq3Bikk1Vw3gO+yDSO6',
|
||||
'TKpLUFGYDiBSSE1MGdxBadWLE1hlRf5B2x62gnGmjSpSVbly33PFkoDmrwCg9rAp',
|
||||
'RmncnF9GhWjOLFkEoQw9Yx8EAOsxvq8Ig5Z1gk+ZKfDZeftpHRe3FdrRtbnhxvYY',
|
||||
'7z+w9uz1EpoZUwDR5G4X3hTwJQ7lXmIOskg/+eRMLEAqEY7b/7tW6RaUJ2d6Ehsi',
|
||||
'dOS89fIxElwjAOnVOM5S24f0FDQTTto7QBOoxcNTfkEJCHXSlpoOUmGAP85fXh3l',
|
||||
'yPTGBACJfKc76Un3UWC1sWIRDxYiyh3ZpZyNEskoV6ESW8jEI1RnMnv5TrfGJH5K',
|
||||
'E8jWX7TTnoFyPJtBTjlucAtkQaS4Bb7dg1LLja17zAqKNGOJK2b9fb2Z+lnTjPiY',
|
||||
'i7DPH1XHnfaEexjlh/U7mYa5RrwIphRxNi8gCuxv874ZMmhEn7QWVGVzdDMgPHRl',
|
||||
'c3QzQHRlc3QuY29tPohiBBMRAgAiBQJREbyOAhsDBgsJCAcDAgYVCAIJCgsEFgID',
|
||||
'AQIeAQIXgAAKCRC0u8O0Moa2JYxyAJ9Oi2UlcUT0VJNgwjyl/VF9Xcjf9gCeJPvy',
|
||||
'g/fp4EAU8MJIaN2yMI8pLFS5AaIEURG8nhEEAKVgeNDuYDPufLuJ0GrJV/CbXEjj',
|
||||
'aEPA0iTUqV0nTCPdAfQ/nmE3gh5UlNMr/zSHJ+c4FQhYdLrzRGDOSzV+mfPHH3t+',
|
||||
'YVx+wat0BYwABpHAtsIuLIVo2RQqYZYH85tatwBkm71HHT3jmlEAvr6NFH38+v3s',
|
||||
'3w4Wl0/sdHyaeiSXAKCxJ4X1eOdN7L1rrbJozQ/gDCFuVQP/dcV6Ksss8Aw443jG',
|
||||
'AYBLHWh6o4GhAY6/h1kijF0xD+uc+tNmTQnQi1tEOoTeIZMXnSRwtk8XEuJkkbAP',
|
||||
'+uyvMgyV3wrk9zkaTAin7nrjAERxezFOdBEOtnB1CovJxtMn+RRxaMEGpC4GnETy',
|
||||
'N5+6FkLuLcNXiCQP75ajzOAN1aID/juNjUNpBbNpfqBV7j1K+Kn0n9HYTyQl9ghy',
|
||||
'026+/4c8ag2HV+bg3BD7c2VTVu9xBODHsfu0q8Ql/QB9W8tmYugU6DeXMHaeWPUH',
|
||||
'ph98guM9kF2yHIiRBvAd5i7wOjwn+I/Ir6nBR2yxJ3p31CDUnUlbjTPYg7mtQvHW',
|
||||
'EY2Cp4SWiJEEGBECAAkFAlERvJ4CGwIAUgkQtLvDtDKGtiVHIAQZEQIABgUCURG8',
|
||||
'ngAKCRAMiMeR296Y2SjyAJ9V3wRJJ2Szazqal4khWGfLu5R6/wCfQQIRD24yVdz8',
|
||||
'2a+2eCrwyALT2GAihACfS0nWM3a0gtITqngpJsRws+Ep+eIAn15qD2itutxNb8NI',
|
||||
'bR2gBB5QmVJ3',
|
||||
'=pGA6',
|
||||
'-----END PGP PUBLIC KEY BLOCK-----'
|
||||
].join("\n"));
|
||||
it('Import key pair', function(done) {
|
||||
// clear any keys already in the keychain
|
||||
keyring.clear();
|
||||
keyring.importKey(privkey);
|
||||
keyring.importKey(pubkey);
|
||||
done();
|
||||
});
|
||||
|
||||
var msg2 = openpgp.message.readArmored([
|
||||
'-----BEGIN PGP MESSAGE-----',
|
||||
'Version: GnuPG v1.4.11 (GNU/Linux)',
|
||||
'',
|
||||
'kA0DAAIRDIjHkdvemNkBrB1iB2Zvby50eHRREbz3VEVTVCBEQVRBIDEyMzQ1NohG',
|
||||
'BAARAgAGBQJREbz3AAoJEAyIx5Hb3pjZ2TcAn32LpDEuHe9QrSRlyvSuREKNOFwz',
|
||||
'AJ9zh4zsK4GIPuEu81YPNmHsju7DYg==',
|
||||
'=WaSx',
|
||||
'-----END PGP MESSAGE-----'
|
||||
].join("\n"));
|
||||
|
||||
it('Testing keyring getKeysForKeyId method', function (done) {
|
||||
var signingKeyIds = msg2.getSigningKeyIds();
|
||||
var key = keyring.getKeysForKeyId(signingKeyIds[0].toHex());
|
||||
it('getPublicKeyForAddress() - unknown address', function(done) {
|
||||
var key = keyring.getPublicKeyForAddress('nobody@example.com');
|
||||
expect(key).to.be.empty;
|
||||
done();
|
||||
});
|
||||
it('getPublicKeyForAddress() - valid address', function(done) {
|
||||
var key = keyring.getPublicKeyForAddress(user);
|
||||
expect(key).to.exist;
|
||||
expect(key).to.have.length(1);
|
||||
|
||||
var verified = msg2.verify(key);
|
||||
expect(verified).to.exist;
|
||||
expect(verified).to.have.length(1);
|
||||
expect(verified[0].valid).to.be.true;
|
||||
done();
|
||||
});
|
||||
it('getPrivateKeyForAddress() - unknown address', function(done) {
|
||||
var key = keyring.getPrivateKeyForAddress('nobody@example.com');
|
||||
expect(key).to.be.empty;
|
||||
done();
|
||||
});
|
||||
it('getPrivateKeyForAddress() - valid address', function(done) {
|
||||
var key = keyring.getPrivateKeyForAddress(user);
|
||||
expect(key).to.exist;
|
||||
done();
|
||||
});
|
||||
it('getKeysForKeyId() - unknown id', function(done) {
|
||||
var keys = keyring.getKeysForKeyId('000102030405060708');
|
||||
expect(keys).to.be.empty;
|
||||
done();
|
||||
});
|
||||
it('getKeysForKeyId() - valid id', function(done) {
|
||||
var keys = keyring.getKeysForKeyId(keyId.toLowerCase());
|
||||
expect(keys).to.exist.and.have.length(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
|
121
test/index.html
121
test/index.html
|
@ -1,121 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
|
||||
<!-- unit test -->
|
||||
<title>OpenPGP.js testpage</title>
|
||||
|
||||
<style>
|
||||
* {
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
#debug, #testoutput {
|
||||
border: 1px dotted #aaa;
|
||||
background-color: #eee;
|
||||
margin: 5px;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.successful {
|
||||
background-color: #afa;
|
||||
}
|
||||
.failed {
|
||||
background-color: #faa;
|
||||
}
|
||||
|
||||
#unittests {
|
||||
width: 98%;
|
||||
max-width: 99%;
|
||||
table-layout: fixed;
|
||||
word-wrap: break-word;
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
|
||||
#unittests tbody tr th {
|
||||
background-color: #eee;
|
||||
border: 1px dotted #aaa;
|
||||
}
|
||||
|
||||
#unittests tbody tr td {
|
||||
padding: 2px;
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
|
||||
.unittesttitle {
|
||||
font-weight: bold;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.unittestrow {
|
||||
border-top: 1px solid #aaa;
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
<script src="../resources/openpgp.js"></script>
|
||||
<script src="../resources/keyring.js"></script>
|
||||
<script src="lib/test-bundle.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
var test = require('unittests');
|
||||
|
||||
function unit_tests() {
|
||||
var table = document.getElementById('unittests');
|
||||
|
||||
var single_test = function() {
|
||||
var result = test.run();
|
||||
|
||||
var html = '<tr class="unittestrow"><td rowspan="' +
|
||||
result.tests.length + '" class="unittesttitle">' + result.title + '</td>';
|
||||
|
||||
|
||||
for (var i in result.tests) {
|
||||
html += (i != 0 ?
|
||||
'<tr>' : '')
|
||||
+ '<td>' + result.tests[i].description
|
||||
+ '</td><td ' + (result.tests[i].result ?
|
||||
'class="successful">PASSED</td>' :
|
||||
'class="failed">FAILED</td>')
|
||||
+ '</tr>';
|
||||
}
|
||||
|
||||
table.innerHTML += html;
|
||||
|
||||
if(test.tests.length > 0) {
|
||||
setTimeout(single_test, 100);
|
||||
}
|
||||
}
|
||||
|
||||
single_test();
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<a href="index.html">Unit Tests</a> |
|
||||
<a href="parser.html">Parser</a> |
|
||||
<a href="encryption.html">Encryption / Decryption</a> |
|
||||
<a href="coverage.html">Coverage</a>
|
||||
|
||||
<h1>Unit tests</h1>
|
||||
|
||||
<table id="unittests">
|
||||
<colgroup>
|
||||
<col style="width: 20%;">
|
||||
<col>
|
||||
<col style="width: 5%;">
|
||||
</colgroup>
|
||||
<tr><th>Test</th><th>Description</th><th>Result</th></tr>
|
||||
</table>
|
||||
|
||||
<br>
|
||||
<button type="submit" onmousedown="unit_tests();">Run unit tests</button>
|
||||
|
||||
<!-- src/util/util.js print_debug() writes to -->
|
||||
<h2>Messages</h2>
|
||||
<div id="debug"></div>
|
||||
</body>
|
||||
</html>
|
|
@ -1,20 +0,0 @@
|
|||
|
||||
module.exports = require('./unit.js');
|
||||
|
||||
require('./crypto/hash/sha.js');
|
||||
require('./crypto/hash/md5.js');
|
||||
require('./crypto/hash/ripemd.js');
|
||||
|
||||
require('./crypto/cipher/aes.js');
|
||||
require('./crypto/cipher/blowfish.js');
|
||||
require('./crypto/cipher/cast5.js');
|
||||
require('./crypto/cipher/des.js');
|
||||
require('./crypto/cipher/twofish.js');
|
||||
|
||||
require('./crypto/crypto.js');
|
||||
|
||||
require('./general/basic.js');
|
||||
require('./general/key.js');
|
||||
require('./general/keyring.js');
|
||||
require('./general/packet.js');
|
||||
require('./general/signature.js');
|
|
@ -1,6 +0,0 @@
|
|||
|
||||
module.exports = require('./unit.js');
|
||||
|
||||
require('./test-all.js');
|
||||
|
||||
module.exports.run_all();
|
48
test/unit.js
48
test/unit.js
|
@ -1,48 +0,0 @@
|
|||
|
||||
module.exports = {
|
||||
tests: [],
|
||||
register: function(str_title, func_runtest) {
|
||||
this.tests.push({ title: str_title, run: func_runtest });
|
||||
},
|
||||
|
||||
run: function() {
|
||||
var test = this.tests.shift();
|
||||
|
||||
var result = {
|
||||
title: test.title
|
||||
};
|
||||
|
||||
|
||||
result.tests = test.run();
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
run_all: function() {
|
||||
var passed = true;
|
||||
|
||||
while(this.tests.length > 0) {
|
||||
var result = this.run();
|
||||
|
||||
console.log('Test: ' + result.title);
|
||||
|
||||
for(var i in result.tests) {
|
||||
|
||||
var res = result.tests[i].result ?
|
||||
'SUCCESS' : 'FAILED';
|
||||
|
||||
console.log(result.tests[i].description + ' ' + res);
|
||||
|
||||
passed = passed && result.tests[i].result;
|
||||
}
|
||||
}
|
||||
|
||||
if(!passed) process.exit(1);
|
||||
},
|
||||
|
||||
result: function(str_description, boolean_result) {
|
||||
this.description = str_description;
|
||||
this.result = boolean_result;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>OpenPGPJS Continuous Integration Tests</title>
|
||||
<title>OpenPGPJS Unit Tests</title>
|
||||
<link rel="stylesheet" href="lib/mocha.css" />
|
||||
|
||||
</head>
|
||||
|
@ -13,14 +13,13 @@
|
|||
<script src="../resources/openpgp.js"></script>
|
||||
<script src="../resources/keyring.js"></script>
|
||||
<script src="lib/chai.js"></script>
|
||||
<script src="lib/sinon.js"></script>
|
||||
<script src="lib/mocha.js"></script>
|
||||
<script>
|
||||
mocha.setup('bdd');
|
||||
</script>
|
||||
<script src="lib/ci-tests-bundle.js"></script>
|
||||
<script src="lib/unittests-bundle.js"></script>
|
||||
<script>
|
||||
require('ci-tests');
|
||||
require('unittests');
|
||||
if (window.mochaPhantomJS) {
|
||||
mochaPhantomJS.run();
|
||||
} else {
|
4
test/unittests.js
Normal file
4
test/unittests.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
describe('Unit Tests', function () {
|
||||
require('./general');
|
||||
require('./crypto');
|
||||
});
|
Loading…
Reference in New Issue
Block a user