commit
0060c9a0c9
25 changed files with 216 additions and 35 deletions
|
|
@ -14,6 +14,19 @@ describe('crypto utils', function() {
|
|||
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() {
|
||||
var key = 'My secret key';
|
||||
var message = 'My secret message';
|
||||
|
|
@ -22,6 +35,17 @@ describe('crypto utils', function() {
|
|||
|
||||
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 = [
|
||||
{
|
||||
|
|
@ -55,6 +79,11 @@ describe('crypto utils', function() {
|
|||
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);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
|
|
|||
89
test/util.http.js
Normal file
89
test/util.http.js
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
'use strict';
|
||||
|
||||
var _ = require('lodash');
|
||||
var chai = chai || require('chai');
|
||||
var sinon = sinon || require('sinon');
|
||||
var should = chai.should();
|
||||
var httpUtils = require('../js/util/HTTP');
|
||||
describe('http utils', function() {
|
||||
|
||||
var xhr;
|
||||
beforeEach(function() {
|
||||
xhr = {
|
||||
open: sinon.stub(),
|
||||
getAllResponseHeaders: sinon.stub().returns('Content-type: xx'),
|
||||
setRequestHeader: sinon.stub().returns(),
|
||||
send: function() {
|
||||
var self = this;
|
||||
setTimeout(function() {
|
||||
self.response = 'test';
|
||||
self.error ? self.onerror() : self.onload();
|
||||
}, 10);
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
it('should get success', function(done) {
|
||||
xhr.error = 0;
|
||||
httpUtils.request({
|
||||
xhr: xhr,
|
||||
method: 'GET',
|
||||
url: 'http://test'
|
||||
}).success(function(data, status) {
|
||||
done();
|
||||
}).error(function(data, status) {
|
||||
throw new Error();
|
||||
});
|
||||
});
|
||||
it('should get error', function(done) {
|
||||
xhr.error = 1;
|
||||
httpUtils.request({
|
||||
xhr: xhr,
|
||||
method: 'GET',
|
||||
url: 'http://test',
|
||||
}).success(function(data, status) {
|
||||
throw new Error();
|
||||
}).error(function(data, status) {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should get with headers', function(done) {
|
||||
xhr.error = 0;
|
||||
httpUtils.request({
|
||||
xhr: xhr,
|
||||
method: 'GET',
|
||||
url: 'http://test',
|
||||
headers: {
|
||||
'Content-Transfer-Encoding': 'a',
|
||||
'Content-Length': 1,
|
||||
'X-test': 2,
|
||||
}
|
||||
}).success(function(data, status) {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('should get with body', function(done) {
|
||||
xhr.error = 0;
|
||||
httpUtils.request({
|
||||
xhr: xhr,
|
||||
method: 'GET',
|
||||
url: 'http://test',
|
||||
body: 'hola',
|
||||
responseType: 'type',
|
||||
}).success(function(data, status) {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('should get with default error', function() {
|
||||
xhr.error = 1;
|
||||
|
||||
var ret = httpUtils.request({
|
||||
xhr: xhr,
|
||||
method: 'GET',
|
||||
url: 'http://test',
|
||||
});
|
||||
ret._error.should.throw()
|
||||
});
|
||||
|
||||
});
|
||||
41
test/util.log.js
Normal file
41
test/util.log.js
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
'use strict';
|
||||
|
||||
var _ = require('lodash');
|
||||
var chai = chai || require('chai');
|
||||
var sinon = sinon || require('sinon');
|
||||
var should = chai.should();
|
||||
var log = require('../js/util/log');
|
||||
|
||||
describe('log utils', function() {
|
||||
afterEach(function() {
|
||||
log.setLevel('info');
|
||||
});
|
||||
|
||||
it('should log fatal', function() {
|
||||
if (console.warn.restore)
|
||||
console.warn.restore();
|
||||
|
||||
sinon.stub(console,'warn');
|
||||
|
||||
log.setLevel('debug');
|
||||
log.warn('hola');
|
||||
|
||||
var arg = console.warn.getCall(0).args[0];
|
||||
arg.should.contain('util.log.js');
|
||||
arg.should.contain('hola');
|
||||
console.warn.restore();
|
||||
});
|
||||
|
||||
it('should not log debug', function() {
|
||||
sinon.stub(console,'log');
|
||||
log.setLevel('info');
|
||||
log.debug('hola');
|
||||
console.log.called.should.equal(false);
|
||||
console.log.restore();
|
||||
});
|
||||
|
||||
it('should log debug', function() {
|
||||
log.getLevels().debug.should.equal(0);
|
||||
log.getLevels().fatal.should.equal(5);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue