writing test for scriptLocation function, fixing non-removed query separator bug

This commit is contained in:
El RIDO 2017-02-05 16:45:11 +01:00
parent 5442af6e20
commit 80f7baa604
No known key found for this signature in database
GPG key ID: 0F5C940A6BD81F92
2 changed files with 39 additions and 16 deletions

View file

@ -259,7 +259,8 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
var scriptLocation = window.location.href.substring( var scriptLocation = window.location.href.substring(
0, 0,
window.location.href.length - window.location.search.length - window.location.hash.length window.location.href.length - window.location.search.length - window.location.hash.length
), hashIndex = scriptLocation.indexOf('#'); ),
hashIndex = scriptLocation.indexOf('?');
if (hashIndex !== -1) if (hashIndex !== -1)
{ {
scriptLocation = scriptLocation.substring(0, hashIndex); scriptLocation = scriptLocation.substring(0, hashIndex);

View file

@ -1,22 +1,20 @@
'use strict'; 'use strict';
var jsc = require('jsverify'); var jsc = require('jsverify'),
jsdom = require('jsdom-global'),
before(function () { cleanup = jsdom();
this.jsdom = require('jsdom-global')(); global.$ = global.jQuery = require('./jquery-3.1.1');
global.$ = global.jQuery = require('./jquery-3.1.1'); global.sjcl = require('./sjcl-1.0.6');
global.sjcl = require('./sjcl-1.0.6'); global.Base64 = require('./base64-2.1.9');
global.Base64 = require('./base64-2.1.9'); global.RawDeflate = require('./rawdeflate-0.5');
global.RawDeflate = require('./rawdeflate-0.5'); require('./rawinflate-0.3');
require('./rawinflate-0.3'); require('./privatebin');
require('./privatebin');
})
after(function () {
this.jsdom();
})
describe('helper', function () { describe('helper', function () {
describe('secondsToHuman', function () { describe('secondsToHuman', function () {
after(function () {
cleanup();
});
jsc.property('returns an array with a number and a word', 'integer', function (number) { jsc.property('returns an array with a number and a word', 'integer', function (number) {
var result = $.PrivateBin.helper.secondsToHuman(number); var result = $.PrivateBin.helper.secondsToHuman(number);
return Array.isArray(result) && return Array.isArray(result) &&
@ -56,5 +54,29 @@ describe('helper', function () {
return $.PrivateBin.helper.secondsToHuman(number)[1] === 'month'; return $.PrivateBin.helper.secondsToHuman(number)[1] === 'month';
}); });
}); });
describe('scriptLocation', function () {
after(function () {
cleanup();
});
var a2zString = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'],
alnumString = a2zString.concat(['0','1','2','3','4','5','6','7','8','9']),
queryString = alnumString.concat(['+','%','&','.','*','-','_']);
jsc.property(
'returns the URL without query & fragment',
jsc.nearray(jsc.elements(a2zString)),
jsc.nearray(jsc.elements(a2zString)),
jsc.array(jsc.elements(queryString)),
'string',
function (schema, address, query, fragment) {
var expected = schema.join('') + '://' + address.join('') + '/',
clean = jsdom('', {url: expected + '?' + query.join('') + '#' + fragment}),
result = $.PrivateBin.helper.scriptLocation();
clean();
return expected === result;
}
);
});
}); });