add tests to getSEssionId

This commit is contained in:
Matias Alejo Garcia 2014-08-15 10:35:25 -04:00
commit 5753f406e0
2 changed files with 210 additions and 198 deletions

View file

@ -100,7 +100,7 @@ Storage.prototype.removeGlobal = function(k) {
Storage.prototype.getSessionId = function() { Storage.prototype.getSessionId = function() {
var sessionId = this.sessionStorage.getItem('sessionId'); var sessionId = this.sessionStorage.getItem('sessionId');
if (!sessionId) { if (!sessionId) {
sessionId = bitcore.getRandomBuffer(8).toString('hex'); sessionId = bitcore.SecureRandom.getRandomBuffer(8).toString('hex');
this.sessionStorage.setItem(sessionId, 'sessionId'); this.sessionStorage.setItem(sessionId, 'sessionId');
} }
return sessionId; return sessionId;

View file

@ -19,8 +19,7 @@ CryptoJS.AES.decrypt = function(a) {
'use strict'; 'use strict';
var chai = chai || require('chai'); var chai = chai || require('chai');
var should = chai.should(); var should = chai.should();
var is_browser = typeof process == 'undefined' var is_browser = typeof process == 'undefined' || typeof process.versions === 'undefined';
|| typeof process.versions === 'undefined';
if (is_browser) { if (is_browser) {
var copay = require('copay'); //browser var copay = require('copay'); //browser
} else { } else {
@ -269,4 +268,17 @@ var is_browser = typeof process == 'undefined'
should.not.exist(s.getGlobal('a')); should.not.exist(s.getGlobal('a'));
}); });
}); });
describe('session storage', function() {
it('should get a session ID', function() {
var s = new LocalEncrypted({
localStorage: localMock,
sessionStorage: sessionMock,
password: 'password'
});
s.getSessionId().length.should.equal(16);
(new Buffer(s.getSessionId(),'hex')).length.should.equal(8);
});
});
}); });