InitialCheck.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. 'use strict';
  2. var common = require('../common');
  3. /* global WebCrypto */
  4. describe('InitialCheck', 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. 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.nearray(common.jscA2zString()),
  61. function (secureProtocol, domain) {
  62. const clean = jsdom('', {
  63. 'url': (secureProtocol ? 'https' : 'http' ) + '://' + domain.join('') + '/'
  64. });
  65. $('body').html(
  66. '<html><body><div id="httpnotice" class="hidden"></div>'+
  67. '</body></html>'
  68. );
  69. $.PrivateBin.Alert.init();
  70. window.crypto = new WebCrypto();
  71. const result1 = $.PrivateBin.InitialCheck.init(),
  72. result2 = secureProtocol === $('#httpnotice').hasClass('hidden');
  73. clean();
  74. return result1 && result2;
  75. }
  76. );
  77. });
  78. });