2019-06-22 07:12:31 +00:00
|
|
|
'use strict';
|
|
|
|
var common = require('../common');
|
|
|
|
|
|
|
|
describe('InitialCheck', function () {
|
|
|
|
describe('init', function () {
|
|
|
|
this.timeout(30000);
|
|
|
|
before(function () {
|
|
|
|
cleanup();
|
|
|
|
});
|
|
|
|
|
2019-06-22 13:44:54 +00:00
|
|
|
it('returns false and shows error, if a bot UA is detected', function () {
|
|
|
|
jsc.assert(jsc.forall(
|
|
|
|
'string',
|
|
|
|
jsc.elements(['Bot', 'bot']),
|
|
|
|
'string',
|
|
|
|
function (prefix, botBit, suffix) {
|
|
|
|
const clean = jsdom('', {
|
|
|
|
'userAgent': prefix + botBit + suffix
|
|
|
|
});
|
|
|
|
$('body').html(
|
|
|
|
'<html><body><div id="errormessage" class="hidden"></div>' +
|
|
|
|
'</body></html>'
|
|
|
|
);
|
|
|
|
$.PrivateBin.Alert.init();
|
|
|
|
const result1 = !$.PrivateBin.InitialCheck.init(),
|
|
|
|
result2 = !$('#errormessage').hasClass('hidden');
|
|
|
|
clean();
|
|
|
|
return result1 && result2;
|
|
|
|
}
|
|
|
|
),
|
2019-06-23 08:38:08 +00:00
|
|
|
{tests: 10});
|
2019-06-22 13:44:54 +00:00
|
|
|
});
|
|
|
|
|
2019-06-23 08:38:08 +00:00
|
|
|
jsc.property(
|
|
|
|
'shows error, if no webcrypto is detected',
|
|
|
|
'bool',
|
|
|
|
jsc.elements(['localhost', '127.0.0.1', '[::1]', '']),
|
|
|
|
jsc.nearray(common.jscA2zString()),
|
|
|
|
jsc.elements(['.onion', '.i2p', '']),
|
|
|
|
function (secureProtocol, localhost, domain, tld) {
|
|
|
|
const isDomain = localhost === '',
|
|
|
|
isSecureContext = secureProtocol || !isDomain || tld.length > 0,
|
|
|
|
clean = jsdom('', {
|
|
|
|
'url': (secureProtocol ? 'https' : 'http' ) + '://' +
|
|
|
|
(isDomain ? domain.join('') + tld : localhost) + '/'
|
|
|
|
});
|
|
|
|
$('body').html(
|
|
|
|
'<html><body><div id="errormessage" class="hidden"></div>'+
|
|
|
|
'<div id="oldnotice" class="hidden"></div></body></html>'
|
|
|
|
);
|
|
|
|
$.PrivateBin.Alert.init();
|
|
|
|
const result1 = !$.PrivateBin.InitialCheck.init(),
|
|
|
|
result2 = isSecureContext === $('#errormessage').hasClass('hidden'),
|
|
|
|
result3 = !$('#oldnotice').hasClass('hidden');
|
|
|
|
clean();
|
|
|
|
return result1 && result2 && result3;
|
|
|
|
}
|
|
|
|
);
|
2019-06-22 13:44:54 +00:00
|
|
|
|
2019-06-23 08:38:08 +00:00
|
|
|
jsc.property(
|
|
|
|
'shows error, if HTTP only site is detected',
|
|
|
|
'bool',
|
|
|
|
jsc.nearray(common.jscA2zString()),
|
2019-08-27 21:16:06 +00:00
|
|
|
function (secureProtocol, domain) {
|
|
|
|
const clean = jsdom('', {
|
|
|
|
'url': (secureProtocol ? 'https' : 'http' ) + '://' + domain.join('') + '/'
|
2019-06-23 08:38:08 +00:00
|
|
|
});
|
|
|
|
$('body').html(
|
|
|
|
'<html><body><div id="httpnotice" class="hidden"></div>'+
|
|
|
|
'</body></html>'
|
|
|
|
);
|
|
|
|
$.PrivateBin.Alert.init();
|
2019-08-27 21:16:06 +00:00
|
|
|
window.crypto = new WebCrypto();
|
2019-06-23 08:38:08 +00:00
|
|
|
const result1 = $.PrivateBin.InitialCheck.init(),
|
2019-08-27 21:16:06 +00:00
|
|
|
result2 = secureProtocol === $('#httpnotice').hasClass('hidden');
|
2019-06-23 08:38:08 +00:00
|
|
|
clean();
|
|
|
|
return result1 && result2;
|
|
|
|
}
|
|
|
|
);
|
2019-06-22 07:12:31 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|