add tests

This commit is contained in:
Gordon Hall 2014-06-25 14:15:41 -04:00
parent 75b77019c4
commit ca3e3dd3f3
2 changed files with 86 additions and 1 deletions

View File

@ -13,6 +13,7 @@
],
"scripts": {
"make-dist": "sh scripts/make-dist.sh",
"test": "node_modules/.bin/mocha test/* --reporter spec",
"postinstall": "npm run make-dist"
},
"main": "index.js",
@ -26,6 +27,8 @@
},
"devDependencies": {
"uglify-js": "~2.4.14",
"browserify": "~4.1.11"
"browserify": "~4.1.11",
"should": "~4.0.4",
"mocha": "~1.20.1"
}
}

82
test/bitauth.js Normal file
View File

@ -0,0 +1,82 @@
var should = require('should');
var bitauth = require('../index');
describe('bitauth', function() {
var keys = null;
var contract = 'keyboard cat';
var secret = 'o hai, nsa. how i do teh cryptos?';
var password = 's4705hiru13z!';
var signature = null;
var enc = null;
describe('#generateSin', function() {
it('should generate a sin object', function(done) {
keys = bitauth.generateSin();
should.exist(keys);
should.exist(keys.pub);
should.exist(keys.priv);
should.exist(keys.sin);
done();
});
});
describe('#getPublicKeyFromPrivateKey', function() {
it('should properly get the public key', function(done) {
bitauth.getPublicKeyFromPrivateKey(keys.priv).should.equal(keys.pub);
done();
});
});
describe('#getSinFromPublicKey', function() {
it('should properly get the sin', function(done) {
bitauth.getSinFromPublicKey(keys.pub).should.equal(keys.sin);
done();
});
});
describe('#sign', function() {
it('should sign the string', function(done) {
signature = bitauth.sign(contract, keys.priv);
should.exist(signature);
done();
});
});
describe('#verifySignature', function() {
it('should verify the signature', function(done) {
bitauth.verifySignature(contract, keys.pub, signature, done);
});
});
describe('#encrypt', function() {
it('should encrypt the secret message', function(done) {
enc = bitauth.encrypt(password, secret);
should.exist(enc);
done();
});
});
describe('#decrypt', function() {
it('should decrypt the secret message', function(done) {
var dec = bitauth.decrypt(password, enc);
should.exist(dec);
done();
});
});
});