InitialCheck.js 3.6 KB

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