Check.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. 'use strict';
  2. var common = require('../common');
  3. /* global Legacy, WebCrypto */
  4. describe('Check', function () {
  5. describe('init', function () {
  6. this.timeout(30000);
  7. it('returns false and shows error, if a bot UA is detected', function () {
  8. jsc.assert(jsc.forall(
  9. 'string',
  10. jsc.elements(['Bot', 'bot']),
  11. 'string',
  12. function (prefix, botBit, suffix) {
  13. const clean = jsdom(
  14. '<html><body><div id="errormessage" class="hidden"></div>' +
  15. '</body></html>', {
  16. 'userAgent': prefix + botBit + suffix
  17. }
  18. );
  19. Legacy.Check.init();
  20. const result1 = Legacy.Check.getInit() && !Legacy.Check.getStatus(),
  21. result2 = (document.getElementById('errormessage').className !== 'hidden');
  22. clean();
  23. return result1 && result2;
  24. }
  25. ),
  26. {tests: 10});
  27. });
  28. jsc.property(
  29. 'shows error, if no webcrypto is detected',
  30. 'bool',
  31. jsc.elements(['localhost', '127.0.0.1', '[::1]', '']),
  32. jsc.nearray(common.jscA2zString()),
  33. jsc.elements(['.onion', '.i2p', '']),
  34. function (secureProtocol, localhost, domain, tld) {
  35. const isDomain = localhost === '',
  36. isSecureContext = secureProtocol || !isDomain || tld.length > 0,
  37. clean = jsdom(
  38. '<html><body><div id="errormessage" class="hidden"></div>' +
  39. '<div id="oldnotice" class="hidden"></div>' +
  40. '<div id="insecurecontextnotice" class="hidden"></div></body></html>',
  41. {
  42. 'url': (secureProtocol ? 'https' : 'http' ) + '://' +
  43. (isDomain ? domain.join('') + tld : localhost) + '/'
  44. }
  45. );
  46. Legacy.Check.init();
  47. const result1 = Legacy.Check.getInit() && !Legacy.Check.getStatus(),
  48. result2 = isSecureContext === (document.getElementById('insecurecontextnotice').className === 'hidden'),
  49. result3 = (document.getElementById('oldnotice').className !== 'hidden');
  50. clean();
  51. return result1 && result2 && result3;
  52. }
  53. );
  54. jsc.property(
  55. 'shows error, if HTTP only site is detected',
  56. 'bool',
  57. jsc.nearray(common.jscA2zString()),
  58. function (secureProtocol, domain) {
  59. const clean = jsdom(
  60. '<html><body><div id="httpnotice" class="hidden"></div>' +
  61. '</body></html>',
  62. {
  63. 'url': (secureProtocol ? 'https' : 'http' ) + '://' + domain.join('') + '/'
  64. }
  65. );
  66. window.crypto = new WebCrypto();
  67. Legacy.Check.init();
  68. const result1 = Legacy.Check.getInit() && Legacy.Check.getStatus(),
  69. result2 = secureProtocol === (document.getElementById('httpnotice').className === 'hidden');
  70. clean();
  71. return result1 && result2;
  72. }
  73. );
  74. });
  75. });