2017-12-13 07:40:48 +01:00
|
|
|
'use strict';
|
|
|
|
|
2017-12-14 07:19:05 +01:00
|
|
|
// testing prerequisites
|
2017-12-13 07:40:48 +01:00
|
|
|
global.jsc = require('jsverify');
|
|
|
|
global.jsdom = require('jsdom-global');
|
|
|
|
global.cleanup = global.jsdom();
|
|
|
|
global.fs = require('fs');
|
|
|
|
|
2017-12-14 07:19:05 +01:00
|
|
|
// application libraries to test
|
2017-12-13 07:40:48 +01:00
|
|
|
global.$ = global.jQuery = require('./jquery-3.1.1');
|
|
|
|
global.sjcl = require('./sjcl-1.0.6');
|
|
|
|
global.Base64 = require('./base64-2.1.9').Base64;
|
|
|
|
global.RawDeflate = require('./rawdeflate-0.5').RawDeflate;
|
|
|
|
global.RawDeflate.inflate = require('./rawinflate-0.3').RawDeflate.inflate;
|
|
|
|
require('./prettify');
|
|
|
|
global.prettyPrint = window.PR.prettyPrint;
|
|
|
|
global.prettyPrintOne = window.PR.prettyPrintOne;
|
|
|
|
global.showdown = require('./showdown-1.6.1');
|
2018-01-02 09:37:46 +01:00
|
|
|
global.DOMPurify = require('./purify-1.0.3');
|
2017-12-13 07:40:48 +01:00
|
|
|
require('./bootstrap-3.3.7');
|
|
|
|
require('./privatebin');
|
|
|
|
|
2017-12-14 07:19:05 +01:00
|
|
|
// internal variables
|
|
|
|
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(['+','%','&','.','*','-','_']),
|
|
|
|
base64String = alnumString.concat(['+','/','=']).concat(
|
|
|
|
a2zString.map(function(c) {
|
|
|
|
return c.toUpperCase();
|
|
|
|
})
|
|
|
|
),
|
|
|
|
schemas = ['ftp','gopher','http','https','ws','wss'],
|
|
|
|
supportedLanguages = ['de', 'es', 'fr', 'it', 'no', 'pl', 'pt', 'oc', 'ru', 'sl', 'zh'],
|
|
|
|
mimeTypes = ['image/png', 'application/octet-stream'],
|
2017-12-18 14:25:08 +01:00
|
|
|
formats = ['plaintext', 'markdown', 'syntaxhighlighting'],
|
2017-12-14 07:19:05 +01:00
|
|
|
/**
|
|
|
|
* character to HTML entity lookup table
|
|
|
|
*
|
|
|
|
* @see {@link https://github.com/janl/mustache.js/blob/master/mustache.js#L60}
|
|
|
|
*/
|
|
|
|
entityMap = {
|
|
|
|
'&': '&',
|
|
|
|
'<': '<',
|
|
|
|
'>': '>',
|
|
|
|
'"': '"',
|
|
|
|
"'": ''',
|
|
|
|
'/': '/',
|
|
|
|
'`': '`',
|
|
|
|
'=': '='
|
|
|
|
},
|
|
|
|
logFile = fs.createWriteStream('test.log'),
|
|
|
|
mimeFile = fs.createReadStream('/etc/mime.types'),
|
|
|
|
mimeLine = '';
|
|
|
|
|
2017-12-13 07:40:48 +01:00
|
|
|
// redirect console messages to log file
|
|
|
|
console.info = console.warn = console.error = function () {
|
|
|
|
logFile.write(Array.prototype.slice.call(arguments).join('') + '\n');
|
2018-01-06 10:57:54 +01:00
|
|
|
};
|
2017-12-13 07:40:48 +01:00
|
|
|
|
|
|
|
// populate mime types from environment
|
|
|
|
mimeFile.on('data', function(data) {
|
|
|
|
mimeLine += data;
|
|
|
|
var index = mimeLine.indexOf('\n');
|
|
|
|
while (index > -1) {
|
|
|
|
var line = mimeLine.substring(0, index);
|
|
|
|
mimeLine = mimeLine.substring(index + 1);
|
|
|
|
parseMime(line);
|
|
|
|
index = mimeLine.indexOf('\n');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mimeFile.on('end', function() {
|
|
|
|
if (mimeLine.length > 0) {
|
|
|
|
parseMime(mimeLine);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function parseMime(line) {
|
|
|
|
// ignore comments
|
|
|
|
var index = line.indexOf('#');
|
|
|
|
if (index > -1) {
|
|
|
|
line = line.substring(0, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ignore bits after tabs
|
|
|
|
index = line.indexOf('\t');
|
|
|
|
if (index > -1) {
|
|
|
|
line = line.substring(0, index);
|
|
|
|
}
|
|
|
|
if (line.length > 0) {
|
2017-12-14 07:19:05 +01:00
|
|
|
mimeTypes.push(line);
|
2017-12-13 07:40:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-14 07:19:05 +01:00
|
|
|
// common testing helper functions
|
|
|
|
|
2017-12-13 07:40:48 +01:00
|
|
|
/**
|
|
|
|
* convert all applicable characters to HTML entities
|
|
|
|
*
|
|
|
|
* @see {@link https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.231_-_HTML_Escape_Before_Inserting_Untrusted_Data_into_HTML_Element_Content}
|
|
|
|
* @name htmlEntities
|
|
|
|
* @function
|
|
|
|
* @param {string} str
|
|
|
|
* @return {string} escaped HTML
|
|
|
|
*/
|
|
|
|
exports.htmlEntities = function(str) {
|
|
|
|
return String(str).replace(
|
|
|
|
/[&<>"'`=\/]/g, function(s) {
|
|
|
|
return entityMap[s];
|
|
|
|
});
|
2018-01-06 13:32:07 +01:00
|
|
|
};
|
2017-12-13 07:40:48 +01:00
|
|
|
|
2017-12-14 07:19:05 +01:00
|
|
|
// provides random lowercase characters from a to z
|
|
|
|
exports.jscA2zString = function() {
|
|
|
|
return jsc.elements(a2zString);
|
2018-01-06 13:32:07 +01:00
|
|
|
};
|
2017-12-14 07:19:05 +01:00
|
|
|
|
|
|
|
// provides random lowercase alpha numeric characters (a to z and 0 to 9)
|
|
|
|
exports.jscAlnumString = function() {
|
|
|
|
return jsc.elements(alnumString);
|
2018-01-06 13:32:07 +01:00
|
|
|
};
|
2017-12-14 07:19:05 +01:00
|
|
|
|
|
|
|
// provides random characters allowed in GET queries
|
|
|
|
exports.jscQueryString = function() {
|
|
|
|
return jsc.elements(queryString);
|
2018-01-06 13:32:07 +01:00
|
|
|
};
|
2017-12-14 07:19:05 +01:00
|
|
|
|
2017-12-14 07:31:09 +01:00
|
|
|
// provides random characters allowed in base64 encoded strings
|
|
|
|
exports.jscBase64String = function() {
|
|
|
|
return jsc.elements(base64String);
|
2018-01-06 13:32:07 +01:00
|
|
|
};
|
2017-12-14 07:31:09 +01:00
|
|
|
|
2017-12-14 07:19:05 +01:00
|
|
|
// provides a random URL schema supported by the whatwg-url library
|
|
|
|
exports.jscSchemas = function() {
|
|
|
|
return jsc.elements(schemas);
|
2018-01-06 13:32:07 +01:00
|
|
|
};
|
2017-12-14 07:19:05 +01:00
|
|
|
|
|
|
|
// provides a random supported language string
|
|
|
|
exports.jscSupportedLanguages = function() {
|
|
|
|
return jsc.elements(supportedLanguages);
|
2018-01-06 13:32:07 +01:00
|
|
|
};
|
2017-12-14 07:19:05 +01:00
|
|
|
|
2017-12-18 14:25:08 +01:00
|
|
|
// provides a random mime type
|
|
|
|
exports.jscMimeTypes = function() {
|
|
|
|
return jsc.elements(mimeTypes);
|
2018-01-06 13:32:07 +01:00
|
|
|
};
|
2017-12-18 14:25:08 +01:00
|
|
|
|
|
|
|
// provides a random PrivateBin paste formatter
|
|
|
|
exports.jscFormats = function() {
|
|
|
|
return jsc.elements(formats);
|
2018-01-06 13:32:07 +01:00
|
|
|
};
|
2017-12-18 14:25:08 +01:00
|
|
|
|