Check.js 3.4 KB

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