InitialCheck.js 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. const result1 = !$.PrivateBin.InitialCheck.init(),
  24. result2 = !$('#errormessage').hasClass('hidden');
  25. clean();
  26. return result1 && result2;
  27. }
  28. ),
  29. {tests: 10});
  30. });
  31. jsc.property(
  32. 'shows error, if no webcrypto is detected',
  33. 'bool',
  34. jsc.elements(['localhost', '127.0.0.1', '[::1]', '']),
  35. jsc.nearray(common.jscA2zString()),
  36. jsc.elements(['.onion', '.i2p', '']),
  37. function (secureProtocol, localhost, domain, tld) {
  38. const isDomain = localhost === '',
  39. isSecureContext = secureProtocol || !isDomain || tld.length > 0,
  40. clean = jsdom('', {
  41. 'url': (secureProtocol ? 'https' : 'http' ) + '://' +
  42. (isDomain ? domain.join('') + tld : localhost) + '/'
  43. });
  44. $('body').html(
  45. '<html><body><div id="errormessage" class="hidden"></div>'+
  46. '<div id="oldnotice" class="hidden"></div></body></html>'
  47. );
  48. const crypto = window.crypto;
  49. window.crypto = null;
  50. $.PrivateBin.Alert.init();
  51. const result1 = !$.PrivateBin.InitialCheck.init(),
  52. result2 = isSecureContext === $('#errormessage').hasClass('hidden'),
  53. result3 = !$('#oldnotice').hasClass('hidden');
  54. window.crypto = crypto;
  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.elements(['localhost', '127.0.0.1', '[::1]', '']),
  63. jsc.nearray(common.jscA2zString()),
  64. jsc.elements(['.onion', '.i2p', '']),
  65. function (secureProtocol, localhost, domain, tld) {
  66. const isDomain = localhost === '',
  67. isSecureContext = secureProtocol || !isDomain || tld.length > 0,
  68. clean = jsdom('', {
  69. 'url': (secureProtocol ? 'https' : 'http' ) + '://' +
  70. (isDomain ? domain.join('') + tld : localhost) + '/'
  71. });
  72. $('body').html(
  73. '<html><body><div id="httpnotice" class="hidden"></div>'+
  74. '</body></html>'
  75. );
  76. $.PrivateBin.Alert.init();
  77. const result1 = $.PrivateBin.InitialCheck.init(),
  78. result2 = isSecureContext === $('#httpnotice').hasClass('hidden');
  79. clean();
  80. return result1 && result2;
  81. }
  82. );
  83. });
  84. });