2017-12-15 07:20:51 +01:00
|
|
|
'use strict';
|
|
|
|
var common = require('../common');
|
|
|
|
|
2024-01-07 17:45:01 +01:00
|
|
|
function urlStrings(schema, longUrl, shortUrl) {
|
|
|
|
longUrl.schema = schema;
|
|
|
|
shortUrl.schema = schema;
|
|
|
|
let longUrlString = common.urlToString(longUrl),
|
|
|
|
shortUrlString = common.urlToString(shortUrl);
|
|
|
|
// ensure the two random URLs actually are sorted as expected
|
|
|
|
if (longUrlString.length <= shortUrlString.length) {
|
|
|
|
if (longUrlString.length === shortUrlString.length) {
|
|
|
|
longUrl.address.unshift('a');
|
|
|
|
longUrlString = common.urlToString(longUrl);
|
|
|
|
} else {
|
|
|
|
[longUrlString, shortUrlString] = [shortUrlString, longUrlString];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return [longUrlString, shortUrlString];
|
|
|
|
}
|
|
|
|
|
2017-12-15 07:20:51 +01:00
|
|
|
describe('PasteStatus', function () {
|
|
|
|
describe('createPasteNotification', function () {
|
|
|
|
this.timeout(30000);
|
|
|
|
|
|
|
|
jsc.property(
|
|
|
|
'creates a notification after a successfull paste upload',
|
2024-01-07 14:10:43 +01:00
|
|
|
common.jscUrl(),
|
|
|
|
common.jscUrl(false),
|
|
|
|
function (url1, url2) {
|
2024-01-08 08:09:29 +01:00
|
|
|
const expected1 = common.urlToString(url1).replace(/&(gt|lt)$/, '&$1a'),
|
|
|
|
expected2 = common.urlToString(url2).replace(/&(gt|lt)$/, '&$1a'),
|
2017-12-15 07:20:51 +01:00
|
|
|
clean = jsdom();
|
|
|
|
$('body').html('<div><div id="deletelink"></div><div id="pastelink"></div></div>');
|
|
|
|
$.PrivateBin.PasteStatus.init();
|
|
|
|
$.PrivateBin.PasteStatus.createPasteNotification(expected1, expected2);
|
2024-01-08 08:09:29 +01:00
|
|
|
const result1 = $('#pasteurl')[0].href,
|
2017-12-15 07:20:51 +01:00
|
|
|
result2 = $('#deletelink a')[0].href;
|
|
|
|
clean();
|
2018-01-06 07:17:33 +01:00
|
|
|
return result1 === expected1 && result2 === expected2;
|
2017-12-15 07:20:51 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2024-01-04 23:08:17 +01:00
|
|
|
describe('extractUrl', function () {
|
|
|
|
this.timeout(30000);
|
|
|
|
|
|
|
|
jsc.property(
|
2024-01-07 17:45:01 +01:00
|
|
|
'extracts and updates IDN URLs found in given response',
|
|
|
|
common.jscSchemas(false),
|
2024-01-04 23:08:17 +01:00
|
|
|
'nestring',
|
2024-01-07 14:10:43 +01:00
|
|
|
common.jscUrl(),
|
|
|
|
function (schema, domain, url) {
|
2024-01-08 08:09:29 +01:00
|
|
|
domain = domain.replace(/\P{Letter}|[\u00AA-\u00BA]/gu, '').toLowerCase();
|
2024-01-04 23:08:17 +01:00
|
|
|
if (domain.length === 0) {
|
|
|
|
domain = 'a';
|
|
|
|
}
|
2024-01-07 14:10:43 +01:00
|
|
|
url.schema = schema;
|
|
|
|
url.address.unshift('.');
|
|
|
|
url.address = domain.split('').concat(url.address);
|
|
|
|
const urlString = common.urlToString(url),
|
|
|
|
expected = urlString.substring((schema + '://' + domain).length),
|
2024-01-04 23:08:17 +01:00
|
|
|
clean = jsdom();
|
|
|
|
|
|
|
|
$('body').html('<div><div id="pastelink"></div></div>');
|
|
|
|
$.PrivateBin.PasteStatus.init();
|
|
|
|
$.PrivateBin.PasteStatus.createPasteNotification('', '');
|
2024-01-07 14:10:43 +01:00
|
|
|
$.PrivateBin.PasteStatus.extractUrl(urlString);
|
2024-01-04 23:08:17 +01:00
|
|
|
|
|
|
|
const result = $('#pasteurl')[0].href;
|
|
|
|
clean();
|
|
|
|
|
|
|
|
return result.endsWith(expected) && (
|
|
|
|
result.startsWith(schema + '://xn--') ||
|
|
|
|
result.startsWith(schema + '://' + domain)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
2024-01-07 17:45:01 +01:00
|
|
|
|
|
|
|
// YOURLS API samples from: https://yourls.org/readme.html#API;apireturn
|
|
|
|
jsc.property(
|
|
|
|
'extracts and updates URLs found in YOURLS API JSON response',
|
|
|
|
common.jscSchemas(false),
|
|
|
|
common.jscUrl(),
|
|
|
|
common.jscUrl(false),
|
|
|
|
function (schema, longUrl, shortUrl) {
|
|
|
|
const [longUrlString, shortUrlString] = urlStrings(schema, longUrl, shortUrl),
|
|
|
|
yourlsResponse = {
|
|
|
|
url: {
|
|
|
|
keyword: longUrl.address.join(''),
|
|
|
|
url: longUrlString,
|
|
|
|
title: "example title",
|
|
|
|
date: "2014-10-24 16:01:39",
|
|
|
|
ip: "127.0.0.1"
|
|
|
|
},
|
|
|
|
status: "success",
|
|
|
|
message: longUrlString + " added to database",
|
|
|
|
title: "example title",
|
|
|
|
shorturl: shortUrlString,
|
|
|
|
statusCode: 200
|
|
|
|
},
|
|
|
|
clean = jsdom();
|
|
|
|
|
|
|
|
$('body').html('<div><div id="pastelink"></div></div>');
|
|
|
|
$.PrivateBin.PasteStatus.init();
|
|
|
|
$.PrivateBin.PasteStatus.createPasteNotification('', '');
|
|
|
|
$.PrivateBin.PasteStatus.extractUrl(JSON.stringify(yourlsResponse, undefined, 4));
|
|
|
|
|
|
|
|
const result = $('#pasteurl')[0].href;
|
|
|
|
clean();
|
|
|
|
|
|
|
|
return result === shortUrlString;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
jsc.property(
|
|
|
|
'extracts and updates URLs found in YOURLS API XML response',
|
|
|
|
common.jscSchemas(false),
|
|
|
|
common.jscUrl(),
|
|
|
|
common.jscUrl(false),
|
|
|
|
function (schema, longUrl, shortUrl) {
|
|
|
|
const [longUrlString, shortUrlString] = urlStrings(schema, longUrl, shortUrl),
|
|
|
|
yourlsResponse = '<result>\n' +
|
|
|
|
' <keyword>' + longUrl.address.join('') + '</keyword>\n' +
|
|
|
|
' <shorturl>' + shortUrlString + '</shorturl>\n' +
|
|
|
|
' <longurl>' + longUrlString + '</longurl>\n' +
|
|
|
|
' <message>success</message>\n' +
|
|
|
|
' <statusCode>200</statusCode>\n' +
|
|
|
|
'</result>',
|
|
|
|
clean = jsdom();
|
|
|
|
|
|
|
|
$('body').html('<div><div id="pastelink"></div></div>');
|
|
|
|
$.PrivateBin.PasteStatus.init();
|
|
|
|
$.PrivateBin.PasteStatus.createPasteNotification('', '');
|
|
|
|
$.PrivateBin.PasteStatus.extractUrl(yourlsResponse);
|
|
|
|
|
|
|
|
const result = $('#pasteurl')[0].href;
|
|
|
|
clean();
|
|
|
|
|
|
|
|
return result === shortUrlString;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
jsc.property(
|
|
|
|
'extracts and updates URLs found in YOURLS proxy HTML response',
|
|
|
|
common.jscSchemas(false),
|
|
|
|
common.jscUrl(),
|
|
|
|
common.jscUrl(false),
|
|
|
|
function (schema, longUrl, shortUrl) {
|
|
|
|
const [longUrlString, shortUrlString] = urlStrings(schema, longUrl, shortUrl),
|
|
|
|
yourlsResponse = '<!DOCTYPE html>\n' +
|
|
|
|
'<html lang="en">\n' +
|
|
|
|
'\t<head>\n' +
|
|
|
|
'\t\t<meta charset="utf-8" />\n' +
|
|
|
|
'\t\t<meta http-equiv="Content-Security-Policy" content="default-src \'none\'; base-uri \'self\'; form-action \'none\'; manifest-src \'self\'; connect-src * blob:; script-src \'self\' \'unsafe-eval\'; style-src \'self\'; font-src \'self\'; frame-ancestors \'none\'; img-src \'self\' data: blob:; media-src blob:; object-src blob:; sandbox allow-same-origin allow-scripts allow-forms allow-popups allow-modals allow-downloads">\n' +
|
|
|
|
'\t\t<meta name="robots" content="noindex" />\n' +
|
|
|
|
'\t\t<meta name="google" content="notranslate">\n' +
|
|
|
|
'\t\t<title>PrivateBin</title>\n' +
|
|
|
|
'\t</head>\n' +
|
|
|
|
'\t<body>\n' +
|
|
|
|
'\t\t<p>Your paste is <a id="pasteurl" href="' + shortUrlString + '">' + shortUrlString + '</a> <span id="copyhint">(Hit [Ctrl]+[c] to copy)</span></p>\n' +
|
|
|
|
'\t</body>\n' +
|
|
|
|
'</html>',
|
|
|
|
clean = jsdom();
|
|
|
|
|
|
|
|
$('body').html('<div><div id="pastelink"></div></div>');
|
|
|
|
$.PrivateBin.PasteStatus.init();
|
|
|
|
$.PrivateBin.PasteStatus.createPasteNotification('', '');
|
|
|
|
$.PrivateBin.PasteStatus.extractUrl(yourlsResponse);
|
|
|
|
|
|
|
|
const result = $('#pasteurl')[0].href;
|
|
|
|
clean();
|
|
|
|
|
|
|
|
return result === shortUrlString;
|
|
|
|
}
|
|
|
|
);
|
2024-01-04 23:08:17 +01:00
|
|
|
});
|
|
|
|
|
2017-12-15 07:20:51 +01:00
|
|
|
describe('showRemainingTime', function () {
|
|
|
|
this.timeout(30000);
|
|
|
|
|
|
|
|
jsc.property(
|
2019-05-15 07:44:03 +02:00
|
|
|
'shows burn after reading message or remaining time v1',
|
2017-12-15 07:20:51 +01:00
|
|
|
'bool',
|
|
|
|
'nat',
|
2024-01-07 14:10:43 +01:00
|
|
|
common.jscUrl(),
|
|
|
|
function (burnafterreading, remainingTime, url) {
|
|
|
|
let clean = jsdom('', {url: common.urlToString(url)}),
|
2018-01-06 07:17:33 +01:00
|
|
|
result;
|
2017-12-15 07:20:51 +01:00
|
|
|
$('body').html('<div id="remainingtime" class="hidden"></div>');
|
|
|
|
$.PrivateBin.PasteStatus.init();
|
2019-05-25 13:20:39 +02:00
|
|
|
$.PrivateBin.PasteStatus.showRemainingTime($.PrivateBin.Helper.PasteFactory({'meta': {
|
2017-12-15 07:20:51 +01:00
|
|
|
'burnafterreading': burnafterreading,
|
2019-05-15 07:44:03 +02:00
|
|
|
'remaining_time': remainingTime
|
2019-05-25 13:20:39 +02:00
|
|
|
}}));
|
2019-05-15 07:44:03 +02:00
|
|
|
if (burnafterreading) {
|
|
|
|
result = $('#remainingtime').hasClass('foryoureyesonly') &&
|
|
|
|
!$('#remainingtime').hasClass('hidden');
|
|
|
|
} else if (remainingTime) {
|
|
|
|
result =!$('#remainingtime').hasClass('foryoureyesonly') &&
|
|
|
|
!$('#remainingtime').hasClass('hidden');
|
|
|
|
} else {
|
|
|
|
result = $('#remainingtime').hasClass('hidden') &&
|
|
|
|
!$('#remainingtime').hasClass('foryoureyesonly');
|
|
|
|
}
|
|
|
|
clean();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
jsc.property(
|
|
|
|
'shows burn after reading message or remaining time v2',
|
|
|
|
'bool',
|
|
|
|
'nat',
|
2024-01-07 14:10:43 +01:00
|
|
|
common.jscUrl(),
|
|
|
|
function (burnafterreading, remainingTime, url) {
|
|
|
|
let clean = jsdom('', {url: common.urlToString(url)}),
|
2019-05-15 07:44:03 +02:00
|
|
|
result;
|
|
|
|
$('body').html('<div id="remainingtime" class="hidden"></div>');
|
|
|
|
$.PrivateBin.PasteStatus.init();
|
2019-05-25 13:20:39 +02:00
|
|
|
$.PrivateBin.PasteStatus.showRemainingTime($.PrivateBin.Helper.PasteFactory({
|
2019-05-15 07:44:03 +02:00
|
|
|
'adata': [null, null, null, burnafterreading],
|
2019-05-25 13:20:39 +02:00
|
|
|
'v': 2,
|
2019-05-15 07:44:03 +02:00
|
|
|
'meta': {
|
|
|
|
'time_to_live': remainingTime
|
|
|
|
}
|
2019-05-25 13:20:39 +02:00
|
|
|
}));
|
2017-12-15 07:20:51 +01:00
|
|
|
if (burnafterreading) {
|
2018-01-06 07:17:33 +01:00
|
|
|
result = $('#remainingtime').hasClass('foryoureyesonly') &&
|
|
|
|
!$('#remainingtime').hasClass('hidden');
|
2018-01-06 10:57:54 +01:00
|
|
|
} else if (remainingTime) {
|
2018-01-06 07:17:33 +01:00
|
|
|
result =!$('#remainingtime').hasClass('foryoureyesonly') &&
|
|
|
|
!$('#remainingtime').hasClass('hidden');
|
2017-12-15 07:20:51 +01:00
|
|
|
} else {
|
2018-01-06 07:17:33 +01:00
|
|
|
result = $('#remainingtime').hasClass('hidden') &&
|
|
|
|
!$('#remainingtime').hasClass('foryoureyesonly');
|
2017-12-15 07:20:51 +01:00
|
|
|
}
|
|
|
|
clean();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('hideMessages', function () {
|
|
|
|
it(
|
|
|
|
'hides all messages',
|
|
|
|
function() {
|
|
|
|
$('body').html(
|
|
|
|
'<div id="remainingtime"></div><div id="pastesuccess"></div>'
|
|
|
|
);
|
|
|
|
$.PrivateBin.PasteStatus.init();
|
|
|
|
$.PrivateBin.PasteStatus.hideMessages();
|
2018-03-01 06:43:30 +01:00
|
|
|
assert.ok(
|
|
|
|
$('#remainingtime').hasClass('hidden') &&
|
|
|
|
$('#pastesuccess').hasClass('hidden')
|
|
|
|
);
|
2017-12-15 07:20:51 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|