2019-06-22 09:12:31 +02:00
|
|
|
'use strict';
|
|
|
|
var common = require('../common');
|
2019-09-18 07:31:32 +02:00
|
|
|
/* global Legacy, WebCrypto */
|
2019-06-22 09:12:31 +02:00
|
|
|
|
2019-09-14 09:41:52 +02:00
|
|
|
describe('Check', function () {
|
2019-06-22 09:12:31 +02:00
|
|
|
describe('init', function () {
|
|
|
|
this.timeout(30000);
|
|
|
|
|
2019-06-22 15:44:54 +02: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) {
|
2019-09-18 07:31:32 +02:00
|
|
|
const clean = jsdom(
|
2019-06-22 15:44:54 +02:00
|
|
|
'<html><body><div id="errormessage" class="hidden"></div>' +
|
2019-09-18 07:31:32 +02:00
|
|
|
'</body></html>', {
|
|
|
|
'userAgent': prefix + botBit + suffix
|
|
|
|
}
|
2019-06-22 15:44:54 +02:00
|
|
|
);
|
2019-09-18 07:31:32 +02:00
|
|
|
Legacy.Check.init();
|
|
|
|
const result1 = Legacy.Check.getInit() && !Legacy.Check.getStatus(),
|
|
|
|
result2 = (document.getElementById('errormessage').className !== 'hidden');
|
2019-06-22 15:44:54 +02:00
|
|
|
clean();
|
|
|
|
return result1 && result2;
|
|
|
|
}
|
|
|
|
),
|
2019-06-23 10:38:08 +02:00
|
|
|
{tests: 10});
|
2019-06-22 15:44:54 +02:00
|
|
|
});
|
|
|
|
|
2019-06-23 10:38:08 +02: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,
|
2019-09-18 07:31:32 +02:00
|
|
|
clean = jsdom(
|
|
|
|
'<html><body><div id="errormessage" class="hidden"></div>' +
|
2019-09-19 19:14:48 +02:00
|
|
|
'<div id="oldnotice" class="hidden"></div>' +
|
|
|
|
'<div id="insecurecontextnotice" class="hidden"></div></body></html>',
|
2019-09-18 07:31:32 +02:00
|
|
|
{
|
|
|
|
'url': (secureProtocol ? 'https' : 'http' ) + '://' +
|
|
|
|
(isDomain ? domain.join('') + tld : localhost) + '/'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
Legacy.Check.init();
|
|
|
|
const result1 = Legacy.Check.getInit() && !Legacy.Check.getStatus(),
|
2019-09-19 19:14:48 +02:00
|
|
|
result2 = isSecureContext === (document.getElementById('insecurecontextnotice').className === 'hidden'),
|
2019-09-18 07:31:32 +02:00
|
|
|
result3 = (document.getElementById('oldnotice').className !== 'hidden');
|
2019-06-23 10:38:08 +02:00
|
|
|
clean();
|
|
|
|
return result1 && result2 && result3;
|
|
|
|
}
|
|
|
|
);
|
2019-06-22 15:44:54 +02:00
|
|
|
|
2019-06-23 10:38:08 +02:00
|
|
|
jsc.property(
|
|
|
|
'shows error, if HTTP only site is detected',
|
|
|
|
'bool',
|
|
|
|
jsc.nearray(common.jscA2zString()),
|
2019-08-27 23:16:06 +02:00
|
|
|
function (secureProtocol, domain) {
|
2019-09-18 07:31:32 +02:00
|
|
|
const clean = jsdom(
|
|
|
|
'<html><body><div id="httpnotice" class="hidden"></div>' +
|
|
|
|
'</body></html>',
|
|
|
|
{
|
|
|
|
'url': (secureProtocol ? 'https' : 'http' ) + '://' + domain.join('') + '/'
|
|
|
|
}
|
|
|
|
);
|
2019-08-27 23:16:06 +02:00
|
|
|
window.crypto = new WebCrypto();
|
2019-09-18 07:31:32 +02:00
|
|
|
Legacy.Check.init();
|
|
|
|
const result1 = Legacy.Check.getInit() && Legacy.Check.getStatus(),
|
|
|
|
result2 = secureProtocol === (document.getElementById('httpnotice').className === 'hidden');
|
2019-06-23 10:38:08 +02:00
|
|
|
clean();
|
|
|
|
return result1 && result2;
|
|
|
|
}
|
|
|
|
);
|
2019-06-22 09:12:31 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|