Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Update tests (#2100)

Leendert de Borst4a4314539352
diff --git a/apps/browser-extension/src/utils/loginDetector/__tests__/LoginDetector.excludedDomains.test.ts b/apps/browser-extension/src/utils/loginDetector/__tests__/LoginDetector.excludedDomains.test.ts
index 0d341bb41..2b7e0a090 100644
--- a/apps/browser-extension/src/utils/loginDetector/__tests__/LoginDetector.excludedDomains.test.ts
+++ b/apps/browser-extension/src/utils/loginDetector/__tests__/LoginDetector.excludedDomains.test.ts
@@ -4,49 +4,6 @@ import { LoginDetector } from '../LoginDetector';
import { createTestEnvironment, cleanupTestEnvironment, setGlobalWindow } from './TestUtils';
-describe('LoginDetector excluded domains', () => {
- let detector: LoginDetector;
-
- afterEach(() => {
- if (detector) {
- detector.destroy();
- }
- cleanupTestEnvironment();
- });
-
- const excludedUrls = [
- 'https://aliasvault.net/login',
- 'https://subdomain.aliasvault.net/login',
- ];
-
- excludedUrls.forEach((url) => {
- it(`should skip ${url}`, () => {
- const { document, window } = createTestEnvironment(
- `<html><body>
- <form>
- <input type="text" value="user">
- <input type="password" value="pass">
- </form>
- </body></html>`,
- url
- );
- setGlobalWindow(window);
-
- detector = new LoginDetector(document);
- detector.initialize();
-
- const callback = vi.fn();
- detector.onLoginCapture(callback);
-
- const form = document.querySelector('form');
- form?.dispatchEvent(new window.Event('submit', { bubbles: true }));
-
- vi.runAllTimers();
- expect(callback).not.toHaveBeenCalled();
- });
- });
-});
-
describe('LoginDetector av-disable attribute', () => {
let detector: LoginDetector;
@@ -153,3 +110,120 @@ describe('LoginDetector av-disable attribute', () => {
expect(callback).toHaveBeenCalled();
});
});
+
+describe('LoginDetector av-enable attribute', () => {
+ let detector: LoginDetector;
+
+ afterEach(() => {
+ if (detector) {
+ detector.destroy();
+ }
+ cleanupTestEnvironment();
+ });
+
+ it('should capture when av-enable="true" overrides av-disable on body', () => {
+ const { document, window } = createTestEnvironment(
+ `<html><body av-disable="true">
+ <div av-enable="true">
+ <form>
+ <input type="text" value="user">
+ <input type="password" value="pass">
+ </form>
+ </div>
+ </body></html>`
+ );
+ setGlobalWindow(window);
+
+ detector = new LoginDetector(document);
+ detector.initialize();
+
+ const callback = vi.fn();
+ detector.onLoginCapture(callback);
+
+ const form = document.querySelector('form');
+ form?.dispatchEvent(new window.Event('submit', { bubbles: true }));
+
+ vi.runAllTimers();
+ expect(callback).toHaveBeenCalled();
+ });
+
+ it('should capture when av-enable="true" is set directly on the form', () => {
+ const { document, window } = createTestEnvironment(
+ `<html><body av-disable="true">
+ <form av-enable="true">
+ <input type="text" value="user">
+ <input type="password" value="pass">
+ </form>
+ </body></html>`
+ );
+ setGlobalWindow(window);
+
+ detector = new LoginDetector(document);
+ detector.initialize();
+
+ const callback = vi.fn();
+ detector.onLoginCapture(callback);
+
+ const form = document.querySelector('form');
+ form?.dispatchEvent(new window.Event('submit', { bubbles: true }));
+
+ vi.runAllTimers();
+ expect(callback).toHaveBeenCalled();
+ });
+
+ it('should skip a form that is opted in via av-enable but also marked av-suppress-save', () => {
+ const { document, window } = createTestEnvironment(
+ `<html><body av-disable="true">
+ <form av-enable="true" av-suppress-save="true">
+ <input type="text" value="user">
+ <input type="password" value="pass">
+ </form>
+ </body></html>`
+ );
+ setGlobalWindow(window);
+
+ detector = new LoginDetector(document);
+ detector.initialize();
+
+ const callback = vi.fn();
+ detector.onLoginCapture(callback);
+
+ const form = document.querySelector('form');
+ form?.dispatchEvent(new window.Event('submit', { bubbles: true }));
+
+ vi.runAllTimers();
+ expect(callback).not.toHaveBeenCalled();
+ });
+
+ it('should still skip sibling forms when av-enable is scoped elsewhere', () => {
+ const { document, window } = createTestEnvironment(
+ `<html><body av-disable="true">
+ <div av-enable="true">
+ <form id="opted-in">
+ <input type="text" value="alice">
+ <input type="password" value="pw1">
+ </form>
+ </div>
+ <form id="still-disabled">
+ <input type="text" value="bob">
+ <input type="password" value="pw2">
+ </form>
+ </body></html>`
+ );
+ setGlobalWindow(window);
+
+ detector = new LoginDetector(document);
+ detector.initialize();
+
+ const callback = vi.fn();
+ detector.onLoginCapture(callback);
+
+ document.getElementById('still-disabled')?.dispatchEvent(new window.Event('submit', { bubbles: true }));
+ vi.runAllTimers();
+ expect(callback).not.toHaveBeenCalled();
+
+ document.getElementById('opted-in')?.dispatchEvent(new window.Event('submit', { bubbles: true }));
+ vi.runAllTimers();
+ expect(callback).toHaveBeenCalled();
+ });
+});
diff --git a/apps/browser-extension/src/utils/loginDetector/__tests__/LoginDetector.lifecycle.test.ts b/apps/browser-extension/src/utils/loginDetector/__tests__/LoginDetector.lifecycle.test.ts
index d181e9216..8b9c3f728 100644
--- a/apps/browser-extension/src/utils/loginDetector/__tests__/LoginDetector.lifecycle.test.ts
+++ b/apps/browser-extension/src/utils/loginDetector/__tests__/LoginDetector.lifecycle.test.ts
@@ -36,26 +36,6 @@ describe('LoginDetector lifecycle', () => {
expect(detector).toBeInstanceOf(LoginDetector);
});
- it('should skip initialization for excluded domains', () => {
- const { document, window } = createTestEnvironment(
- '<html><body><form><input type="password"></form></body></html>',
- 'https://aliasvault.net/login'
- );
- setGlobalWindow(window);
-
- detector = new LoginDetector(document);
- detector.initialize();
-
- const callback = vi.fn();
- detector.onLoginCapture(callback);
-
- const form = document.querySelector('form');
- form?.dispatchEvent(new window.Event('submit', { bubbles: true }));
-
- vi.runAllTimers();
- expect(callback).not.toHaveBeenCalled();
- });
-
it('should allow localhost (for self-hosted users)', () => {
const { document, window } = createTestEnvironment(
`<html><body><form>