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