Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update tests (#1848)
Leendert de Borstf3daf5165712
diff --git a/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.nl.test.ts b/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.nl.test.tsindex c3ec679a7..7c01f1634 100644--- a/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.nl.test.ts+++ b/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.nl.test.ts@@ -1,6 +1,8 @@import { describe, it, expect } from 'vitest';-import { FormField, testField, testBirthdateFormat } from './TestUtils';+import { FormDetector } from '../FormDetector';++import { FormField, testField, testBirthdateFormat, createTestDom } from './TestUtils';describe('FormDetector Dutch tests', () => {it('contains tests for Dutch form field detection', () => {@@ -116,4 +118,105 @@ describe('FormDetector Dutch tests', () => {testField(FormField.LastName, 'Field642', htmlFile);testField(FormField.BirthDate, 'Field675', htmlFile);});++ describe('Dutch login form 1 detection', () => {+ const htmlFile = 'nl-login-form1.html';++ testField(FormField.Username, 'login_form_user', htmlFile);+ testField(FormField.Password, 'login_form_password', htmlFile);++ it('should detect username field despite autocomplete="off"', () => {+ const dom = createTestDom(htmlFile);+ const doc = dom.window.document;++ const usernameInput = doc.getElementById('login_form_user') as HTMLInputElement;+ expect(usernameInput).not.toBeNull();+ expect(usernameInput.getAttribute('autocomplete')).toBe('off');++ const formDetector = new FormDetector(doc, usernameInput);+ const detectedFields = formDetector.getForm();++ expect(detectedFields?.usernameField).toBe(usernameInput);+ expect(detectedFields?.usernameField?.id).toBe('login_form_user');+ });++ it('should detect password field with autocomplete="current-password"', () => {+ const dom = createTestDom(htmlFile);+ const doc = dom.window.document;++ const passwordInput = doc.getElementById('login_form_password') as HTMLInputElement;+ expect(passwordInput).not.toBeNull();+ expect(passwordInput.getAttribute('autocomplete')).toBe('current-password');++ const formDetector = new FormDetector(doc, passwordInput);+ const detectedFields = formDetector.getForm();++ expect(detectedFields?.passwordField).toBe(passwordInput);+ expect(detectedFields?.passwordField?.id).toBe('login_form_password');+ });++ it('should not detect hidden fields as login fields', () => {+ const dom = createTestDom(htmlFile);+ const doc = dom.window.document;++ const usernameInput = doc.getElementById('login_form_user') as HTMLInputElement;+ const formDetector = new FormDetector(doc, usernameInput);+ const detectedFields = formDetector.getForm();++ const hiddenLocation = doc.getElementById('login_form_location') as HTMLInputElement;+ const hiddenToken = doc.getElementById('login_form__token') as HTMLInputElement;++ expect(detectedFields?.usernameField).not.toBe(hiddenLocation);+ expect(detectedFields?.usernameField).not.toBe(hiddenToken);+ expect(detectedFields?.passwordField).not.toBe(hiddenLocation);+ expect(detectedFields?.passwordField).not.toBe(hiddenToken);+ });++ it('should not detect session option fields as login fields', () => {+ const dom = createTestDom(htmlFile);+ const doc = dom.window.document;++ const usernameInput = doc.getElementById('login_form_user') as HTMLInputElement;+ const formDetector = new FormDetector(doc, usernameInput);+ const detectedFields = formDetector.getForm();++ const sessionNameInput = doc.getElementById('login_form_sessionName') as HTMLInputElement;+ const durationSelect = doc.getElementById('login_form_duration') as HTMLSelectElement;++ expect(detectedFields?.usernameField).not.toBe(sessionNameInput);+ expect(detectedFields?.usernameField).not.toBe(durationSelect);+ expect(detectedFields?.passwordField).not.toBe(sessionNameInput);+ });++ it('should detect both username and password fields from the same form', () => {+ const dom = createTestDom(htmlFile);+ const doc = dom.window.document;++ const usernameInput = doc.getElementById('login_form_user') as HTMLInputElement;+ const passwordInput = doc.getElementById('login_form_password') as HTMLInputElement;++ const formDetector = new FormDetector(doc, usernameInput);+ const detectedFields = formDetector.getForm();++ expect(detectedFields?.usernameField).toBe(usernameInput);+ expect(detectedFields?.passwordField).toBe(passwordInput);+ });++ it('should handle form detection when clicking on username field with multiple inputs nearby', () => {+ const dom = createTestDom(htmlFile);+ const doc = dom.window.document;++ const usernameInput = doc.getElementById('login_form_user') as HTMLInputElement;+ const formDetector = new FormDetector(doc, usernameInput);++ expect(formDetector.containsLoginForm()).toBe(true);++ const detectedFields = formDetector.getForm();++ expect(detectedFields?.usernameField).toBeTruthy();+ expect(detectedFields?.passwordField).toBeTruthy();+ expect(detectedFields?.emailField).toBeFalsy();+ expect(detectedFields?.passwordConfirmField).toBeFalsy();+ });+ });});diff --git a/apps/browser-extension/src/utils/formDetector/__tests__/FormDetectorFiller.nl-login-form1.test.ts b/apps/browser-extension/src/utils/formDetector/__tests__/FormDetectorFiller.nl-login-form1.test.tsdeleted file mode 100644index b1cdcd68d..000000000--- a/apps/browser-extension/src/utils/formDetector/__tests__/FormDetectorFiller.nl-login-form1.test.ts+++ /dev/null@@ -1,268 +0,0 @@-import { describe, it, expect, vi, beforeEach } from 'vitest';--import type { Credential } from '@/utils/dist/core/models/vault';--import { FormDetector } from '../FormDetector';-import { FormFiller } from '../FormFiller';--import { createTestDom, createMockCredential, wasTriggerCalledFor } from './TestUtils';--/**- * Tests for Dutch login form with multiple hidden fields and session options.- */-describe('Dutch login form 1 detection and filling', () => {- const htmlFile = 'nl-login-form1.html';-- describe('Field detection', () => {- it('should detect username field despite autocomplete="off"', () => {- const dom = createTestDom(htmlFile);- const doc = dom.window.document;-- // Get the username input field- const usernameInput = doc.getElementById('login_form_user') as HTMLInputElement;- expect(usernameInput).not.toBeNull();- expect(usernameInput.getAttribute('autocomplete')).toBe('off');-- // Create form detector with username field focused- const formDetector = new FormDetector(doc, usernameInput);- const detectedFields = formDetector.getForm();-- // Verify username field is detected despite autocomplete="off"- expect(detectedFields?.usernameField).toBe(usernameInput);- expect(detectedFields?.usernameField?.id).toBe('login_form_user');- });-- it('should detect password field with autocomplete="current-password"', () => {- const dom = createTestDom(htmlFile);- const doc = dom.window.document;-- // Get the password input field- const passwordInput = doc.getElementById('login_form_password') as HTMLInputElement;- expect(passwordInput).not.toBeNull();- expect(passwordInput.getAttribute('autocomplete')).toBe('current-password');-- // Create form detector with password field focused- const formDetector = new FormDetector(doc, passwordInput);- const detectedFields = formDetector.getForm();-- // Verify password field is detected- expect(detectedFields?.passwordField).toBe(passwordInput);- expect(detectedFields?.passwordField?.id).toBe('login_form_password');- });-- it('should not detect hidden fields as login fields', () => {- const dom = createTestDom(htmlFile);- const doc = dom.window.document;-- const usernameInput = doc.getElementById('login_form_user') as HTMLInputElement;- const formDetector = new FormDetector(doc, usernameInput);- const detectedFields = formDetector.getForm();-- // Verify hidden fields are not detected- const hiddenLocation = doc.getElementById('login_form_location') as HTMLInputElement;- const hiddenToken = doc.getElementById('login_form__token') as HTMLInputElement;-- expect(detectedFields?.usernameField).not.toBe(hiddenLocation);- expect(detectedFields?.usernameField).not.toBe(hiddenToken);- expect(detectedFields?.passwordField).not.toBe(hiddenLocation);- expect(detectedFields?.passwordField).not.toBe(hiddenToken);- });-- it('should not detect session option fields as login fields', () => {- const dom = createTestDom(htmlFile);- const doc = dom.window.document;-- const usernameInput = doc.getElementById('login_form_user') as HTMLInputElement;- const formDetector = new FormDetector(doc, usernameInput);- const detectedFields = formDetector.getForm();-- // Verify session option fields are not detected as login fields- const sessionNameInput = doc.getElementById('login_form_sessionName') as HTMLInputElement;- const durationSelect = doc.getElementById('login_form_duration') as HTMLSelectElement;-- expect(detectedFields?.usernameField).not.toBe(sessionNameInput);- expect(detectedFields?.usernameField).not.toBe(durationSelect);- expect(detectedFields?.passwordField).not.toBe(sessionNameInput);- });-- it('should detect both username and password fields from the same form', () => {- const dom = createTestDom(htmlFile);- const doc = dom.window.document;-- const usernameInput = doc.getElementById('login_form_user') as HTMLInputElement;- const passwordInput = doc.getElementById('login_form_password') as HTMLInputElement;-- // Detect from username field focus- const formDetector = new FormDetector(doc, usernameInput);- const detectedFields = formDetector.getForm();-- // Both fields should be detected- expect(detectedFields?.usernameField).toBe(usernameInput);- expect(detectedFields?.passwordField).toBe(passwordInput);- });- });-- describe('Field filling', () => {- let mockCredential: Credential;-- beforeEach(() => {- mockCredential = createMockCredential();- });-- it('should fill username field successfully', async () => {- const dom = createTestDom(htmlFile);- const doc = dom.window.document;-- const usernameInput = doc.getElementById('login_form_user') as HTMLInputElement;- const formDetector = new FormDetector(doc, usernameInput);- const detectedFields = formDetector.getForm();-- expect(detectedFields).not.toBeNull();-- if (detectedFields) {- const triggerMock = vi.fn();- const filler = new FormFiller(detectedFields, triggerMock);- await filler.fillFields(mockCredential);-- // Verify username is filled- expect(usernameInput.value).toBe('testuser');- expect(wasTriggerCalledFor(triggerMock, usernameInput)).toBe(true);- }- });-- it('should fill password field successfully', async () => {- const dom = createTestDom(htmlFile);- const doc = dom.window.document;-- const passwordInput = doc.getElementById('login_form_password') as HTMLInputElement;- const formDetector = new FormDetector(doc, passwordInput);- const detectedFields = formDetector.getForm();-- expect(detectedFields).not.toBeNull();-- if (detectedFields) {- const triggerMock = vi.fn();- const filler = new FormFiller(detectedFields, triggerMock);- await filler.fillFields(mockCredential);-- // Delay for password filling (character-by-character)- await new Promise(resolve => setTimeout(resolve, 150));-- // Verify password is filled- expect(passwordInput.value).toBe('testpass');- expect(wasTriggerCalledFor(triggerMock, passwordInput)).toBe(true);- }- });-- it('should fill both username and password fields without filling other fields', async () => {- const dom = createTestDom(htmlFile);- const doc = dom.window.document;-- const usernameInput = doc.getElementById('login_form_user') as HTMLInputElement;- const passwordInput = doc.getElementById('login_form_password') as HTMLInputElement;- const sessionNameInput = doc.getElementById('login_form_sessionName') as HTMLInputElement;- const hiddenLocation = doc.getElementById('login_form_location') as HTMLInputElement;-- const formDetector = new FormDetector(doc, usernameInput);- const detectedFields = formDetector.getForm();-- expect(detectedFields).not.toBeNull();-- if (detectedFields) {- const triggerMock = vi.fn();- const filler = new FormFiller(detectedFields, triggerMock);- await filler.fillFields(mockCredential);-- // Delay for password filling- await new Promise(resolve => setTimeout(resolve, 150));-- // Verify correct fields are filled- expect(usernameInput.value).toBe('testuser');- expect(passwordInput.value).toBe('testpass');-- // Verify other fields are NOT filled- expect(sessionNameInput.value).toBe('');- expect(hiddenLocation.value).toBe('https://example.com/');-- // Verify trigger events were called for the correct fields only- expect(wasTriggerCalledFor(triggerMock, usernameInput)).toBe(true);- expect(wasTriggerCalledFor(triggerMock, passwordInput)).toBe(true);- expect(wasTriggerCalledFor(triggerMock, sessionNameInput)).toBe(false);- expect(wasTriggerCalledFor(triggerMock, hiddenLocation)).toBe(false);- }- });-- it('should handle form with credential containing email', async () => {- const dom = createTestDom(htmlFile);- const doc = dom.window.document;-- const usernameInput = doc.getElementById('login_form_user') as HTMLInputElement;- const formDetector = new FormDetector(doc, usernameInput);- const detectedFields = formDetector.getForm();-- expect(detectedFields).not.toBeNull();-- if (detectedFields) {- const triggerMock = vi.fn();- const filler = new FormFiller(detectedFields, triggerMock);-- // Credential with email should use username if username field exists- await filler.fillFields(mockCredential);-- // Username field should be filled with username, not email- expect(usernameInput.value).toBe('testuser');- expect(usernameInput.value).not.toBe('[email protected]');- }- });- });-- describe('Edge cases and regressions', () => {- it('should only fill the actual username field, not hidden fields that might match patterns', async () => {- const dom = createTestDom(htmlFile);- const doc = dom.window.document;-- const usernameInput = doc.getElementById('login_form_user') as HTMLInputElement;- const formDetector = new FormDetector(doc, usernameInput);- const detectedFields = formDetector.getForm();-- expect(detectedFields).not.toBeNull();-- if (detectedFields) {- const triggerMock = vi.fn();- const filler = new FormFiller(detectedFields, triggerMock);- await filler.fillFields(createMockCredential());-- // Check that only the visible username field was filled- const allInputs = Array.from(doc.querySelectorAll('input[type="text"]')) as HTMLInputElement[];- const filledInputs = allInputs.filter(input => input.value !== '');-- /*- * Should have exactly one filled text input (the username field)- * Session name field should remain empty- */- expect(filledInputs.length).toBe(1);- expect(filledInputs[0]).toBe(usernameInput);- }- });-- it('should handle form detection when clicking on username field with multiple inputs nearby', () => {- const dom = createTestDom(htmlFile);- const doc = dom.window.document;-- // Simulate clicking the username field- const usernameInput = doc.getElementById('login_form_user') as HTMLInputElement;- const formDetector = new FormDetector(doc, usernameInput);-- // Form should be detected as a login form- expect(formDetector.containsLoginForm()).toBe(true);-- const detectedFields = formDetector.getForm();-- // Should detect exactly the right fields, not extras- expect(detectedFields?.usernameField).toBeTruthy();- expect(detectedFields?.passwordField).toBeTruthy();- expect(detectedFields?.emailField).toBeFalsy(); // No separate email field- expect(detectedFields?.passwordConfirmField).toBeFalsy(); // No password confirm- });- });-});diff --git a/apps/browser-extension/src/utils/formDetector/__tests__/FormFiller.nl.test.ts b/apps/browser-extension/src/utils/formDetector/__tests__/FormFiller.nl.test.tsindex 83e42f4a0..35cb814f0 100644--- a/apps/browser-extension/src/utils/formDetector/__tests__/FormFiller.nl.test.ts+++ b/apps/browser-extension/src/utils/formDetector/__tests__/FormFiller.nl.test.ts@@ -3,10 +3,11 @@ import { describe, it, expect, beforeEach, vi } from 'vitest';import type { Credential } from '@/utils/dist/core/models/vault';+import { FormDetector } from '../FormDetector';import { FormFiller } from '../FormFiller';import { FormFields } from '../types/FormFields';-import { setupTestDOM, createMockFormFields, createMockCredential, wasTriggerCalledFor, createDateSelects } from './TestUtils';+import { setupTestDOM, createMockFormFields, createMockCredential, wasTriggerCalledFor, createDateSelects, createTestDom } from './TestUtils';const { window } = new JSDOM('<!DOCTYPE html>');global.HTMLSelectElement = window.HTMLSelectElement;@@ -62,4 +63,133 @@ describe('FormFiller Dutch', () => {expect(wasTriggerCalledFor(mockTriggerInputEvents, yearSelect)).toBe(true);});});++ describe('Dutch login form 1 field filling', () => {+ const htmlFile = 'nl-login-form1.html';+ let mockCredential: Credential;++ beforeEach(() => {+ mockCredential = createMockCredential();+ });++ it('should fill username field successfully', async () => {+ const dom = createTestDom(htmlFile);+ const doc = dom.window.document;++ const usernameInput = doc.getElementById('login_form_user') as HTMLInputElement;+ const formDetector = new FormDetector(doc, usernameInput);+ const detectedFields = formDetector.getForm();++ expect(detectedFields).not.toBeNull();++ if (detectedFields) {+ const triggerMock = vi.fn();+ const filler = new FormFiller(detectedFields, triggerMock);+ await filler.fillFields(mockCredential);++ expect(usernameInput.value).toBe('testuser');+ expect(wasTriggerCalledFor(triggerMock, usernameInput)).toBe(true);+ }+ });++ it('should fill password field successfully', async () => {+ const dom = createTestDom(htmlFile);+ const doc = dom.window.document;++ const passwordInput = doc.getElementById('login_form_password') as HTMLInputElement;+ const formDetector = new FormDetector(doc, passwordInput);+ const detectedFields = formDetector.getForm();++ expect(detectedFields).not.toBeNull();++ if (detectedFields) {+ const triggerMock = vi.fn();+ const filler = new FormFiller(detectedFields, triggerMock);+ await filler.fillFields(mockCredential);++ await new Promise(resolve => setTimeout(resolve, 150));++ expect(passwordInput.value).toBe('testpass');+ expect(wasTriggerCalledFor(triggerMock, passwordInput)).toBe(true);+ }+ });++ it('should fill both username and password fields without filling other fields', async () => {+ const dom = createTestDom(htmlFile);+ const doc = dom.window.document;++ const usernameInput = doc.getElementById('login_form_user') as HTMLInputElement;+ const passwordInput = doc.getElementById('login_form_password') as HTMLInputElement;+ const sessionNameInput = doc.getElementById('login_form_sessionName') as HTMLInputElement;+ const hiddenLocation = doc.getElementById('login_form_location') as HTMLInputElement;++ const formDetector = new FormDetector(doc, usernameInput);+ const detectedFields = formDetector.getForm();++ expect(detectedFields).not.toBeNull();++ if (detectedFields) {+ const triggerMock = vi.fn();+ const filler = new FormFiller(detectedFields, triggerMock);+ await filler.fillFields(mockCredential);++ await new Promise(resolve => setTimeout(resolve, 150));++ expect(usernameInput.value).toBe('testuser');+ expect(passwordInput.value).toBe('testpass');++ expect(sessionNameInput.value).toBe('');+ expect(hiddenLocation.value).toBe('https://example.com/');++ expect(wasTriggerCalledFor(triggerMock, usernameInput)).toBe(true);+ expect(wasTriggerCalledFor(triggerMock, passwordInput)).toBe(true);+ expect(wasTriggerCalledFor(triggerMock, sessionNameInput)).toBe(false);+ expect(wasTriggerCalledFor(triggerMock, hiddenLocation)).toBe(false);+ }+ });++ it('should handle form with credential containing email', async () => {+ const dom = createTestDom(htmlFile);+ const doc = dom.window.document;++ const usernameInput = doc.getElementById('login_form_user') as HTMLInputElement;+ const formDetector = new FormDetector(doc, usernameInput);+ const detectedFields = formDetector.getForm();++ expect(detectedFields).not.toBeNull();++ if (detectedFields) {+ const triggerMock = vi.fn();+ const filler = new FormFiller(detectedFields, triggerMock);++ await filler.fillFields(mockCredential);++ expect(usernameInput.value).toBe('testuser');+ expect(usernameInput.value).not.toBe('[email protected]');+ }+ });++ it('should only fill the actual username field, not hidden fields that might match patterns', async () => {+ const dom = createTestDom(htmlFile);+ const doc = dom.window.document;++ const usernameInput = doc.getElementById('login_form_user') as HTMLInputElement;+ const formDetector = new FormDetector(doc, usernameInput);+ const detectedFields = formDetector.getForm();++ expect(detectedFields).not.toBeNull();++ if (detectedFields) {+ const triggerMock = vi.fn();+ const filler = new FormFiller(detectedFields, triggerMock);+ await filler.fillFields(createMockCredential());++ const allInputs = Array.from(doc.querySelectorAll('input[type="text"]')) as HTMLInputElement[];+ const filledInputs = allInputs.filter(input => input.value !== '');++ expect(filledInputs.length).toBe(1);+ expect(filledInputs[0]).toBe(usernameInput);+ }+ });+ });});\ No newline at end of file