add test to crypto
This commit is contained in:
parent
b3b0d7903e
commit
b0cb2da3ec
4 changed files with 36 additions and 3 deletions
|
|
@ -5,6 +5,7 @@ var preconditions = require('preconditions').singleton();
|
||||||
var inherits = require('inherits');
|
var inherits = require('inherits');
|
||||||
var events = require('events');
|
var events = require('events');
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
|
var request = require('request');
|
||||||
|
|
||||||
var bitcore = require('bitcore');
|
var bitcore = require('bitcore');
|
||||||
var BIP21 = bitcore.BIP21;
|
var BIP21 = bitcore.BIP21;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
var preconditions = require('preconditions').singleton();
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
request: function(options, callback) {
|
request: function(options, callback) {
|
||||||
preconditions.checkArgument(_.isObject(options));
|
preconditions.checkArgument(_.isObject(options));
|
||||||
|
|
@ -25,9 +27,9 @@ module.exports = {
|
||||||
var req = options;
|
var req = options;
|
||||||
|
|
||||||
req.headers = req.headers || {};
|
req.headers = req.headers || {};
|
||||||
req.body = req.body || req.data || {};
|
req.body = req.body || req.data || '';
|
||||||
|
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = options.xhr || new XMLHttpRequest();
|
||||||
xhr.open(method, url, true);
|
xhr.open(method, url, true);
|
||||||
|
|
||||||
Object.keys(req.headers).forEach(function(key) {
|
Object.keys(req.headers).forEach(function(key) {
|
||||||
|
|
@ -51,6 +53,7 @@ module.exports = {
|
||||||
headers[$1.toLowerCase()] = $2;
|
headers[$1.toLowerCase()] = $2;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return ret._success(buf, xhr.status, headers, options);
|
return ret._success(buf, xhr.status, headers, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node server.js",
|
"start": "node server.js",
|
||||||
"coverage": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --reporter spec test",
|
"coverage": "./node_modules/.bin/istanbul cover -x lib/sjcl.js ./node_modules/.bin/_mocha -- --reporter spec test",
|
||||||
"test": "sh test/run.sh",
|
"test": "sh test/run.sh",
|
||||||
"dist": "node shell/scripts/dist.js",
|
"dist": "node shell/scripts/dist.js",
|
||||||
"shell": "node shell/scripts/launch.js",
|
"shell": "node shell/scripts/launch.js",
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,19 @@ describe('crypto utils', function() {
|
||||||
decrypted.should.equal(message);
|
decrypted.should.equal(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('should decrypt what it encrypts (JSON)', function() {
|
||||||
|
|
||||||
|
var key = 'My secret key';
|
||||||
|
var message = {'hola': 'picho'};
|
||||||
|
var encrypted = cryptoUtils.encrypt(key, message);
|
||||||
|
var decrypted = cryptoUtils.decrypt(key, encrypted);
|
||||||
|
|
||||||
|
JSON.parse(decrypted).should.deep.equal(message);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
it('should return null if the provided key cant decrypt', function() {
|
it('should return null if the provided key cant decrypt', function() {
|
||||||
var key = 'My secret key';
|
var key = 'My secret key';
|
||||||
var message = 'My secret message';
|
var message = 'My secret message';
|
||||||
|
|
@ -22,6 +35,17 @@ describe('crypto utils', function() {
|
||||||
|
|
||||||
assert(decrypted === null);
|
assert(decrypted === null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
it('should sign a message', function() {
|
||||||
|
var key = 'My secret key';
|
||||||
|
var message = 'My secret message';
|
||||||
|
var signature = cryptoUtils.hmac(key, message);
|
||||||
|
signature.should.be.equal('6tpegxYl/Eig9k1Lla8b8G8OcdtOxyNbDsdyic1Yzh4=');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var tests = [
|
var tests = [
|
||||||
{
|
{
|
||||||
|
|
@ -55,6 +79,11 @@ describe('crypto utils', function() {
|
||||||
phrase.should.equal(expected);
|
phrase.should.equal(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it('should generate a passphrase using default salt/iter', function() {
|
||||||
|
var phrase = cryptoUtils.kdf('Pwd123!@#$%^&*(){}[]\|/?.>,<=+-_`~åéþ䲤þçæ¶');
|
||||||
|
var expected = 'ml+mMtjgcvL2pdfDwQqW2qONRNjZ3YD8KnGeV3aFjyOoM0ByOmoREw9zBvowC/ZXsfrezbRXX/W/XIzKOqdrXA==';
|
||||||
|
phrase.should.equal(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue