2017-12-13 14:40:48 +08:00
|
|
|
'use strict';
|
|
|
|
|
2017-12-14 14:19:05 +08:00
|
|
|
// testing prerequisites
|
2018-03-01 13:43:30 +08:00
|
|
|
global.assert = require('assert');
|
2017-12-13 14:40:48 +08:00
|
|
|
global.jsc = require('jsverify');
|
|
|
|
global.jsdom = require('jsdom-global');
|
|
|
|
global.cleanup = global.jsdom();
|
2019-06-21 04:30:49 +08:00
|
|
|
global.URL = require('jsdom-url').URL;
|
2017-12-13 14:40:48 +08:00
|
|
|
global.fs = require('fs');
|
2020-06-01 14:07:25 +08:00
|
|
|
global.WebCrypto = require('@peculiar/webcrypto').Crypto;
|
2017-12-13 14:40:48 +08:00
|
|
|
|
2017-12-14 14:19:05 +08:00
|
|
|
// application libraries to test
|
2023-06-18 19:47:54 +08:00
|
|
|
global.$ = global.jQuery = require('./jquery-3.7.0');
|
2018-12-28 04:32:13 +08:00
|
|
|
global.RawDeflate = require('./rawinflate-0.3').RawDeflate;
|
2024-01-27 18:33:54 +08:00
|
|
|
global.zlib = require('./zlib-1.3.1').zlib;
|
2017-12-13 14:40:48 +08:00
|
|
|
require('./prettify');
|
|
|
|
global.prettyPrint = window.PR.prettyPrint;
|
|
|
|
global.prettyPrintOne = window.PR.prettyPrintOne;
|
2022-11-13 13:37:23 +08:00
|
|
|
global.showdown = require('./showdown-2.1.0');
|
2024-01-27 18:33:54 +08:00
|
|
|
global.DOMPurify = require('./purify-3.0.8');
|
2022-02-18 14:36:09 +08:00
|
|
|
global.baseX = require('./base-x-4.0.0').baseX;
|
2019-09-18 13:31:32 +08:00
|
|
|
global.Legacy = require('./legacy').Legacy;
|
2022-02-20 23:13:34 +08:00
|
|
|
require('./bootstrap-3.4.1');
|
2017-12-13 14:40:48 +08:00
|
|
|
require('./privatebin');
|
|
|
|
|
2017-12-14 14:19:05 +08:00
|
|
|
// internal variables
|
2019-01-20 18:05:34 +08:00
|
|
|
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'],
|
|
|
|
digitString = ['0','1','2','3','4','5','6','7','8','9'],
|
|
|
|
alnumString = a2zString.concat(digitString),
|
|
|
|
hexString = digitString.concat(['a','b','c','d','e','f']),
|
|
|
|
queryString = alnumString.concat(['+','%','&','.','*','-','_']),
|
|
|
|
hashString = queryString.concat(['!']),
|
2017-12-14 14:19:05 +08:00
|
|
|
base64String = alnumString.concat(['+','/','=']).concat(
|
|
|
|
a2zString.map(function(c) {
|
|
|
|
return c.toUpperCase();
|
|
|
|
})
|
|
|
|
),
|
2020-01-18 17:44:35 +08:00
|
|
|
schemas = ['ftp','http','https'],
|
2024-01-05 06:08:17 +08:00
|
|
|
supportedLanguages = ['ar', 'bg', 'ca', 'co', 'cs', 'de', 'el', 'es', 'et', 'fi', 'fr', 'he', 'hu', 'id', 'it', 'ja', 'jbo', 'lt', 'no', 'nl', 'pl', 'pt', 'oc', 'ru', 'sk', 'sl', 'th', 'tr', 'uk', 'zh'],
|
2017-12-14 14:19:05 +08:00
|
|
|
mimeTypes = ['image/png', 'application/octet-stream'],
|
2017-12-18 21:25:08 +08:00
|
|
|
formats = ['plaintext', 'markdown', 'syntaxhighlighting'],
|
2017-12-14 14:19:05 +08:00
|
|
|
mimeFile = fs.createReadStream('/etc/mime.types'),
|
|
|
|
mimeLine = '';
|
|
|
|
|
2017-12-13 14:40:48 +08: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 14:19:05 +08:00
|
|
|
mimeTypes.push(line);
|
2017-12-13 14:40:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-14 14:19:05 +08:00
|
|
|
// common testing helper functions
|
2018-12-30 01:40:59 +08:00
|
|
|
exports.atob = atob;
|
|
|
|
exports.btoa = btoa;
|
2017-12-14 14:19:05 +08:00
|
|
|
|
|
|
|
// provides random lowercase characters from a to z
|
|
|
|
exports.jscA2zString = function() {
|
|
|
|
return jsc.elements(a2zString);
|
2018-01-06 20:32:07 +08:00
|
|
|
};
|
2017-12-14 14:19:05 +08:00
|
|
|
|
|
|
|
// provides random lowercase alpha numeric characters (a to z and 0 to 9)
|
|
|
|
exports.jscAlnumString = function() {
|
|
|
|
return jsc.elements(alnumString);
|
2018-01-06 20:32:07 +08:00
|
|
|
};
|
2017-12-14 14:19:05 +08:00
|
|
|
|
2019-01-20 18:05:34 +08:00
|
|
|
//provides random characters allowed in hexadecimal notation
|
|
|
|
exports.jscHexString = function() {
|
|
|
|
return jsc.elements(hexString);
|
|
|
|
};
|
|
|
|
|
2017-12-14 14:19:05 +08:00
|
|
|
// provides random characters allowed in GET queries
|
|
|
|
exports.jscQueryString = function() {
|
|
|
|
return jsc.elements(queryString);
|
2018-01-06 20:32:07 +08:00
|
|
|
};
|
2017-12-14 14:19:05 +08:00
|
|
|
|
2018-08-11 13:33:33 +08:00
|
|
|
// provides random characters allowed in hash queries
|
|
|
|
exports.jscHashString = function() {
|
|
|
|
return jsc.elements(hashString);
|
|
|
|
};
|
|
|
|
|
2017-12-14 14:31:09 +08:00
|
|
|
// provides random characters allowed in base64 encoded strings
|
|
|
|
exports.jscBase64String = function() {
|
|
|
|
return jsc.elements(base64String);
|
2018-01-06 20:32:07 +08:00
|
|
|
};
|
2017-12-14 14:31:09 +08:00
|
|
|
|
2017-12-14 14:19:05 +08:00
|
|
|
// provides a random URL schema supported by the whatwg-url library
|
2024-01-08 00:45:01 +08:00
|
|
|
exports.jscSchemas = function(withFtp = true) {
|
|
|
|
return jsc.elements(withFtp ? schemas : schemas.slice(1));
|
2018-01-06 20:32:07 +08:00
|
|
|
};
|
2017-12-14 14:19:05 +08:00
|
|
|
|
|
|
|
// provides a random supported language string
|
|
|
|
exports.jscSupportedLanguages = function() {
|
|
|
|
return jsc.elements(supportedLanguages);
|
2018-01-06 20:32:07 +08:00
|
|
|
};
|
2017-12-14 14:19:05 +08:00
|
|
|
|
2017-12-18 21:25:08 +08:00
|
|
|
// provides a random mime type
|
|
|
|
exports.jscMimeTypes = function() {
|
|
|
|
return jsc.elements(mimeTypes);
|
2018-01-06 20:32:07 +08:00
|
|
|
};
|
2017-12-18 21:25:08 +08:00
|
|
|
|
|
|
|
// provides a random PrivateBin paste formatter
|
|
|
|
exports.jscFormats = function() {
|
|
|
|
return jsc.elements(formats);
|
2018-01-06 20:32:07 +08:00
|
|
|
};
|
2024-01-07 21:10:43 +08:00
|
|
|
|
|
|
|
// provides random URLs
|
|
|
|
exports.jscUrl = function(withFragment = true, withQuery = true) {
|
|
|
|
let url = {
|
|
|
|
schema: exports.jscSchemas(),
|
|
|
|
address: jsc.nearray(exports.jscA2zString()),
|
|
|
|
};
|
|
|
|
if (withFragment) {
|
|
|
|
url.fragment = jsc.string;
|
|
|
|
}
|
|
|
|
if(withQuery) {
|
|
|
|
url.query = jsc.array(exports.jscQueryString());
|
|
|
|
}
|
|
|
|
return jsc.record(url);
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.urlToString = function (url) {
|
|
|
|
return url.schema + '://' + url.address.join('') + '/' + (url.query ? '?' +
|
|
|
|
encodeURI(url.query.join('').replace(/^&+|&+$/gm,'')) : '') +
|
|
|
|
(url.fragment ? '#' + encodeURI(url.fragment) : '');
|
2024-01-27 18:33:54 +08:00
|
|
|
};
|