background-step3-password-reuse.test.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. const test = require('node:test');
  2. const assert = require('node:assert/strict');
  3. const fs = require('node:fs');
  4. const source = fs.readFileSync('background/steps/fill-password.js', 'utf8');
  5. const globalScope = {};
  6. const api = new Function('self', `${source}; return self.MultiPageBackgroundStep3;`)(globalScope);
  7. test('step 3 reuses existing generated password when rerunning the same email flow', async () => {
  8. const events = {
  9. passwordStates: [],
  10. messages: [],
  11. };
  12. const executor = api.createStep3Executor({
  13. addLog: async () => {},
  14. chrome: { tabs: { update: async () => {} } },
  15. ensureContentScriptReadyOnTab: async () => {},
  16. generatePassword: () => 'Generated-Should-Not-Be-Used',
  17. getTabId: async () => 88,
  18. isTabAlive: async () => true,
  19. sendToContentScript: async (_source, message) => {
  20. events.messages.push(message);
  21. },
  22. setPasswordState: async (password) => {
  23. events.passwordStates.push(password);
  24. },
  25. setState: async () => {},
  26. SIGNUP_PAGE_INJECT_FILES: [],
  27. });
  28. await executor.executeStep3({
  29. email: 'keep@example.com',
  30. password: 'Secret123!',
  31. customPassword: '',
  32. accounts: [],
  33. });
  34. assert.deepStrictEqual(events.passwordStates, ['Secret123!']);
  35. assert.deepStrictEqual(events.messages, [
  36. {
  37. type: 'EXECUTE_STEP',
  38. step: 3,
  39. source: 'background',
  40. payload: {
  41. email: 'keep@example.com',
  42. password: 'Secret123!',
  43. },
  44. },
  45. ]);
  46. });