InitialCheck.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. $.PrivateBin.Alert.init();
  49. const result1 = !$.PrivateBin.InitialCheck.init(),
  50. result2 = isSecureContext === $('#errormessage').hasClass('hidden'),
  51. result3 = !$('#oldnotice').hasClass('hidden');
  52. clean();
  53. return result1 && result2 && result3;
  54. }
  55. );
  56. jsc.property(
  57. 'shows error, if HTTP only site is detected',
  58. 'bool',
  59. jsc.nearray(common.jscA2zString()),
  60. function (secureProtocol, domain) {
  61. const clean = jsdom('', {
  62. 'url': (secureProtocol ? 'https' : 'http' ) + '://' + domain.join('') + '/'
  63. });
  64. $('body').html(
  65. '<html><body><div id="httpnotice" class="hidden"></div>'+
  66. '</body></html>'
  67. );
  68. $.PrivateBin.Alert.init();
  69. window.crypto = new WebCrypto();
  70. const result1 = $.PrivateBin.InitialCheck.init(),
  71. result2 = secureProtocol === $('#httpnotice').hasClass('hidden');
  72. clean();
  73. return result1 && result2;
  74. }
  75. );
  76. });
  77. });