InitialCheck.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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: 1});
  30. });
  31. it('shows error, if no webcrypto is detected', function () {
  32. [true, false].map(
  33. function (secureProtocol) {
  34. const clean = jsdom('', {
  35. 'url': (secureProtocol ? 'https' : 'http' ) + '://[::1]/'
  36. });
  37. $('body').html(
  38. '<html><body><div id="errormessage" class="hidden"></div>'+
  39. '<div id="oldnotice" class="hidden"></div></body></html>'
  40. );
  41. const crypto = window.crypto;
  42. window.crypto = null;
  43. $.PrivateBin.Alert.init();
  44. assert(!$.PrivateBin.InitialCheck.init());
  45. assert(secureProtocol === $('#errormessage').hasClass('hidden'));
  46. assert(!$('#oldnotice').hasClass('hidden'));
  47. window.crypto = crypto;
  48. clean();
  49. }
  50. );
  51. });
  52. it('shows error, if HTTP only site is detected', function () {
  53. [true, false].map(
  54. function (secureProtocol) {
  55. const clean = jsdom('', {
  56. 'url': (secureProtocol ? 'https' : 'http' ) + '://[::1]/'
  57. });
  58. $('body').html(
  59. '<html><body><div id="httpnotice" class="hidden"></div></body></html>'
  60. );
  61. assert($.PrivateBin.InitialCheck.init());
  62. assert(secureProtocol === $('#httpnotice').hasClass('hidden'));
  63. clean();
  64. }
  65. );
  66. });
  67. });
  68. });