Prompt.js 1.6 KB

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