|
@@ -11,7 +11,9 @@ var jsc = require('jsverify'),
|
|
|
a2zString.map(function(c) {
|
|
a2zString.map(function(c) {
|
|
|
return c.toUpperCase();
|
|
return c.toUpperCase();
|
|
|
})
|
|
})
|
|
|
- );
|
|
|
|
|
|
|
+ ),
|
|
|
|
|
+ // schemas supported by the whatwg-url library
|
|
|
|
|
+ schemas = ['ftp','gopher','http','https','ws','wss'];
|
|
|
|
|
|
|
|
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');
|
|
@@ -20,75 +22,101 @@ global.RawDeflate = require('./rawdeflate-0.5');
|
|
|
require('./rawinflate-0.3');
|
|
require('./rawinflate-0.3');
|
|
|
require('./privatebin');
|
|
require('./privatebin');
|
|
|
|
|
|
|
|
-describe('helper', function () {
|
|
|
|
|
|
|
+describe('Helper', function () {
|
|
|
describe('secondsToHuman', function () {
|
|
describe('secondsToHuman', function () {
|
|
|
after(function () {
|
|
after(function () {
|
|
|
cleanup();
|
|
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) &&
|
|
|
result.length === 2 &&
|
|
result.length === 2 &&
|
|
|
result[0] === parseInt(result[0], 10) &&
|
|
result[0] === parseInt(result[0], 10) &&
|
|
|
typeof result[1] === 'string';
|
|
typeof result[1] === 'string';
|
|
|
});
|
|
});
|
|
|
jsc.property('returns seconds on the first array position', 'integer 59', function (number) {
|
|
jsc.property('returns seconds on the first array position', 'integer 59', function (number) {
|
|
|
- return $.PrivateBin.helper.secondsToHuman(number)[0] === number;
|
|
|
|
|
|
|
+ return $.PrivateBin.Helper.secondsToHuman(number)[0] === number;
|
|
|
});
|
|
});
|
|
|
jsc.property('returns seconds on the second array position', 'integer 59', function (number) {
|
|
jsc.property('returns seconds on the second array position', 'integer 59', function (number) {
|
|
|
- return $.PrivateBin.helper.secondsToHuman(number)[1] === 'second';
|
|
|
|
|
|
|
+ return $.PrivateBin.Helper.secondsToHuman(number)[1] === 'second';
|
|
|
});
|
|
});
|
|
|
jsc.property('returns minutes on the first array position', 'integer 60 3599', function (number) {
|
|
jsc.property('returns minutes on the first array position', 'integer 60 3599', function (number) {
|
|
|
- return $.PrivateBin.helper.secondsToHuman(number)[0] === Math.floor(number / 60);
|
|
|
|
|
|
|
+ return $.PrivateBin.Helper.secondsToHuman(number)[0] === Math.floor(number / 60);
|
|
|
});
|
|
});
|
|
|
jsc.property('returns minutes on the second array position', 'integer 60 3599', function (number) {
|
|
jsc.property('returns minutes on the second array position', 'integer 60 3599', function (number) {
|
|
|
- return $.PrivateBin.helper.secondsToHuman(number)[1] === 'minute';
|
|
|
|
|
|
|
+ return $.PrivateBin.Helper.secondsToHuman(number)[1] === 'minute';
|
|
|
});
|
|
});
|
|
|
jsc.property('returns hours on the first array position', 'integer 3600 86399', function (number) {
|
|
jsc.property('returns hours on the first array position', 'integer 3600 86399', function (number) {
|
|
|
- return $.PrivateBin.helper.secondsToHuman(number)[0] === Math.floor(number / (60 * 60));
|
|
|
|
|
|
|
+ return $.PrivateBin.Helper.secondsToHuman(number)[0] === Math.floor(number / (60 * 60));
|
|
|
});
|
|
});
|
|
|
jsc.property('returns hours on the second array position', 'integer 3600 86399', function (number) {
|
|
jsc.property('returns hours on the second array position', 'integer 3600 86399', function (number) {
|
|
|
- return $.PrivateBin.helper.secondsToHuman(number)[1] === 'hour';
|
|
|
|
|
|
|
+ return $.PrivateBin.Helper.secondsToHuman(number)[1] === 'hour';
|
|
|
});
|
|
});
|
|
|
jsc.property('returns days on the first array position', 'integer 86400 5184000', function (number) {
|
|
jsc.property('returns days on the first array position', 'integer 86400 5184000', function (number) {
|
|
|
- return $.PrivateBin.helper.secondsToHuman(number)[0] === Math.floor(number / (60 * 60 * 24));
|
|
|
|
|
|
|
+ return $.PrivateBin.Helper.secondsToHuman(number)[0] === Math.floor(number / (60 * 60 * 24));
|
|
|
});
|
|
});
|
|
|
jsc.property('returns days on the second array position', 'integer 86400 5184000', function (number) {
|
|
jsc.property('returns days on the second array position', 'integer 86400 5184000', function (number) {
|
|
|
- return $.PrivateBin.helper.secondsToHuman(number)[1] === 'day';
|
|
|
|
|
|
|
+ return $.PrivateBin.Helper.secondsToHuman(number)[1] === 'day';
|
|
|
});
|
|
});
|
|
|
// max safe integer as per http://ecma262-5.com/ELS5_HTML.htm#Section_8.5
|
|
// max safe integer as per http://ecma262-5.com/ELS5_HTML.htm#Section_8.5
|
|
|
jsc.property('returns months on the first array position', 'integer 5184000 9007199254740991', function (number) {
|
|
jsc.property('returns months on the first array position', 'integer 5184000 9007199254740991', function (number) {
|
|
|
- return $.PrivateBin.helper.secondsToHuman(number)[0] === Math.floor(number / (60 * 60 * 24 * 30));
|
|
|
|
|
|
|
+ return $.PrivateBin.Helper.secondsToHuman(number)[0] === Math.floor(number / (60 * 60 * 24 * 30));
|
|
|
});
|
|
});
|
|
|
jsc.property('returns months on the second array position', 'integer 5184000 9007199254740991', function (number) {
|
|
jsc.property('returns months on the second array position', 'integer 5184000 9007199254740991', function (number) {
|
|
|
- return $.PrivateBin.helper.secondsToHuman(number)[1] === 'month';
|
|
|
|
|
|
|
+ return $.PrivateBin.Helper.secondsToHuman(number)[1] === 'month';
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- describe('scriptLocation', function () {
|
|
|
|
|
|
|
+ describe('baseUri', function () {
|
|
|
|
|
+ before(function () {
|
|
|
|
|
+ $.PrivateBin.Helper.reset();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
jsc.property(
|
|
jsc.property(
|
|
|
'returns the URL without query & fragment',
|
|
'returns the URL without query & fragment',
|
|
|
- jsc.nearray(jsc.elements(a2zString)),
|
|
|
|
|
|
|
+ jsc.elements(schemas),
|
|
|
jsc.nearray(jsc.elements(a2zString)),
|
|
jsc.nearray(jsc.elements(a2zString)),
|
|
|
jsc.array(jsc.elements(queryString)),
|
|
jsc.array(jsc.elements(queryString)),
|
|
|
'string',
|
|
'string',
|
|
|
function (schema, address, query, fragment) {
|
|
function (schema, address, query, fragment) {
|
|
|
- var expected = schema.join('') + '://' + address.join('') + '/',
|
|
|
|
|
|
|
+ var expected = schema + '://' + address.join('') + '/',
|
|
|
clean = jsdom('', {url: expected + '?' + query.join('') + '#' + fragment}),
|
|
clean = jsdom('', {url: expected + '?' + query.join('') + '#' + fragment}),
|
|
|
- result = $.PrivateBin.helper.scriptLocation();
|
|
|
|
|
|
|
+ result = $.PrivateBin.Helper.baseUri();
|
|
|
|
|
+ $.PrivateBin.Helper.reset();
|
|
|
clean();
|
|
clean();
|
|
|
return expected === result;
|
|
return expected === result;
|
|
|
}
|
|
}
|
|
|
);
|
|
);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- describe('pasteId', function () {
|
|
|
|
|
|
|
+ describe('htmlEntities', function () {
|
|
|
|
|
+ after(function () {
|
|
|
|
|
+ cleanup();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ jsc.property(
|
|
|
|
|
+ 'removes all HTML entities from any given string',
|
|
|
|
|
+ 'string',
|
|
|
|
|
+ function (string) {
|
|
|
|
|
+ var result = $.PrivateBin.Helper.htmlEntities(string);
|
|
|
|
|
+ return !(/[<>"'`=\/]/.test(result)) && !(string.indexOf('&') > -1 && !(/&/.test(result)));
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
|
|
+ });
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+describe('Model', function () {
|
|
|
|
|
+ describe('getPasteId', function () {
|
|
|
|
|
+ before(function () {
|
|
|
|
|
+ $.PrivateBin.Model.reset();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
jsc.property(
|
|
jsc.property(
|
|
|
'returns the query string without separator, if any',
|
|
'returns the query string without separator, if any',
|
|
|
jsc.nearray(jsc.elements(a2zString)),
|
|
jsc.nearray(jsc.elements(a2zString)),
|
|
|
jsc.nearray(jsc.elements(a2zString)),
|
|
jsc.nearray(jsc.elements(a2zString)),
|
|
|
- jsc.array(jsc.elements(queryString)),
|
|
|
|
|
|
|
+ jsc.nearray(jsc.elements(queryString)),
|
|
|
'string',
|
|
'string',
|
|
|
function (schema, address, query, fragment) {
|
|
function (schema, address, query, fragment) {
|
|
|
var queryString = query.join(''),
|
|
var queryString = query.join(''),
|
|
@@ -96,27 +124,29 @@ describe('helper', function () {
|
|
|
url: schema.join('') + '://' + address.join('') +
|
|
url: schema.join('') + '://' + address.join('') +
|
|
|
'/?' + queryString + '#' + fragment
|
|
'/?' + queryString + '#' + fragment
|
|
|
}),
|
|
}),
|
|
|
- result = $.PrivateBin.helper.pasteId();
|
|
|
|
|
|
|
+ result = $.PrivateBin.Model.getPasteId();
|
|
|
|
|
+ $.PrivateBin.Model.reset();
|
|
|
clean();
|
|
clean();
|
|
|
return queryString === result;
|
|
return queryString === result;
|
|
|
}
|
|
}
|
|
|
);
|
|
);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- describe('pageKey', function () {
|
|
|
|
|
|
|
+ describe('getPasteKey', function () {
|
|
|
jsc.property(
|
|
jsc.property(
|
|
|
'returns the fragment of the URL',
|
|
'returns the fragment of the URL',
|
|
|
jsc.nearray(jsc.elements(a2zString)),
|
|
jsc.nearray(jsc.elements(a2zString)),
|
|
|
jsc.nearray(jsc.elements(a2zString)),
|
|
jsc.nearray(jsc.elements(a2zString)),
|
|
|
jsc.array(jsc.elements(queryString)),
|
|
jsc.array(jsc.elements(queryString)),
|
|
|
- jsc.array(jsc.elements(base64String)),
|
|
|
|
|
|
|
+ jsc.nearray(jsc.elements(base64String)),
|
|
|
function (schema, address, query, fragment) {
|
|
function (schema, address, query, fragment) {
|
|
|
var fragmentString = fragment.join(''),
|
|
var fragmentString = fragment.join(''),
|
|
|
clean = jsdom('', {
|
|
clean = jsdom('', {
|
|
|
url: schema.join('') + '://' + address.join('') +
|
|
url: schema.join('') + '://' + address.join('') +
|
|
|
'/?' + query.join('') + '#' + fragmentString
|
|
'/?' + query.join('') + '#' + fragmentString
|
|
|
}),
|
|
}),
|
|
|
- result = $.PrivateBin.helper.pageKey();
|
|
|
|
|
|
|
+ result = $.PrivateBin.Model.getPasteKey();
|
|
|
|
|
+ $.PrivateBin.Model.reset();
|
|
|
clean();
|
|
clean();
|
|
|
return fragmentString === result;
|
|
return fragmentString === result;
|
|
|
}
|
|
}
|
|
@@ -126,7 +156,7 @@ describe('helper', function () {
|
|
|
jsc.nearray(jsc.elements(a2zString)),
|
|
jsc.nearray(jsc.elements(a2zString)),
|
|
|
jsc.nearray(jsc.elements(a2zString)),
|
|
jsc.nearray(jsc.elements(a2zString)),
|
|
|
jsc.array(jsc.elements(queryString)),
|
|
jsc.array(jsc.elements(queryString)),
|
|
|
- jsc.array(jsc.elements(base64String)),
|
|
|
|
|
|
|
+ jsc.nearray(jsc.elements(base64String)),
|
|
|
jsc.array(jsc.elements(queryString)),
|
|
jsc.array(jsc.elements(queryString)),
|
|
|
function (schema, address, query, fragment, trail) {
|
|
function (schema, address, query, fragment, trail) {
|
|
|
var fragmentString = fragment.join(''),
|
|
var fragmentString = fragment.join(''),
|
|
@@ -134,25 +164,11 @@ describe('helper', function () {
|
|
|
url: schema.join('') + '://' + address.join('') + '/?' +
|
|
url: schema.join('') + '://' + address.join('') + '/?' +
|
|
|
query.join('') + '#' + fragmentString + '&' + trail.join('')
|
|
query.join('') + '#' + fragmentString + '&' + trail.join('')
|
|
|
}),
|
|
}),
|
|
|
- result = $.PrivateBin.helper.pageKey();
|
|
|
|
|
|
|
+ result = $.PrivateBin.Model.getPasteKey();
|
|
|
|
|
+ $.PrivateBin.Model.reset();
|
|
|
clean();
|
|
clean();
|
|
|
return fragmentString === result;
|
|
return fragmentString === result;
|
|
|
}
|
|
}
|
|
|
);
|
|
);
|
|
|
});
|
|
});
|
|
|
-
|
|
|
|
|
- describe('htmlEntities', function () {
|
|
|
|
|
- after(function () {
|
|
|
|
|
- cleanup();
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- jsc.property(
|
|
|
|
|
- 'removes all HTML entities from any given string',
|
|
|
|
|
- 'string',
|
|
|
|
|
- function (string) {
|
|
|
|
|
- var result = $.PrivateBin.helper.htmlEntities(string);
|
|
|
|
|
- return !(/[<>"'`=\/]/.test(result)) && !(string.indexOf('&') > -1 && !(/&/.test(result)));
|
|
|
|
|
- }
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
});
|
|
});
|