Prompt.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. before(function () {
  9. $.PrivateBin.Model.reset();
  10. cleanup();
  11. });
  12. jsc.property(
  13. 'returns the password fed into the dialog',
  14. 'string',
  15. function (password) {
  16. password = password.replace(/\r+/g, '');
  17. var clean = jsdom('', {url: 'ftp://example.com/?0'});
  18. $('body').html(
  19. '<div id="passwordmodal" class="modal fade" role="dialog">' +
  20. '<div class="modal-dialog"><div class="modal-content">' +
  21. '<div class="modal-body"><form id="passwordform" role="form">' +
  22. '<div class="form-group"><input id="passworddecrypt" ' +
  23. 'type="password" class="form-control" placeholder="Enter ' +
  24. 'password"></div><button type="submit">Decrypt</button>' +
  25. '</form></div></div></div></div>'
  26. );
  27. $.PrivateBin.Model.init();
  28. $.PrivateBin.Prompt.init();
  29. $.PrivateBin.Prompt.requestPassword();
  30. $('#passworddecrypt').val(password);
  31. $('#passwordform').submit();
  32. var result = $.PrivateBin.Prompt.getPassword();
  33. $.PrivateBin.Model.reset();
  34. clean();
  35. return result === password;
  36. }
  37. );
  38. });
  39. });