Initial support for node.js testing.
This commit is contained in:
parent
c77a17cf31
commit
7d6cc3c771
5
.travis.yml
Normal file
5
.travis.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
language: node_js
|
||||
|
||||
node_js:
|
||||
- 0.10
|
||||
|
8
Makefile
8
Makefile
|
@ -31,10 +31,10 @@ lint:
|
|||
@./scripts/lint.sh
|
||||
|
||||
bundle:
|
||||
@browserify -d -r ./src:openpgp > ./resources/openpgp.js
|
||||
minify:
|
||||
@echo See http://code.google.com/closure/compiler/
|
||||
@./scripts/minimize.sh
|
||||
@browserify -d -r ./:openpgp > ./resources/openpgp.js
|
||||
|
||||
bundle-test:
|
||||
@browserify -d -r ./test/test-all.js:test-bundle.js > ./test/test-bundle.js
|
||||
|
||||
test:
|
||||
@echo to be implemented
|
||||
|
|
9
package.json
Normal file
9
package.json
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"name": "openpgp",
|
||||
"version": "0.0.1",
|
||||
"main": "./src/index.js",
|
||||
"scripts": {
|
||||
"install": "make bundle",
|
||||
"test": "node ./test/test.js"
|
||||
}
|
||||
}
|
3452
resources/openpgp.js
3452
resources/openpgp.js
File diff suppressed because one or more lines are too long
|
@ -99,18 +99,19 @@ function am3(i,x,w,j,c,n) {
|
|||
}
|
||||
return c;
|
||||
}
|
||||
if(j_lm && (navigator.appName == "Microsoft Internet Explorer")) {
|
||||
/*if(j_lm && (navigator != undefined &&
|
||||
navigator.appName == "Microsoft Internet Explorer")) {
|
||||
BigInteger.prototype.am = am2;
|
||||
dbits = 30;
|
||||
}
|
||||
else if(j_lm && (navigator.appName != "Netscape")) {
|
||||
else if(j_lm && (navigator != undefined && navigator.appName != "Netscape")) {*/
|
||||
BigInteger.prototype.am = am1;
|
||||
dbits = 26;
|
||||
}
|
||||
/*}
|
||||
else { // Mozilla/Netscape seems to prefer am3
|
||||
BigInteger.prototype.am = am3;
|
||||
dbits = 28;
|
||||
}
|
||||
}*/
|
||||
|
||||
BigInteger.prototype.DB = dbits;
|
||||
BigInteger.prototype.DM = ((1<<dbits)-1);
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"name": "openpgpjs",
|
||||
"version": "0.0.1",
|
||||
"main": "./index.js"
|
||||
}
|
|
@ -251,6 +251,10 @@ function packet_secret_key() {
|
|||
this.mpi = this.mpi.concat(parse_cleartext_mpi(hash, cleartext,
|
||||
this.algorithm));
|
||||
}
|
||||
|
||||
this.generate = function(bits) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
Create test cases here
|
File diff suppressed because one or more lines are too long
BIN
test/crypto/hash/.md5.js.swp
Normal file
BIN
test/crypto/hash/.md5.js.swp
Normal file
Binary file not shown.
|
@ -1,21 +1,24 @@
|
|||
var unit = require('../../unit.js')
|
||||
|
||||
unittests.register("MD5 test with test vectors from RFC 1321", function() {
|
||||
var openpgp = require('openpgp'),
|
||||
|
||||
|
||||
unit.register("MD5 test with test vectors from RFC 1321", function() {
|
||||
var openpgp = require('../../../'),
|
||||
util = openpgp.util,
|
||||
MD5 = openpgp.hash.md5;
|
||||
|
||||
var result = new Array();
|
||||
result[0] = new test_result("MD5 (\"\") = d41d8cd98f00b204e9800998ecf8427e",
|
||||
result[0] = new unit.result("MD5 (\"\") = d41d8cd98f00b204e9800998ecf8427e",
|
||||
util.hexstrdump(MD5("")) == "d41d8cd98f00b204e9800998ecf8427e");
|
||||
result[1] = new test_result("MD5 (\"a\") = 0cc175b9c0f1b6a831c399e269772661",
|
||||
result[1] = new unit.result("MD5 (\"a\") = 0cc175b9c0f1b6a831c399e269772661",
|
||||
util.hexstrdump(MD5 ("abc")) == "900150983cd24fb0d6963f7d28e17f72");
|
||||
result[2] = new test_result("MD5 (\"message digest\") = f96b697d7cb7938d525a2f31aaf161d0",
|
||||
result[2] = new unit.result("MD5 (\"message digest\") = f96b697d7cb7938d525a2f31aaf161d0",
|
||||
util.hexstrdump(MD5 ("message digest")) == "f96b697d7cb7938d525a2f31aaf161d0");
|
||||
result[3] = new test_result("MD5 (\"abcdefghijklmnopqrstuvwxyz\") = c3fcd3d76192e4007dfb496cca67e13b",
|
||||
result[3] = new unit.result("MD5 (\"abcdefghijklmnopqrstuvwxyz\") = c3fcd3d76192e4007dfb496cca67e13b",
|
||||
util.hexstrdump(MD5 ("abcdefghijklmnopqrstuvwxyz")) == "c3fcd3d76192e4007dfb496cca67e13b");
|
||||
result[4] = new test_result("MD5 (\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\") = d174ab98d277d9f5a5611c2c9f419d9f",
|
||||
result[4] = new unit.result("MD5 (\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\") = d174ab98d277d9f5a5611c2c9f419d9f",
|
||||
util.hexstrdump(MD5 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")) == "d174ab98d277d9f5a5611c2c9f419d9f");
|
||||
result[5] = new test_result("MD5 (\"12345678901234567890123456789012345678901234567890123456789012345678901234567890\") = 57edf4a22be3c955ac49da2e2107b67a",
|
||||
result[5] = new unit.result("MD5 (\"12345678901234567890123456789012345678901234567890123456789012345678901234567890\") = 57edf4a22be3c955ac49da2e2107b67a",
|
||||
util.hexstrdump(MD5 ("12345678901234567890123456789012345678901234567890123456789012345678901234567890")) == "57edf4a22be3c955ac49da2e2107b67a");
|
||||
return result;
|
||||
});
|
|
@ -1,18 +1,19 @@
|
|||
var unit = require('../../unit.js');
|
||||
|
||||
unittests.register("RIPE-MD 160 bits test with test vectors from http://homes.esat.kuleuven.be/~bosselae/ripemd160.html", function() {
|
||||
unit.register("RIPE-MD 160 bits test with test vectors from http://homes.esat.kuleuven.be/~bosselae/ripemd160.html", function() {
|
||||
|
||||
var openpgp = require('openpgp'),
|
||||
var openpgp = require('../../../'),
|
||||
util = openpgp.util,
|
||||
RMDstring = openpgp.hash.ripemd;
|
||||
|
||||
var result = new Array();
|
||||
result[0] = new test_result("RMDstring (\"\") = 9c1185a5c5e9fc54612808977ee8f548b2258d31",
|
||||
result[0] = new unit.result("RMDstring (\"\") = 9c1185a5c5e9fc54612808977ee8f548b2258d31",
|
||||
util.hexstrdump(RMDstring("")) == "9c1185a5c5e9fc54612808977ee8f548b2258d31");
|
||||
result[1] = new test_result("RMDstring (\"a\") = 0bdc9d2d256b3ee9daae347be6f4dc835a467ffe",
|
||||
result[1] = new unit.result("RMDstring (\"a\") = 0bdc9d2d256b3ee9daae347be6f4dc835a467ffe",
|
||||
util.hexstrdump(RMDstring("a")) == "0bdc9d2d256b3ee9daae347be6f4dc835a467ffe");
|
||||
result[2] = new test_result("RMDstring (\"abc\") = 8eb208f7e05d987a9b044a8e98c6b087f15a0bfc",
|
||||
result[2] = new unit.result("RMDstring (\"abc\") = 8eb208f7e05d987a9b044a8e98c6b087f15a0bfc",
|
||||
util.hexstrdump(RMDstring("abc")) == "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc");
|
||||
result[3] = new test_result("RMDstring (\"message digest\") = 5d0689ef49d2fae572b881b123a85ffa21595f36",
|
||||
result[3] = new unit.result("RMDstring (\"message digest\") = 5d0689ef49d2fae572b881b123a85ffa21595f36",
|
||||
util.hexstrdump(RMDstring("message digest")) == "5d0689ef49d2fae572b881b123a85ffa21595f36");
|
||||
return result;
|
||||
});
|
|
@ -1,31 +1,32 @@
|
|||
var unit = require('../../unit.js');
|
||||
|
||||
|
||||
unittests.register("SHA* test with test vectors from NIST FIPS 180-2", function() {
|
||||
var openpgp = require('openpgp'),
|
||||
unit.register("SHA* test with test vectors from NIST FIPS 180-2", function() {
|
||||
var openpgp = require('../../../'),
|
||||
util = openpgp.util,
|
||||
hash = openpgp.hash;
|
||||
|
||||
var result = new Array();
|
||||
|
||||
result[0] = new test_result("SHA1 - a9993e364706816aba3e25717850c26c9cd0d89d = hash.sha1(\"abc\") ",
|
||||
result[0] = new unit.result("SHA1 - a9993e364706816aba3e25717850c26c9cd0d89d = hash.sha1(\"abc\") ",
|
||||
"a9993e364706816aba3e25717850c26c9cd0d89d" == util.hexstrdump(hash.sha1("abc")));
|
||||
result[1] = new test_result("SHA1 - 84983e441c3bd26ebaae4aa1f95129e5e54670f1 = hash.sha1(\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\") ",
|
||||
result[1] = new unit.result("SHA1 - 84983e441c3bd26ebaae4aa1f95129e5e54670f1 = hash.sha1(\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\") ",
|
||||
"84983e441c3bd26ebaae4aa1f95129e5e54670f1" == util.hexstrdump(hash.sha1("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")));
|
||||
result[2] = new test_result("SHA224 - 23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7 = hash.sha224(\"abc\") ",
|
||||
result[2] = new unit.result("SHA224 - 23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7 = hash.sha224(\"abc\") ",
|
||||
"23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7" == util.hexstrdump(hash.sha224("abc")));
|
||||
result[3] = new test_result("SHA224 - 75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525 = hash.sha224(\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\") ",
|
||||
result[3] = new unit.result("SHA224 - 75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525 = hash.sha224(\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\") ",
|
||||
"75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525" == util.hexstrdump(hash.sha224("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")));
|
||||
result[4] = new test_result("SHA256 - ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad = hash.sha256(\"abc\") ",
|
||||
result[4] = new unit.result("SHA256 - ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad = hash.sha256(\"abc\") ",
|
||||
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" == util.hexstrdump(hash.sha256("abc")));
|
||||
result[5] = new test_result("SHA256 - 248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1 = hash.sha256(\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\") ",
|
||||
result[5] = new unit.result("SHA256 - 248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1 = hash.sha256(\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\") ",
|
||||
"248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1" == util.hexstrdump(hash.sha256("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")));
|
||||
result[6] = new test_result("SHA384 - cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7 = hash.sha384(\"abc\") ",
|
||||
result[6] = new unit.result("SHA384 - cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7 = hash.sha384(\"abc\") ",
|
||||
"cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7" == util.hexstrdump(hash.sha384("abc")));
|
||||
result[7] = new test_result("SHA384 - 3391fdddfc8dc7393707a65b1b4709397cf8b1d162af05abfe8f450de5f36bc6b0455a8520bc4e6f5fe95b1fe3c8452b = str384(\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\") ",
|
||||
result[7] = new unit.result("SHA384 - 3391fdddfc8dc7393707a65b1b4709397cf8b1d162af05abfe8f450de5f36bc6b0455a8520bc4e6f5fe95b1fe3c8452b = str384(\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\") ",
|
||||
"3391fdddfc8dc7393707a65b1b4709397cf8b1d162af05abfe8f450de5f36bc6b0455a8520bc4e6f5fe95b1fe3c8452b" == util.hexstrdump(hash.sha384("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")));
|
||||
result[8] = new test_result("SHA512 - ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f = hash.sha512(\"abc\") ",
|
||||
result[8] = new unit.result("SHA512 - ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f = hash.sha512(\"abc\") ",
|
||||
"ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f" == util.hexstrdump(hash.sha512("abc")));
|
||||
result[9] = new test_result("SHA512 - 204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445 = hash.sha512(\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\") ",
|
||||
result[9] = new unit.result("SHA512 - 204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445 = hash.sha512(\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\") ",
|
||||
"204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445" == util.hexstrdump(hash.sha512("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")));
|
||||
return result;
|
||||
});
|
|
@ -2,27 +2,8 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<script type="text/javascript" src="../resources/openpgp.js"></script>
|
||||
|
||||
<!-- unit test -->
|
||||
<script type="text/javascript" src="unittest.js"></script>
|
||||
<script type="text/javascript" src="example-test.js"></script>
|
||||
|
||||
<script type="text/javascript" src="ciphers/hash/md5.js"></script>
|
||||
<script type="text/javascript" src="ciphers/hash/sha.js"></script>
|
||||
<script type="text/javascript" src="ciphers/hash/ripe-md.js"></script>
|
||||
<script type="text/javascript" src="ciphers/symmetric/aes.js"></script>
|
||||
<script type="text/javascript" src="ciphers/symmetric/cast5.js"></script>
|
||||
<script type="text/javascript" src="ciphers/symmetric/des.js"></script>
|
||||
<script type="text/javascript" src="ciphers/symmetric/blowfish.js"></script>
|
||||
<script type="text/javascript" src="ciphers/symmetric/twofish.js"></script>
|
||||
|
||||
<script type="text/javascript" src="general/packet.js"></script>
|
||||
|
||||
<script type="text/javascript" src="ciphers/openpgp.crypto.js"></script>
|
||||
<script type="text/javascript" src="ciphers/openpgp.sigcheck.js"></script>
|
||||
|
||||
<script type="text/javascript" src="general/openpgp.basic.js"></script>
|
||||
<script type="text/javascript" src="test-bundle.js"></script>
|
||||
<title>OpenPGP.js testpage</title>
|
||||
|
||||
<style>
|
||||
|
@ -76,14 +57,14 @@
|
|||
</style>
|
||||
<script type="text/javascript">
|
||||
|
||||
require('openpgp').util.debug = true;
|
||||
|
||||
var test = require('test-bundle.js');
|
||||
|
||||
function unit_tests() {
|
||||
var table = document.getElementById('unittests');
|
||||
|
||||
var single_test = function() {
|
||||
var result = unittests.run();
|
||||
var result = test.run();
|
||||
|
||||
var html = '<tr class="unittestrow"><td rowspan="' +
|
||||
result.tests.length + '" class="unittesttitle">' + result.title + '</td>';
|
||||
|
@ -101,7 +82,7 @@ function unit_tests() {
|
|||
|
||||
table.innerHTML += html;
|
||||
|
||||
if(unittests.tests.length > 0) {
|
||||
if(test.tests.length > 0) {
|
||||
setTimeout(single_test, 100);
|
||||
}
|
||||
}
|
||||
|
|
7
test/test-all.js
Normal file
7
test/test-all.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
|
||||
module.exports = require('./unit.js');
|
||||
|
||||
require('./crypto/hash/sha.js');
|
||||
require('./crypto/hash/md5.js');
|
||||
require('./crypto/hash/ripemd.js');
|
||||
|
11992
test/test-bundle.js
Normal file
11992
test/test-bundle.js
Normal file
File diff suppressed because one or more lines are too long
6
test/test.js
Normal file
6
test/test.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
module.exports = require('./unit.js');
|
||||
|
||||
require('./test-all.js');
|
||||
|
||||
module.exports.run_all();
|
48
test/unit.js
Normal file
48
test/unit.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
|
||||
var unittests = {
|
||||
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
|
||||
};
|
||||
|
||||
|
||||
//try
|
||||
{
|
||||
result.tests = test.run();
|
||||
}
|
||||
/*catch(e)
|
||||
{
|
||||
result.tests = [{
|
||||
description: 'Failed with an exception: ' + e,
|
||||
result: false
|
||||
}];
|
||||
}*/
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
function test_result(str_description, boolean_result) {
|
||||
this.description = str_description;
|
||||
this.result = boolean_result;
|
||||
}
|
Loading…
Reference in New Issue
Block a user