'use strict';
require('../common');
const fc = require('fast-check');
describe('Prompt', function () {
describe('requestPassword & getPassword', function () {
this.timeout(30000);
it('returns the password fed into the dialog', () => {
fc.assert(fc.property(
fc.string(),
function (password) {
password = password.replace(/\r+|\n+/g, '');
const clean = globalThis.cleanup('', {url: 'ftp://example.com/?0000000000000000'});
document.body.innerHTML = `
`;
// Initialize the Prompt module to set up event listeners
PrivateBin.Alert.init();
PrivateBin.TopNav.init();
PrivateBin.Prompt.init();
PrivateBin.Prompt.requestPassword();
// mock request response
const originalFetch = globalThis.fetch;
globalThis.fetch = function (url) {
assert.strictEqual(url, 'ftp://example.com/?pasteid=0000000000000000');
return Promise.resolve({
ok: true,
status: 200,
statusText: 'OK',
json: function () {
return Promise.resolve({});
}
});
};
// Simulate user input
const passwordInput = document.getElementById('passworddecrypt');
passwordInput.value = password;
// Simulate form submission to trigger password capture
const passwordForm = document.getElementById('passwordform');
/** {@type SubmitEvent} */
const submitEvent = new Event('submit', { bubbles: true, cancelable: true });
passwordForm.dispatchEvent(submitEvent);
// Verify that getPassword returns the submitted password
const result = PrivateBin.Prompt.getPassword();
globalThis.fetch = originalFetch;
clean();
return result === password;
}
));
});
});
});