Prompt.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict';
  2. require('../common');
  3. describe('Prompt', function () {
  4. // TODO: this does not test the prompt() fallback, since that isn't available
  5. // in nodejs -> replace the prompt in the "page" template with a modal
  6. describe('requestPassword & getPassword', function () {
  7. this.timeout(30000);
  8. jsc.property(
  9. 'returns the password fed into the dialog',
  10. 'string',
  11. function (password) {
  12. password = password.replace(/\r+/g, '');
  13. var clean = jsdom('', {url: 'ftp://example.com/?0'});
  14. $('body').html(
  15. '<div id="passwordmodal" class="modal fade" role="dialog">' +
  16. '<div class="modal-dialog"><div class="modal-content">' +
  17. '<div class="modal-body"><form id="passwordform" role="form">' +
  18. '<div class="form-group"><input id="passworddecrypt" ' +
  19. 'type="password" class="form-control" placeholder="Enter ' +
  20. 'password"></div><button type="submit">Decrypt</button>' +
  21. '</form></div></div></div></div>'
  22. );
  23. $.PrivateBin.Model.reset();
  24. $.PrivateBin.Model.init();
  25. $.PrivateBin.Prompt.init();
  26. $.PrivateBin.Prompt.requestPassword();
  27. $('#passworddecrypt').val(password);
  28. $('#passwordform').submit();
  29. var result = $.PrivateBin.Prompt.getPassword();
  30. $.PrivateBin.Model.reset();
  31. clean();
  32. return result === password;
  33. }
  34. );
  35. });
  36. });