Skip to content

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

Add tests for all import services (#2413)

Leendert de Borst99c82533d34e
diff --git a/core/client/src/transfer/export/__tests__/AliasVaultCsvExportService.test.ts b/core/client/src/transfer/export/__tests__/AliasVaultCsvExportService.test.ts
new file mode 100644
index 000000000..9f5027b2b
--- /dev/null
+++ b/core/client/src/transfer/export/__tests__/AliasVaultCsvExportService.test.ts
@@ -0,0 +1,98 @@
+import { FieldKey, ItemTypes } from '@aliasvault/models/vault';
+import { describe, expect, it } from 'vitest';
+
+import { byName, utc } from '../../import/__tests__/testHelpers';
+import { AliasVaultCsvImportService } from '../../import/importers/aliasvault/AliasVaultCsvImportService';
+import { convertToItems } from '../../import/writers/ItemConverter';
+import { AliasVaultCsvExportService } from '../AliasVaultCsvExportService';
+
+import { createAppItem, csvText } from './testHelpers';
+
+describe('AliasVaultCsvExportService', () => {
+ it('re-imports an exported item from CSV unchanged', () => {
+ const item = createAppItem('Test Service', ItemTypes.Login, {
+ [FieldKey.LoginUsername]: 'testuser',
+ [FieldKey.NotesContent]: 'Test notes',
+ [FieldKey.LoginUrl]: 'https://testservice.com',
+ [FieldKey.LoginPassword]: 'password123',
+ [FieldKey.LoginEmail]: 'johndoe',
+ [FieldKey.AliasGender]: 'Male',
+ [FieldKey.AliasFirstName]: 'John',
+ [FieldKey.AliasLastName]: 'Doe',
+ [FieldKey.AliasBirthdate]: '1990-01-01',
+ });
+
+ const csv = csvText(AliasVaultCsvExportService.exportItemsToCsv([item]));
+ const imported = AliasVaultCsvImportService.importItemsFromCsv(csv);
+
+ expect(imported).toHaveLength(1);
+ const credential = imported[0];
+ expect(credential.ServiceName).toBe(item.Name);
+ expect(credential.ServiceUrls?.[0]).toBe('https://testservice.com');
+ expect(credential.Username).toBe('testuser');
+ expect(credential.Notes).toBe('Test notes');
+ expect(credential.CreatedAt?.toISOString().substring(0, 10)).toBe(item.CreatedAt.substring(0, 10));
+ expect(credential.UpdatedAt?.toISOString().substring(0, 10)).toBe(item.UpdatedAt.substring(0, 10));
+ expect(credential.Alias!.Gender).toBe('Male');
+ expect(credential.Alias!.FirstName).toBe('John');
+ expect(credential.Alias!.LastName).toBe('Doe');
+ expect(credential.Alias!.BirthDate?.getTime()).toBe(utc(1990, 1, 1).getTime());
+ expect(credential.Password).toBe('password123');
+ });
+
+ it('re-imports an exported credit card item from CSV unchanged', () => {
+ const loginItem = createAppItem('Login service', ItemTypes.Login, { [FieldKey.LoginUsername]: 'loginuser', [FieldKey.LoginPassword]: 'loginpass' });
+ const cardItem = createAppItem('My Visa', ItemTypes.CreditCard, {
+ [FieldKey.CardCardholderName]: 'John Doe',
+ [FieldKey.CardNumber]: '4111111111111111',
+ [FieldKey.CardExpiryMonth]: '12',
+ [FieldKey.CardExpiryYear]: '2030',
+ [FieldKey.CardCvv]: '123',
+ [FieldKey.CardPin]: '9876',
+ [FieldKey.NotesContent]: 'Card notes',
+ });
+
+ const csv = csvText(AliasVaultCsvExportService.exportItemsToCsv([loginItem, cardItem]));
+ const headerLine = csv.split('\n')[0];
+ for (const column of ['CardholderName', 'CardNumber', 'CardExpiryMonth', 'CardExpiryYear', 'CardCvv', 'CardPin']) {
+ expect(headerLine).toContain(column);
+ }
+
+ const imported = AliasVaultCsvImportService.importItemsFromCsv(csv);
+ expect(imported).toHaveLength(2);
+
+ const importedLogin = byName(imported, 'Login service');
+ expect(importedLogin.ItemType).toBeUndefined();
+ expect(importedLogin.Creditcard).toBeUndefined();
+ expect(importedLogin.Username).toBe('loginuser');
+
+ const importedCard = byName(imported, 'My Visa');
+ expect(importedCard.ItemType).toBe(ItemTypes.CreditCard);
+ expect(importedCard.Creditcard).toBeDefined();
+ expect(importedCard.Creditcard!.CardholderName).toBe('John Doe');
+ expect(importedCard.Creditcard!.Number).toBe('4111111111111111');
+ expect(importedCard.Creditcard!.ExpiryMonth).toBe('12');
+ expect(importedCard.Creditcard!.ExpiryYear).toBe('2030');
+ expect(importedCard.Creditcard!.Cvv).toBe('123');
+ expect(importedCard.Creditcard!.Pin).toBe('9876');
+ expect(importedCard.Notes).toBe('Card notes');
+ });
+
+ it('re-imports multiple service URLs', () => {
+ const item = createAppItem('Multi url service', ItemTypes.Login, {
+ [FieldKey.LoginUsername]: 'testuser',
+ [FieldKey.LoginUrl]: ['https://www.aliasvault.com', 'https://app.aliasvault.com', 'https://downloads.aliasvault.com'],
+ });
+
+ const csv = csvText(AliasVaultCsvExportService.exportItemsToCsv([item]));
+ const imported = AliasVaultCsvImportService.importItemsFromCsv(csv);
+
+ expect(csv).toContain('"https://www.aliasvault.com,https://app.aliasvault.com,https://downloads.aliasvault.com"');
+ expect(imported).toHaveLength(1);
+ expect(imported[0].ServiceUrls).toEqual(['https://www.aliasvault.com', 'https://app.aliasvault.com', 'https://downloads.aliasvault.com']);
+
+ const convertedItem = convertToItems(imported)[0];
+ const urlFieldValues = convertedItem.FieldValues.filter(fv => fv.FieldKey === FieldKey.LoginUrl).sort((a, b) => a.Weight - b.Weight);
+ expect(urlFieldValues.map(fv => fv.Value)).toEqual(['https://www.aliasvault.com', 'https://app.aliasvault.com', 'https://downloads.aliasvault.com']);
+ });
+});
diff --git a/core/client/src/transfer/export/__tests__/AvexExportService.test.ts b/core/client/src/transfer/export/__tests__/AvexExportService.test.ts
new file mode 100644
index 000000000..4ab9b629f
--- /dev/null
+++ b/core/client/src/transfer/export/__tests__/AvexExportService.test.ts
@@ -0,0 +1,25 @@
+import { FieldKey, ItemTypes } from '@aliasvault/models/vault';
+import { describe, expect, it } from 'vitest';
+
+import { AvexImportService } from '../../import/importers/aliasvault/AvexImportService';
+import { AvuxImportService } from '../../import/importers/aliasvault/AvuxImportService';
+import { AvexExportService } from '../AvexExportService';
+
+import { createTestItem, exportItems } from './testHelpers';
+
+describe('AvexExportService', () => {
+ it('decrypts what it encrypted', async () => {
+ const avuxBytes = exportItems([createTestItem('Encrypted item', ItemTypes.Login, { [FieldKey.LoginUsername]: 'user' })]);
+
+ const avexBytes = await AvexExportService.encryptToAvex(avuxBytes, 'export-password', 'tester');
+ const { header } = AvexImportService.parseAvexHeader(avexBytes);
+ expect(header.format).toBe('avex');
+ expect(header.version).toBe('1.0.0');
+ expect(header.kdf.type.toLowerCase()).toBe('argon2id');
+ expect(header.metadata.exportedBy).toBe('tester');
+
+ const decrypted = await AvexImportService.decryptAvex(avexBytes, 'export-password');
+ expect(Array.from(decrypted)).toEqual(Array.from(avuxBytes));
+ expect(AvuxImportService.importFromAvux(decrypted)[0].ServiceName).toBe('Encrypted item');
+ });
+});
diff --git a/core/client/src/transfer/export/__tests__/AvuxExportService.test.ts b/core/client/src/transfer/export/__tests__/AvuxExportService.test.ts
new file mode 100644
index 000000000..54cc0b823
--- /dev/null
+++ b/core/client/src/transfer/export/__tests__/AvuxExportService.test.ts
@@ -0,0 +1,168 @@
+import { FieldKey, FieldTypes, ItemTypes } from '@aliasvault/models/vault';
+import { describe, expect, it } from 'vitest';
+
+import { byName } from '../../import/__tests__/testHelpers';
+import { AvuxImportService } from '../../import/importers/aliasvault/AvuxImportService';
+import { convertToItems } from '../../import/writers/ItemConverter';
+import { ZipArchive } from '../../shared/ZipArchive';
+import { AvuxExportService } from '../AvuxExportService';
+
+import { createTestItem, addCustomFieldValue, addTotpCode, addAttachment, exportItems } from './testHelpers';
+
+import type { FieldDefinitionEntity, FolderEntity, ItemTagEntity, LogoEntity, TagEntity } from '../../shared/VaultEntities';
+
+describe('AvuxExportService', () => {
+ it('writes the manifest and attachments', () => {
+ const login = createTestItem('Basic Login', ItemTypes.Login, { [FieldKey.LoginUsername]: 'testuser', [FieldKey.LoginPassword]: 'testpass', [FieldKey.LoginUrl]: 'https://example.com', [FieldKey.NotesContent]: 'Test notes' });
+ const loginWithTotp = createTestItem('Login with 2FA', ItemTypes.Login, { [FieldKey.LoginUsername]: 'user2fa', [FieldKey.LoginPassword]: 'pass2fa' });
+ addTotpCode(loginWithTotp, 'JBSWY3DPEHPK3PXP');
+ const card = createTestItem('Test Card', ItemTypes.CreditCard, { [FieldKey.CardNumber]: '4111111111111111', [FieldKey.CardCardholderName]: 'Test Holder' });
+ const note = createTestItem('Test Note', ItemTypes.Note, { [FieldKey.NotesContent]: 'This is a test secure note.' });
+ const withAttachment = createTestItem('Item with Attachment', ItemTypes.Login, { [FieldKey.LoginUsername]: 'attachuser' });
+ addAttachment(withAttachment, 'test-file.txt', 'Test attachment content');
+ const items = [login, loginWithTotp, card, note, withAttachment];
+ const folders: FolderEntity[] = [{ Id: crypto.randomUUID(), Name: 'Test Folder', ParentFolderId: null, Weight: 0, CreatedAt: new Date(), UpdatedAt: new Date(), IsDeleted: false }];
+ const tags: TagEntity[] = [{ Id: crypto.randomUUID(), Name: 'Test Tag', Color: '#FF0000', DisplayOrder: 0, CreatedAt: new Date(), UpdatedAt: new Date(), IsDeleted: false }];
+ const itemTags: ItemTagEntity[] = [{ ItemId: items[0].Id, TagId: tags[0].Id, IsDeleted: false }];
+
+ const avuxBytes = AvuxExportService.exportToAvux(items, folders, tags, itemTags, [], [], '[email protected]');
+
+ expect(avuxBytes.length).toBeGreaterThan(0);
+
+ const archive = ZipArchive.open(avuxBytes);
+ const manifestJson = archive.readText('manifest.json');
+ expect(manifestJson).not.toBeNull();
+ expect(manifestJson).toContain('"version"');
+ expect(manifestJson).toContain('"items"');
+ expect(manifestJson).toContain('"folders"');
+ expect(manifestJson).toContain('Basic Login');
+ expect(manifestJson).toContain('Test Folder');
+ expect(archive.has(`attachments/${withAttachment.Id}_${withAttachment.Attachments[0].Id}_test-file.txt`)).toBe(true);
+ });
+
+ it('re-imports exported logins, TOTP codes and credit cards', () => {
+ const loginWithTotp = createTestItem('Import 2FA', ItemTypes.Login, { [FieldKey.LoginUsername]: 'user2fa', [FieldKey.LoginPassword]: 'pass2fa' });
+ addTotpCode(loginWithTotp, 'JBSWY3DPEHPK3PXP');
+ const items = [
+ createTestItem('Import Test Item', ItemTypes.Login, { [FieldKey.LoginUsername]: 'importuser', [FieldKey.LoginPassword]: 'importpass', [FieldKey.LoginUrl]: 'https://import.example.com' }),
+ loginWithTotp,
+ createTestItem('Test Card', ItemTypes.CreditCard, { [FieldKey.CardNumber]: '4111111111111111', [FieldKey.CardCardholderName]: 'Test Holder' }),
+ ];
+
+ const imported = AvuxImportService.importFromAvux(exportItems(items));
+
+ expect(imported).toHaveLength(3);
+
+ const basicLogin = byName(imported, 'Import Test Item');
+ expect(basicLogin.Username).toBe('importuser');
+ expect(basicLogin.Password).toBe('importpass');
+ expect(basicLogin.ServiceUrls?.[0]).toBe('https://import.example.com');
+
+ const twoFa = byName(imported, 'Import 2FA');
+ expect(twoFa.Username).toBe('user2fa');
+ expect(twoFa.Password).toBe('pass2fa');
+ expect(twoFa.TwoFactorSecret).toBe('JBSWY3DPEHPK3PXP');
+
+ const creditCard = imported.find(c => c.ItemType === ItemTypes.CreditCard)!;
+ expect(creditCard.Creditcard).toBeDefined();
+ expect(creditCard.Creditcard!.Number).toBe('4111111111111111');
+ expect(creditCard.Creditcard!.CardholderName).toBe('Test Holder');
+ });
+
+ it('preserves all data when re-importing an .avux export', () => {
+ const original = createTestItem('Reimport Test', ItemTypes.Login, {
+ [FieldKey.LoginUsername]: 'reimportuser',
+ [FieldKey.LoginPassword]: 'reimportpass',
+ [FieldKey.LoginUrl]: 'https://reimport.example.com',
+ [FieldKey.NotesContent]: 'Reimport notes',
+ [FieldKey.AliasFirstName]: 'John',
+ [FieldKey.AliasLastName]: 'Doe',
+ });
+ addTotpCode(original, 'JBSWY3DPEHPK3PXP');
+
+ const imported = AvuxImportService.importFromAvux(exportItems([original]));
+
+ expect(imported).toHaveLength(1);
+ const credential = imported[0];
+ expect(credential.ServiceName).toBe('Reimport Test');
+ expect(credential.Username).toBe('reimportuser');
+ expect(credential.Password).toBe('reimportpass');
+ expect(credential.ServiceUrls?.[0]).toBe('https://reimport.example.com');
+ expect(credential.Notes).toBe('Reimport notes');
+ expect(credential.Alias?.FirstName).toBe('John');
+ expect(credential.Alias?.LastName).toBe('Doe');
+ expect(credential.TwoFactorSecret).toBe('JBSWY3DPEHPK3PXP');
+ expect(credential.CreatedAt?.getTime()).toBe(original.CreatedAt.getTime());
+ });
+
+ it('preserves custom fields when re-importing an .avux export', () => {
+ const item = createTestItem('Custom Field Item', ItemTypes.Login, { [FieldKey.LoginUsername]: 'customuser' });
+ const textFieldDef: FieldDefinitionEntity = { Id: crypto.randomUUID(), Label: 'Security Question', FieldType: 'Text', IsMultiValue: false, IsHidden: false, EnableHistory: false, Weight: 3, ApplicableToTypes: null, CreatedAt: new Date(), UpdatedAt: new Date(), IsDeleted: false };
+ const hiddenFieldDef: FieldDefinitionEntity = { Id: crypto.randomUUID(), Label: 'Recovery Code', FieldType: 'Password', IsMultiValue: false, IsHidden: true, EnableHistory: false, Weight: 5, ApplicableToTypes: null, CreatedAt: new Date(), UpdatedAt: new Date(), IsDeleted: false };
+ addCustomFieldValue(item, textFieldDef, 'My first pet');
+ addCustomFieldValue(item, hiddenFieldDef, 'super-secret-recovery');
+
+ const imported = AvuxImportService.importFromAvux(exportItems([item], [], [textFieldDef, hiddenFieldDef]));
+
+ expect(imported).toHaveLength(1);
+ const credential = imported[0];
+ expect(credential.CustomFieldValues).toHaveLength(2);
+
+ const textField = credential.CustomFieldValues!.find(f => f.Label === 'Security Question')!;
+ expect(textField.Value).toBe('My first pet');
+ expect(textField.FieldType).toBe(FieldTypes.Text);
+ expect(textField.IsHidden).toBe(false);
+ expect(textField.Weight).toBe(3);
+
+ const hiddenField = credential.CustomFieldValues!.find(f => f.Label === 'Recovery Code')!;
+ expect(hiddenField.Value).toBe('super-secret-recovery');
+ expect(hiddenField.FieldType).toBe(FieldTypes.Password);
+ expect(hiddenField.IsHidden).toBe(true);
+ expect(hiddenField.Weight).toBe(5);
+
+ // Converting to items recreates the custom definitions and their values.
+ const convertedItem = convertToItems(imported)[0];
+ const customFieldValues = convertedItem.FieldValues.filter(fv => fv.FieldKey === null && fv.FieldDefinition);
+ expect(customFieldValues).toHaveLength(2);
+
+ const recoveryValue = customFieldValues.find(fv => fv.FieldDefinition!.Label === 'Recovery Code')!;
+ expect(recoveryValue.Value).toBe('super-secret-recovery');
+ expect(recoveryValue.FieldDefinition!.FieldType).toBe('Password');
+ expect(recoveryValue.FieldDefinition!.IsHidden).toBe(true);
+ expect(recoveryValue.FieldDefinition!.Weight).toBe(5);
+ });
+
+ it('re-imports exported logos', () => {
+ const logoId1 = crypto.randomUUID();
+ const logoId2 = crypto.randomUUID();
+
+ const item1 = createTestItem('GitHub', ItemTypes.Login, { [FieldKey.LoginUsername]: 'testuser', [FieldKey.LoginPassword]: 'password123', [FieldKey.LoginUrl]: 'https://github.com' });
+ item1.LogoId = logoId1;
+ const item2 = createTestItem('Google', ItemTypes.Login, { [FieldKey.LoginUsername]: '[email protected]', [FieldKey.LoginPassword]: 'pass456', [FieldKey.LoginUrl]: 'https://google.com' });
+ item2.LogoId = logoId2;
+ // Shares the logo of item1 (deduplication).
+ const item3 = createTestItem('GitHub Issue Tracker', ItemTypes.Login, { [FieldKey.LoginUsername]: 'issueuser', [FieldKey.LoginPassword]: 'issuepass' });
+ item3.LogoId = logoId1;
+
+ const logos: LogoEntity[] = [
+ { Id: logoId1, Source: 'github.com', FileData: new Uint8Array([1, 2, 3, 4, 5]), MimeType: 'image/png', FetchedAt: new Date(), IsDeleted: false },
+ { Id: logoId2, Source: 'google.com', FileData: new Uint8Array([6, 7, 8, 9, 10]), MimeType: 'image/png', FetchedAt: new Date(), IsDeleted: false },
+ ];
+
+ const imported = AvuxImportService.importFromAvux(exportItems([item1, item2, item3], logos));
+
+ expect(imported).toHaveLength(3);
+
+ const github = byName(imported, 'GitHub');
+ expect(github.Username).toBe('testuser');
+ expect(github.Password).toBe('password123');
+ expect(Array.from(github.FaviconBytes!)).toEqual([1, 2, 3, 4, 5]);
+
+ const google = byName(imported, 'Google');
+ expect(google.Username).toBe('[email protected]');
+ expect(google.Password).toBe('pass456');
+ expect(Array.from(google.FaviconBytes!)).toEqual([6, 7, 8, 9, 10]);
+
+ expect(Array.from(byName(imported, 'GitHub Issue Tracker').FaviconBytes!)).toEqual([1, 2, 3, 4, 5]);
+ });
+});
diff --git a/core/client/src/transfer/export/__tests__/testHelpers.ts b/core/client/src/transfer/export/__tests__/testHelpers.ts
new file mode 100644
index 000000000..513db827b
--- /dev/null
+++ b/core/client/src/transfer/export/__tests__/testHelpers.ts
@@ -0,0 +1,151 @@
+import { FieldTypes } from '@aliasvault/models/vault';
+
+import { toStandardFormat } from '../../../utilities/DateFormatter';
+import { AvuxExportService } from '../AvuxExportService';
+
+import type { FieldDefinitionEntity, FieldValueEntity, ItemEntity, LogoEntity } from '../../shared/VaultEntities';
+import type { Item, ItemType } from '@aliasvault/models/vault';
+
+/*
+ * Item builders for the export tests.
+ */
+
+/**
+ * Decode CSV bytes as text.
+ * @param bytes - The bytes
+ * @returns The text
+ */
+export function csvText(bytes: Uint8Array): string {
+ return new TextDecoder().decode(bytes);
+}
+
+/**
+ * Build a test item as the app reads it from the vault.
+ * @param name - The item name
+ * @param itemType - The item type
+ * @param fields - System field values by key; an array for a multi-value field, in display order
+ * @returns The item
+ */
+export function createAppItem(name: string, itemType: ItemType, fields: Record<string, string | string[]>): Item {
+ const now = toStandardFormat(new Date());
+ return {
+ Id: crypto.randomUUID(),
+ ManifestId: crypto.randomUUID(),
+ Name: name,
+ ItemType: itemType,
+ CreatedAt: now,
+ UpdatedAt: now,
+ Fields: Object.entries(fields).map(([fieldKey, value], index) => ({
+ FieldKey: fieldKey,
+ Label: fieldKey,
+ FieldType: FieldTypes.Text,
+ Value: value,
+ IsHidden: false,
+ DisplayOrder: index,
+ IsCustomField: false,
+ EnableHistory: false,
+ })),
+ };
+}
+
+/**
+ * Build a test item.
+ * @param name - The item name
+ * @param itemType - The item type
+ * @param fields - System field values by key
+ * @returns The item
+ */
+export function createTestItem(name: string, itemType: ItemType, fields: Record<string, string>): ItemEntity {
+ const now = new Date();
+ const item: ItemEntity = {
+ Id: crypto.randomUUID(),
+ Name: name,
+ ItemType: itemType,
+ FolderId: null,
+ LogoId: null,
+ CreatedAt: now,
+ UpdatedAt: now,
+ IsDeleted: false,
+ FieldValues: [],
+ Attachments: [],
+ TotpCodes: [],
+ Passkeys: [],
+ };
+ for (const [key, value] of Object.entries(fields)) {
+ addFieldValue(item, key, value);
+ }
+ return item;
+}
+
+/**
+ * Add a system field value to an item.
+ * @param item - The item
+ * @param fieldKey - The field key
+ * @param value - The value
+ * @param weight - The weight, for multi-value fields
+ */
+export function addFieldValue(item: ItemEntity, fieldKey: string, value: string, weight: number = 0): void {
+ const fieldValue: FieldValueEntity = {
+ Id: crypto.randomUUID(),
+ ItemId: item.Id,
+ FieldKey: fieldKey,
+ FieldDefinitionId: null,
+ Value: value,
+ Weight: weight,
+ CreatedAt: item.CreatedAt,
+ UpdatedAt: item.UpdatedAt,
+ IsDeleted: false,
+ };
+ item.FieldValues.push(fieldValue);
+}
+
+/**
+ * Add a custom field value to an item.
+ * @param item - The item
+ * @param definition - The custom field definition
+ * @param value - The value
+ */
+export function addCustomFieldValue(item: ItemEntity, definition: FieldDefinitionEntity, value: string): void {
+ item.FieldValues.push({
+ Id: crypto.randomUUID(),
+ ItemId: item.Id,
+ FieldDefinition: definition,
+ FieldDefinitionId: definition.Id,
+ FieldKey: null,
+ Value: value,
+ Weight: 0,
+ CreatedAt: item.CreatedAt,
+ UpdatedAt: item.UpdatedAt,
+ IsDeleted: false,
+ });
+}
+
+/**
+ * Add a TOTP code to an item.
+ * @param item - The item
+ * @param secretKey - The Base32 secret
+ */
+export function addTotpCode(item: ItemEntity, secretKey: string): void {
+ item.TotpCodes.push({ Id: crypto.randomUUID(), ItemId: item.Id, Name: 'Test TOTP', SecretKey: secretKey, Algorithm: 'SHA1', Digits: 6, Period: 30, CreatedAt: item.CreatedAt, UpdatedAt: item.UpdatedAt, IsDeleted: false });
+}
+
+/**
+ * Add an attachment to an item.
+ * @param item - The item
+ * @param filename - The file name
+ * @param content - The file content as text
+ */
+export function addAttachment(item: ItemEntity, filename: string, content: string): void {
+ item.Attachments.push({ Id: crypto.randomUUID(), ItemId: item.Id, Filename: filename, Blob: new TextEncoder().encode(content), CreatedAt: item.CreatedAt, UpdatedAt: item.UpdatedAt, IsDeleted: false });
+}
+
+/**
+ * Export with no folders, tags or definitions.
+ * @param items - The items
+ * @param logos - The logos
+ * @param fieldDefinitions - The custom field definitions
+ * @returns The .avux bytes
+ */
+export function exportItems(items: ItemEntity[], logos: LogoEntity[] = [], fieldDefinitions: FieldDefinitionEntity[] = []): Uint8Array {
+ return AvuxExportService.exportToAvux(items, [], [], [], fieldDefinitions, logos, '[email protected]');
+}
diff --git a/core/client/src/transfer/import/__tests__/testHelpers.ts b/core/client/src/transfer/import/__tests__/testHelpers.ts
new file mode 100644
index 000000000..dae88864a
--- /dev/null
+++ b/core/client/src/transfer/import/__tests__/testHelpers.ts
@@ -0,0 +1,68 @@
+import { readFileSync } from 'node:fs';
+import path from 'node:path';
+
+import type { ItemEntity } from '../../shared/VaultEntities';
+import type { ImportedCredential } from '../models/ImportedCredential';
+
+/*
+ * Fixture readers and lookups for the import tests; fixtures live next to the test that reads them.
+ */
+
+/**
+ * Read a fixture as text.
+ * @param dir - The directory holding the fixture, usually the test's own `import.meta.dirname`
+ * @param name - The file name
+ * @returns The file content
+ */
+export function readFixtureText(dir: string, name: string): string {
+ return readFileSync(path.join(dir, name), 'utf8');
+}
+
+/**
+ * Read a fixture as bytes.
+ * @param dir - The directory holding the fixture, usually the test's own `import.meta.dirname`
+ * @param name - The file name
+ * @returns The file bytes
+ */
+export function readFixtureBytes(dir: string, name: string): Uint8Array {
+ return new Uint8Array(readFileSync(path.join(dir, name)));
+}
+
+/**
+ * The first credential with a given service name.
+ * @param credentials - The credentials
+ * @param serviceName - The service name
+ * @returns The credential
+ */
+export function byName(credentials: ImportedCredential[], serviceName: string): ImportedCredential {
+ const credential = credentials.find(c => c.ServiceName === serviceName);
+ if (!credential) {
+ throw new Error(`No credential named '${serviceName}'`);
+ }
+ return credential;
+}
+
+/**
+ * The first item with a given name.
+ * @param items - The items
+ * @param name - The item name
+ * @returns The item
+ */
+export function itemByName(items: ItemEntity[], name: string): ItemEntity {
+ const item = items.find(i => i.Name === name);
+ if (!item) {
+ throw new Error(`No item named '${name}'`);
+ }
+ return item;
+}
+
+/**
+ * A UTC date.
+ * @param year - Year
+ * @param month - 1-based month
+ * @param day - Day
+ * @returns The date
+ */
+export function utc(year: number, month: number, day: number): Date {
+ return new Date(Date.UTC(year, month - 1, day));
+}
diff --git a/core/client/src/transfer/import/importers/aliasvault/AliasVaultCsvImportService.ts b/core/client/src/transfer/import/importers/aliasvault/AliasVaultCsvImportService.ts
index 6c5cba0a3..3e1be7438 100644
--- a/core/client/src/transfer/import/importers/aliasvault/AliasVaultCsvImportService.ts
+++ b/core/client/src/transfer/import/importers/aliasvault/AliasVaultCsvImportService.ts
@@ -2,7 +2,7 @@ import { ItemTypes } from '@aliasvault/models/vault';
import { nullIfBlank } from '../../../shared/StringUtils';
import { dateTime, readCsvRecords, text, type CsvColumn, type CsvRecord } from '../../readers/CsvRecordMapper';
-import { parseUrls } from '../shared/CredentialHelpers';
+import { parseUrls } from '../../readers/FieldParsers';
import type { AliasVaultCsvColumn } from '../../../export/AliasVaultCsvExportService';
import type { ImportedCredential } from '../../models/ImportedCredential';
diff --git a/core/client/src/transfer/import/importers/aliasvault/__tests__/AliasVaultCsv.test.ts b/core/client/src/transfer/import/importers/aliasvault/__tests__/AliasVaultCsv.test.ts
new file mode 100644
index 000000000..096030441
--- /dev/null
+++ b/core/client/src/transfer/import/importers/aliasvault/__tests__/AliasVaultCsv.test.ts
@@ -0,0 +1,75 @@
+import { describe, expect, it } from 'vitest';
+
+import { readFixtureText, byName, utc } from '../../../__tests__/testHelpers';
+import { AliasVaultCsvImportService } from '../AliasVaultCsvImportService';
+
+describe('AliasVaultCsvImportService', () => {
+ it('imports a legacy CSV without credit card columns', () => {
+ const legacyCsv =
+ 'ServiceName,FolderPath,ServiceUrl,Username,CurrentPassword,AliasEmail,TwoFactorSecret,AliasGender,AliasFirstName,AliasLastName,AliasNickName,AliasBirthDate,Notes,CreatedAt,UpdatedAt\n'
+ + 'Old Service,,https://old.example,olduser,oldpass,,,,,,,,,2024-01-01 00:00:00,2024-01-01 00:00:00\n';
+
+ const imported = AliasVaultCsvImportService.importItemsFromCsv(legacyCsv);
+
+ expect(imported).toHaveLength(1);
+ expect(imported[0].ServiceName).toBe('Old Service');
+ expect(imported[0].Username).toBe('olduser');
+ expect(imported[0].ItemType).toBeUndefined();
+ expect(imported[0].Creditcard).toBeUndefined();
+ });
+
+ it('imports the mobile app CSV export', () => {
+ const imported = AliasVaultCsvImportService.importItemsFromCsv(readFixtureText(import.meta.dirname, 'aliasvault_mobile_app_export.csv'));
+
+ expect(imported).toHaveLength(3);
+
+ const credential3 = byName(imported, 'credential3');
+ expect(credential3.ServiceUrls?.[0]).toBeUndefined();
+ expect(credential3.Username).toBe('username3');
+ expect(credential3.Password).toBe('');
+ expect(credential3.Notes).toBe('without password');
+ expect(credential3.TwoFactorSecret).toBe('test');
+ expect(credential3.CreatedAt?.toISOString().substring(0, 10)).toBe('2025-09-12');
+ expect(credential3.UpdatedAt?.toISOString().substring(0, 10)).toBe('2025-09-12');
+ expect(credential3.Alias?.Gender).toBe('');
+ expect(credential3.Alias?.FirstName).toBe('');
+ expect(credential3.Alias?.LastName).toBe('');
+ expect(credential3.Email).toBe('');
+
+ const service2 = byName(imported, 'service2');
+ expect(service2.ServiceUrls?.[0]).toBe('https://service2.com');
+ expect(service2.Username).toBe('username2');
+ expect(service2.Password).toBe('password2');
+ expect(service2.Notes).toBe('');
+ expect(service2.TwoFactorSecret).toBe('');
+ expect(service2.Email).toBe('[email protected]');
+ expect(service2.Alias?.Gender).toBe('gender2');
+ expect(service2.Alias?.FirstName).toBe('firstname2');
+ expect(service2.Alias?.LastName).toBe('lastname2');
+
+ const service1 = byName(imported, 'service1');
+ expect(service1.ServiceUrls?.[0]).toBeUndefined();
+ expect(service1.Username).toBe('username1');
+ expect(service1.Password).toBe('password1');
+ expect(service1.Notes).toBe('notes1');
+ expect(service1.TwoFactorSecret).toBe('');
+ expect(service1.Email).toBe('[email protected]');
+ expect(service1.Alias?.Gender).toBe('gender1');
+ expect(service1.Alias?.FirstName).toBe('firstname1');
+ expect(service1.Alias?.LastName).toBe('lastname1');
+ expect(service1.Alias?.BirthDate?.getTime()).toBe(utc(1970, 1, 1).getTime());
+ });
+
+ it('imports a CSV whose ServiceUrl column holds several URLs with spaces', () => {
+ const csv =
+ 'ServiceName,FolderPath,ServiceUrl,Username,CurrentPassword,AliasEmail,TwoFactorSecret,AliasGender,AliasFirstName,AliasLastName,AliasNickName,AliasBirthDate,Notes,CreatedAt,UpdatedAt\n'
+ + 'Multi url service,,"https://example.com, https://www.example.com",user,pass,,,,,,,,,2024-01-01 00:00:00,2024-01-01 00:00:00\n'
+ + 'Single url service,,https://single.example,user,pass,,,,,,,,,2024-01-01 00:00:00,2024-01-01 00:00:00\n';
+
+ const imported = AliasVaultCsvImportService.importItemsFromCsv(csv);
+
+ expect(imported).toHaveLength(2);
+ expect(byName(imported, 'Multi url service').ServiceUrls).toEqual(['https://example.com', 'https://www.example.com']);
+ expect(byName(imported, 'Single url service').ServiceUrls).toEqual(['https://single.example']);
+ });
+});
diff --git a/core/client/src/transfer/import/importers/aliasvault/__tests__/Avex.test.ts b/core/client/src/transfer/import/importers/aliasvault/__tests__/Avex.test.ts
new file mode 100644
index 000000000..d7ee91e14
--- /dev/null
+++ b/core/client/src/transfer/import/importers/aliasvault/__tests__/Avex.test.ts
@@ -0,0 +1,20 @@
+import { describe, expect, it } from 'vitest';
+
+import { readFixtureBytes } from '../../../__tests__/testHelpers';
+import { AvexDecryptionError, AvexImportService } from '../AvexImportService';
+import { AvuxImportService } from '../AvuxImportService';
+
+describe('AvexImportService', () => {
+ const TEST_AVEX_PASSWORD = 'testexportpass123';
+
+ it('decrypts the reference .avex fixture', async () => {
+ const avuxBytes = await AvexImportService.decryptAvex(readFixtureBytes(import.meta.dirname, 'aliasvault.avex'), TEST_AVEX_PASSWORD);
+ const imported = AvuxImportService.importFromAvux(avuxBytes);
+ const reference = AvuxImportService.importFromAvux(readFixtureBytes(import.meta.dirname, 'aliasvault.avux'));
+ expect(imported.map(c => c.ServiceName).sort()).toEqual(reference.map(c => c.ServiceName).sort());
+ });
+
+ it('rejects a wrong password', async () => {
+ await expect(AvexImportService.decryptAvex(readFixtureBytes(import.meta.dirname, 'aliasvault.avex'), 'wrong-password')).rejects.toBeInstanceOf(AvexDecryptionError);
+ });
+});
diff --git a/core/client/src/transfer/import/importers/aliasvault/__tests__/Avux.test.ts b/core/client/src/transfer/import/importers/aliasvault/__tests__/Avux.test.ts
new file mode 100644
index 000000000..fbcac1a1e
--- /dev/null
+++ b/core/client/src/transfer/import/importers/aliasvault/__tests__/Avux.test.ts
@@ -0,0 +1,12 @@
+import { describe, expect, it } from 'vitest';
+
+import { readFixtureBytes } from '../../../__tests__/testHelpers';
+import { AvuxImportService } from '../AvuxImportService';
+
+describe('AvuxImportService', () => {
+ it('imports the reference .avux fixture', () => {
+ const imported = AvuxImportService.importFromAvux(readFixtureBytes(import.meta.dirname, 'aliasvault.avux'));
+ expect(imported.length).toBeGreaterThan(0);
+ expect(imported.every(c => c.CreatedAt instanceof Date && !isNaN(c.CreatedAt.getTime()))).toBe(true);
+ });
+});
diff --git a/core/client/src/transfer/__tests__/fixtures/aliasvault.avex b/core/client/src/transfer/import/importers/aliasvault/__tests__/aliasvault.avex
similarity index 100%
rename from core/client/src/transfer/__tests__/fixtures/aliasvault.avex
rename to core/client/src/transfer/import/importers/aliasvault/__tests__/aliasvault.avex
diff --git a/core/client/src/transfer/__tests__/fixtures/aliasvault.avux b/core/client/src/transfer/import/importers/aliasvault/__tests__/aliasvault.avux
similarity index 100%
rename from core/client/src/transfer/__tests__/fixtures/aliasvault.avux
rename to core/client/src/transfer/import/importers/aliasvault/__tests__/aliasvault.avux
diff --git a/core/client/src/transfer/__tests__/fixtures/aliasvault_mobile_app_export.csv b/core/client/src/transfer/import/importers/aliasvault/__tests__/aliasvault_mobile_app_export.csv
similarity index 100%
rename from core/client/src/transfer/__tests__/fixtures/aliasvault_mobile_app_export.csv
rename to core/client/src/transfer/import/importers/aliasvault/__tests__/aliasvault_mobile_app_export.csv
diff --git a/core/client/src/transfer/import/importers/bitwarden/BitwardenCsvImporter.ts b/core/client/src/transfer/import/importers/bitwarden/BitwardenCsvImporter.ts
index 63e83d7ac..65b2efb30 100644
--- a/core/client/src/transfer/import/importers/bitwarden/BitwardenCsvImporter.ts
+++ b/core/client/src/transfer/import/importers/bitwarden/BitwardenCsvImporter.ts
@@ -3,7 +3,7 @@ import { ItemTypes } from '@aliasvault/models/vault';
import { nullIfBlank } from '../../../shared/StringUtils';
import { readImportCsv } from '../../readers/CsvImport';
import { optionalText, text } from '../../readers/CsvRecordMapper';
-import { mapItemType, parseUrls } from '../shared/CredentialHelpers';
+import { mapItemType, parseUrls } from '../../readers/FieldParsers';
import type { ImportedCredential } from '../../models/ImportedCredential';
diff --git a/core/client/src/transfer/import/importers/bitwarden/BitwardenZipImporter.ts b/core/client/src/transfer/import/importers/bitwarden/BitwardenZipImporter.ts
index 3676b39e5..2c759c81a 100644
--- a/core/client/src/transfer/import/importers/bitwarden/BitwardenZipImporter.ts
+++ b/core/client/src/transfer/import/importers/bitwarden/BitwardenZipImporter.ts
@@ -2,9 +2,8 @@ import { FieldTypes, ItemTypes, type ItemType } from '@aliasvault/models/vault';
import { isBlank, nonBlank } from '../../../shared/StringUtils';
import { ImportException, ImportStage } from '../../models/ImportException';
+import { addCustomField, convertArchiveItems, openArchive, readArchiveJson } from '../../readers/ArchiveImport';
import { readStringAtPath } from '../../readers/JsonReader';
-import { convertArchiveItems, openArchive, readArchiveJson } from '../shared/ArchiveImport';
-import { addCustomField, appendNotes } from '../shared/CredentialHelpers';
import { BitwardenFieldTypes, BitwardenItemTypes, parseBitwardenItem, parseBitwardenJsonExport, type BitwardenIdentity, type BitwardenItem } from './BitwardenJson';
@@ -101,3 +100,16 @@ function applyIdentity(credential: ImportedCredential, identity: BitwardenIdenti
const details: [string, string | null][] = [['Title', identity.Title], ['Company', identity.Company], ['Phone', identity.Phone], ['Address', address]];
appendNotes(credential, details.filter(([, value]) => !isBlank(value)).map(([label, value]) => `${label}: ${value}`));
}
+
+/**
+ * Append a block of text to a credential's notes, separated by an empty line.
+ * @param credential - The credential
+ * @param lines - The lines to append.
+ */
+function appendNotes(credential: ImportedCredential, lines: string[]): void {
+ if (lines.length === 0) {
+ return;
+ }
+ const block = lines.join('\n');
+ credential.Notes = isBlank(credential.Notes) ? block : `${credential.Notes}\n\n${block}`;
+}
diff --git a/core/client/src/transfer/import/importers/bitwarden/__tests__/BitwardenCsvImporter.test.ts b/core/client/src/transfer/import/importers/bitwarden/__tests__/BitwardenCsvImporter.test.ts
new file mode 100644
index 000000000..f1ec638a0
--- /dev/null
+++ b/core/client/src/transfer/import/importers/bitwarden/__tests__/BitwardenCsvImporter.test.ts
@@ -0,0 +1,83 @@
+import { FieldKey, ItemTypes } from '@aliasvault/models/vault';
+import { describe, expect, it, vi } from 'vitest';
+
+import { parseFolderPath } from '../../../../shared/FolderPaths';
+import { readFixtureText, byName, itemByName } from '../../../__tests__/testHelpers';
+import { collectHierarchicalFolderPaths } from '../../../writers/ImportDuplicateDetection';
+import { convertToItems } from '../../../writers/ItemConverter';
+import { importBitwardenCsv } from '../BitwardenCsvImporter';
+
+import type { ImportedCredential } from '../../../models/ImportedCredential';
+
+/**
+ * Converts the Bitwarden fixture, which holds one invalid TOTP secret that the importer logs and skips.
+ */
+function convertBitwardenFixture(imported: ImportedCredential[]): ReturnType<typeof convertToItems> {
+ const consoleWarn = vi.spyOn(console, 'warn').mockImplementation(() => {});
+ try {
+ const items = convertToItems(imported);
+ expect(consoleWarn).toHaveBeenCalledTimes(1);
+ return items;
+ } finally {
+ consoleWarn.mockRestore();
+ }
+}
+
+describe('BitwardenCsvImporter', () => {
+ it('imports Bitwarden CSV', () => {
+ const imported = importBitwardenCsv(readFixtureText(import.meta.dirname, 'bitwarden.csv'));
+ expect(imported).toHaveLength(12);
+
+ // One entry has an invalid TOTP secret ("!" in it); conversion must not throw.
+ const convertedItems = convertBitwardenFixture(imported);
+ expect(itemByName(convertedItems, 'TutaNota4').TotpCodes).toHaveLength(0);
+ expect(itemByName(convertedItems, 'TutaNota').TotpCodes).toHaveLength(1);
+ expect(itemByName(convertedItems, 'TutaNota3').TotpCodes).toHaveLength(1);
+
+ const tutaNota = byName(imported, 'TutaNota');
+ expect(tutaNota.Username).toBe('[email protected]');
+ expect(tutaNota.Password).toBe('blabla');
+ expect(tutaNota.TwoFactorSecret).toBe('otpauth://totp/Strongbox?secret=PLW4SB3PQ7MKVXY2MXF4NEXS6Y&algorithm=SHA1&digits=6&period=30');
+
+ const aliasVault = byName(imported, 'Aliasvault.com');
+ expect(aliasVault.ServiceUrls?.[0]).toBe('https://www.aliasvault.com');
+ expect(aliasVault.Username).toBe('root');
+ expect(aliasVault.Password).toBe('toor');
+
+ const multiUrl = byName(imported, 'TutaNota3');
+ expect(multiUrl.ServiceUrls).toEqual(['https://www.aliasvault.com', 'https://app.aliasvault.com', 'https://downloads.aliasvault.com']);
+ expect(multiUrl.Username).toBe('[email protected]');
+ expect(multiUrl.TwoFactorSecret).toBe('otpauth://totp/Test%20name%3Atest%40test.org?secret=PLW4SB3PQ7MKVXY2MXF4NEXS6Y&issuer=Alias%20Vault');
+
+ const multiUrlItem = itemByName(convertedItems, 'TutaNota3');
+ const urlFieldValues = multiUrlItem.FieldValues.filter(fv => fv.FieldKey === FieldKey.LoginUrl).sort((a, b) => a.Weight - b.Weight);
+ expect(urlFieldValues.map(fv => fv.Value)).toEqual(['https://www.aliasvault.com', 'https://app.aliasvault.com', 'https://downloads.aliasvault.com']);
+ expect(urlFieldValues.map(fv => fv.Weight)).toEqual([0, 1, 2]);
+
+ // The TOTP name is URL-decoded from the otpauth URI.
+ const totp = multiUrlItem.TotpCodes[0];
+ expect(totp).toBeDefined();
+ expect(totp.SecretKey).toBe('PLW4SB3PQ7MKVXY2MXF4NEXS6Y');
+ expect(totp.Name).toBe('Alias Vault: Test name:[email protected]');
+
+ expect(byName(imported, 'ProjectItem').FolderPath).toBe('Work/Projects');
+ expect(byName(imported, 'ActiveProjectItem').FolderPath).toBe('Work/Projects/Active');
+ expect(byName(imported, 'BankAccount').FolderPath).toBe('Personal/Finance/Banking');
+ expect(byName(imported, 'SavingsAccount').FolderPath).toBe('Personal/Finance/Banking/Savings');
+
+ expect(parseFolderPath('Work/Projects/Active')).toEqual(['Work', 'Projects', 'Active']);
+ expect(parseFolderPath('Personal/Finance/Banking/Savings')).toEqual(['Personal', 'Finance', 'Banking', 'Savings']);
+ });
+
+ it('imports Bitwarden folders', () => {
+ const imported = importBitwardenCsv(readFixtureText(import.meta.dirname, 'bitwarden.csv'));
+ expect(imported.filter(c => c.FolderPath === 'Business')).toHaveLength(6);
+ expect(collectHierarchicalFolderPaths(imported)).toContain('Business');
+ });
+
+ it('detects Bitwarden item types', () => {
+ const imported = importBitwardenCsv(readFixtureText(import.meta.dirname, 'bitwarden.csv'));
+ const items = convertBitwardenFixture(imported);
+ expect(items.filter(i => i.ItemType === ItemTypes.Login).length).toBeGreaterThan(0);
+ });
+});
diff --git a/core/client/src/transfer/import/importers/bitwarden/__tests__/BitwardenZipImporter.test.ts b/core/client/src/transfer/import/importers/bitwarden/__tests__/BitwardenZipImporter.test.ts
new file mode 100644
index 000000000..74e8e235a
--- /dev/null
+++ b/core/client/src/transfer/import/importers/bitwarden/__tests__/BitwardenZipImporter.test.ts
@@ -0,0 +1,120 @@
+import { FieldTypes, ItemTypes } from '@aliasvault/models/vault';
+import { describe, expect, it } from 'vitest';
+
+import { createZipArchive, textToZipBytes } from '../../../../shared/ZipArchive';
+import { readFixtureBytes, byName, itemByName } from '../../../__tests__/testHelpers';
+import { ImportException, ImportStage } from '../../../models/ImportException';
+import { convertToItems } from '../../../writers/ItemConverter';
+import { importBitwardenZip } from '../BitwardenZipImporter';
+
+describe('BitwardenZipImporter', () => {
+ it('imports a Bitwarden ZIP with attachments', () => {
+ const result = importBitwardenZip(readFixtureBytes(import.meta.dirname, 'bitwarden.zip'));
+ const imported = result.Credentials;
+ expect(imported).toHaveLength(5);
+
+ const login = byName(imported, 'Example Login');
+ expect(login.Username).toBe('[email protected]');
+ expect(login.Password).toBe('SecurePassword123!');
+ expect(login.ServiceUrls).toEqual(['https://example.com']);
+ expect(login.TwoFactorSecret).toBe('otpauth://totp/Example:[email protected]?secret=JBSWY3DPEHPK3PXP&issuer=Example');
+ expect(login.FolderPath).toBe('Personal');
+ expect(login.ItemType).toBe(ItemTypes.Login);
+
+ // Custom fields of every type (Text=0, Hidden=1, Boolean=2); linked fields (3) are skipped.
+ expect(login.CustomFieldValues).toHaveLength(3);
+ const securityQuestion = login.CustomFieldValues!.find(f => f.Label === 'Security Question')!;
+ expect(securityQuestion.Value).toBe('My first pet');
+ expect(securityQuestion.FieldType).toBe(FieldTypes.Text);
+ const apiKey = login.CustomFieldValues!.find(f => f.Label === 'API Key')!;
+ expect(apiKey.Value).toBe('sk_test_123456789');
+ expect(apiKey.FieldType).toBe(FieldTypes.Hidden);
+ const twoFactorEnabled = login.CustomFieldValues!.find(f => f.Label === 'Two Factor Enabled')!;
+ expect(twoFactorEnabled.Value).toBe('true');
+ expect(twoFactorEnabled.FieldType).toBe(FieldTypes.Text);
+ expect(login.Notes).toBe('This is a test login item');
+
+ const note = byName(imported, 'Secure Note');
+ expect(note.Notes).toBe('This is a secure note with sensitive information');
+ expect(note.ItemType).toBe(ItemTypes.Note);
+ expect(note.FolderPath).toBeNull();
+
+ const card = byName(imported, 'My Credit Card');
+ expect(card.Notes).toBe('Primary card');
+ expect(card.FolderPath).toBe('Work');
+ expect(card.ItemType).toBe(ItemTypes.CreditCard);
+ expect(card.Creditcard!.CardholderName).toBe('John Doe');
+ expect(card.Creditcard!.Number).toBe('4111111111111111');
+ expect(card.Creditcard!.ExpiryMonth).toBe('12');
+ expect(card.Creditcard!.ExpiryYear).toBe('2025');
+ expect(card.Creditcard!.Cvv).toBe('123');
+
+ const identity = byName(imported, 'Personal Identity');
+ expect(identity.ItemType).toBe(ItemTypes.Alias);
+ expect(identity.Alias!.FirstName).toBe('John');
+ expect(identity.Alias!.LastName).toBe('Doe');
+ expect(identity.Email).toBe('[email protected]');
+ expect(identity.Notes).toContain('Company: Example Corp');
+ expect(identity.Notes).toContain('Phone: +1234567890');
+ expect(identity.Notes).toContain('Address: 123 Main St, Apt 4B, New York, NY, 10001, US');
+
+ const withAttachment = byName(imported, 'Login with Attachment');
+ expect(withAttachment.Username).toBe('admin');
+ expect(withAttachment.Password).toBe('AdminPass456!');
+
+ const convertedItems = convertToItems(imported);
+ expect(convertedItems).toHaveLength(5);
+ const convertedLogin = itemByName(convertedItems, 'Example Login');
+ expect(convertedLogin.ItemType).toBe(ItemTypes.Login);
+ expect(convertedLogin.TotpCodes).toHaveLength(1);
+ expect(convertedLogin.TotpCodes[0].SecretKey).toBe('JBSWY3DPEHPK3PXP');
+ });
+
+ it('ignores directory entries when reading Bitwarden ZIP attachments', () => {
+ const itemId = 'item-with-attachment-uuid';
+ const fileName = 'dataset_Backup_keys.json';
+ const fileBytes = new TextEncoder().encode('{"keys":"value"}');
+ const dataJson = JSON.stringify({
+ encrypted: false,
+ folders: [],
+ items: [{
+ id: itemId, organizationId: null, folderId: null, type: 1, reprompt: 0, name: 'Login with Attachment', notes: 'This item has an attachment', favorite: false,
+ revisionDate: '2023-08-15T16:30:00.000Z', fields: [], login: { uris: [{ match: null, uri: 'https://secure.example.com' }], username: 'admin', password: 'AdminPass456!', totp: null }, collectionIds: null,
+ }],
+ });
+
+ // Directory entries (zero bytes, trailing slash) as many ZIP tools emit them.
+ const zipBytes = createZipArchive({
+ 'data.json': textToZipBytes(dataJson),
+ 'attachments/': new Uint8Array(0),
+ [`attachments/${itemId}/`]: new Uint8Array(0),
+ [`attachments/${itemId}/${fileName}`]: fileBytes,
+ });
+
+ const imported = (importBitwardenZip(zipBytes)).Credentials;
+
+ expect(imported).toHaveLength(1);
+ const credential = imported[0];
+ expect(credential.Attachments).toHaveLength(1);
+ expect(credential.Attachments![0].Filename).toBe(fileName);
+ expect(Array.from(credential.Attachments![0].Blob)).toEqual(Array.from(fileBytes));
+ expect(credential.Attachments!.some(a => a.Filename.length === 0)).toBe(false);
+ expect(credential.Attachments!.some(a => a.Blob.length === 0)).toBe(false);
+ });
+
+ it('reports an encrypted Bitwarden export clearly', () => {
+ const zipBytes = createZipArchive({ 'data.json': textToZipBytes('{"encrypted":true,"folders":[],"items":[]}') });
+
+ let caught: unknown;
+ try {
+ importBitwardenZip(zipBytes);
+ } catch (error) {
+ caught = error;
+ }
+
+ expect(caught).toBeInstanceOf(ImportException);
+ expect((caught as ImportException).stage).toBe(ImportStage.Parse);
+ expect((caught as ImportException).message).toContain('Encrypted Bitwarden');
+ expect((caught as ImportException).message).toContain('unencrypted');
+ });
+});
diff --git a/core/client/src/transfer/__tests__/fixtures/bitwarden.csv b/core/client/src/transfer/import/importers/bitwarden/__tests__/bitwarden.csv
similarity index 100%
rename from core/client/src/transfer/__tests__/fixtures/bitwarden.csv
rename to core/client/src/transfer/import/importers/bitwarden/__tests__/bitwarden.csv
diff --git a/core/client/src/transfer/import/importers/ChromeCsvImporter.ts b/core/client/src/transfer/import/importers/chrome/ChromeCsvImporter.ts
similarity index 68%
rename from core/client/src/transfer/import/importers/ChromeCsvImporter.ts
rename to core/client/src/transfer/import/importers/chrome/ChromeCsvImporter.ts
index 5b0fe394a..fbca9afe7 100644
--- a/core/client/src/transfer/import/importers/ChromeCsvImporter.ts
+++ b/core/client/src/transfer/import/importers/chrome/ChromeCsvImporter.ts
@@ -1,9 +1,8 @@
-import { readImportCsv } from '../readers/CsvImport';
-import { optionalText, text } from '../readers/CsvRecordMapper';
+import { readImportCsv } from '../../readers/CsvImport';
+import { optionalText, text } from '../../readers/CsvRecordMapper';
+import { parseUrls } from '../../readers/FieldParsers';
-import { parseUrls } from './shared/CredentialHelpers';
-
-import type { ImportedCredential } from '../models/ImportedCredential';
+import type { ImportedCredential } from '../../models/ImportedCredential';
const COLUMNS = {
name: text,
diff --git a/core/client/src/transfer/import/importers/chrome/__tests__/ChromeCsvImporter.test.ts b/core/client/src/transfer/import/importers/chrome/__tests__/ChromeCsvImporter.test.ts
new file mode 100644
index 000000000..916fee850
--- /dev/null
+++ b/core/client/src/transfer/import/importers/chrome/__tests__/ChromeCsvImporter.test.ts
@@ -0,0 +1,23 @@
+import { describe, expect, it } from 'vitest';
+
+import { readFixtureText, byName } from '../../../__tests__/testHelpers';
+import { importChromeCsv } from '../ChromeCsvImporter';
+
+describe('ChromeCsvImporter', () => {
+ it('imports Chrome CSV', () => {
+ const imported = importChromeCsv(readFixtureText(import.meta.dirname, 'chrome.csv'));
+ expect(imported).toHaveLength(3);
+
+ const example = byName(imported, 'example.com');
+ expect(example.ServiceUrls?.[0]).toBe('https://example.com/');
+ expect(example.Username).toBe('usernamegoogle');
+ expect(example.Password).toBe('passwordgoogle');
+ expect(example.Notes).toBe('Note for example password from Google');
+
+ const facebook = byName(imported, 'facebook.com');
+ expect(facebook.ServiceUrls?.[0]).toBe('https://facebook.com/');
+ expect(facebook.Username).toBe('facebookuser');
+ expect(facebook.Password).toBe('facebookpass');
+ expect(facebook.Notes).toBe('Facebook comment');
+ });
+});
diff --git a/core/client/src/transfer/__tests__/fixtures/chrome.csv b/core/client/src/transfer/import/importers/chrome/__tests__/chrome.csv
similarity index 100%
rename from core/client/src/transfer/__tests__/fixtures/chrome.csv
rename to core/client/src/transfer/import/importers/chrome/__tests__/chrome.csv
diff --git a/core/client/src/transfer/import/importers/DashlaneCsvImporter.ts b/core/client/src/transfer/import/importers/dashlane/DashlaneCsvImporter.ts
similarity index 78%
rename from core/client/src/transfer/import/importers/DashlaneCsvImporter.ts
rename to core/client/src/transfer/import/importers/dashlane/DashlaneCsvImporter.ts
index fc93ba7d9..f25553b71 100644
--- a/core/client/src/transfer/import/importers/DashlaneCsvImporter.ts
+++ b/core/client/src/transfer/import/importers/dashlane/DashlaneCsvImporter.ts
@@ -1,10 +1,9 @@
-import { nullIfBlank } from '../../shared/StringUtils';
-import { readImportCsv } from '../readers/CsvImport';
-import { optionalText, text } from '../readers/CsvRecordMapper';
+import { nullIfBlank } from '../../../shared/StringUtils';
+import { readImportCsv } from '../../readers/CsvImport';
+import { optionalText, text } from '../../readers/CsvRecordMapper';
+import { parseUrls } from '../../readers/FieldParsers';
-import { parseUrls } from './shared/CredentialHelpers';
-
-import type { ImportedCredential } from '../models/ImportedCredential';
+import type { ImportedCredential } from '../../models/ImportedCredential';
const COLUMNS = {
username: text,
diff --git a/core/client/src/transfer/import/importers/dashlane/__tests__/DashlaneCsvImporter.test.ts b/core/client/src/transfer/import/importers/dashlane/__tests__/DashlaneCsvImporter.test.ts
new file mode 100644
index 000000000..9683bb1df
--- /dev/null
+++ b/core/client/src/transfer/import/importers/dashlane/__tests__/DashlaneCsvImporter.test.ts
@@ -0,0 +1,35 @@
+import { describe, expect, it } from 'vitest';
+
+import { readFixtureText, byName } from '../../../__tests__/testHelpers';
+import { collectHierarchicalFolderPaths } from '../../../writers/ImportDuplicateDetection';
+import { importDashlaneCsv } from '../DashlaneCsvImporter';
+
+describe('DashlaneCsvImporter', () => {
+ it('imports Dashlane CSV', () => {
+ const imported = importDashlaneCsv(readFixtureText(import.meta.dirname, 'dashlane.csv'));
+ expect(imported).toHaveLength(3);
+
+ const test = byName(imported, 'Test');
+ expect(test.ServiceUrls?.[0]).toBe('https://Test');
+ expect(test.Username).toBe('Test username');
+ expect(test.Password).toBe('password123');
+ expect(test.Notes).toBeNull();
+
+ const google = byName(imported, 'Google');
+ expect(google.ServiceUrls?.[0]).toBe('https://www.google.com');
+ expect(google.Username).toBe('googleuser');
+ expect(google.Password).toBe('googlepassword');
+ expect(google.Notes).toBeNull();
+
+ const local = byName(imported, 'Local');
+ expect(local.ServiceUrls?.[0]).toBe('https://www.testwebsite.local');
+ expect(local.Username).toBe('testusername');
+ expect(local.Password).toBe('testpassword');
+ expect(local.Notes).toBe('testnote\nAlternative username 1: testusernamealternative');
+ });
+
+ it('imports Dashlane categories', () => {
+ const imported = importDashlaneCsv(readFixtureText(import.meta.dirname, 'dashlane.csv'));
+ expect(Array.isArray(collectHierarchicalFolderPaths(imported))).toBe(true);
+ });
+});
diff --git a/core/client/src/transfer/__tests__/fixtures/dashlane.csv b/core/client/src/transfer/import/importers/dashlane/__tests__/dashlane.csv
similarity index 100%
rename from core/client/src/transfer/__tests__/fixtures/dashlane.csv
rename to core/client/src/transfer/import/importers/dashlane/__tests__/dashlane.csv
diff --git a/core/client/src/transfer/import/importers/DropboxCsvImporter.ts b/core/client/src/transfer/import/importers/dropbox/DropboxCsvImporter.ts
similarity index 66%
rename from core/client/src/transfer/import/importers/DropboxCsvImporter.ts
rename to core/client/src/transfer/import/importers/dropbox/DropboxCsvImporter.ts
index 98329cae6..b7d3a2ff9 100644
--- a/core/client/src/transfer/import/importers/DropboxCsvImporter.ts
+++ b/core/client/src/transfer/import/importers/dropbox/DropboxCsvImporter.ts
@@ -1,10 +1,9 @@
-import { isBlank } from '../../shared/StringUtils';
-import { readImportCsv } from '../readers/CsvImport';
-import { optionalText, text } from '../readers/CsvRecordMapper';
+import { isBlank } from '../../../shared/StringUtils';
+import { readImportCsv } from '../../readers/CsvImport';
+import { optionalText, text } from '../../readers/CsvRecordMapper';
+import { parseUrls } from '../../readers/FieldParsers';
-import { parseUrls } from './shared/CredentialHelpers';
-
-import type { ImportedCredential } from '../models/ImportedCredential';
+import type { ImportedCredential } from '../../models/ImportedCredential';
const COLUMNS = {
Name: text,
diff --git a/core/client/src/transfer/import/importers/dropbox/__tests__/DropboxCsvImporter.test.ts b/core/client/src/transfer/import/importers/dropbox/__tests__/DropboxCsvImporter.test.ts
new file mode 100644
index 000000000..7bb92d9f5
--- /dev/null
+++ b/core/client/src/transfer/import/importers/dropbox/__tests__/DropboxCsvImporter.test.ts
@@ -0,0 +1,29 @@
+import { describe, expect, it } from 'vitest';
+
+import { readFixtureText, byName } from '../../../__tests__/testHelpers';
+import { importDropboxCsv } from '../DropboxCsvImporter';
+
+describe('DropboxCsvImporter', () => {
+ it('imports Dropbox CSV', () => {
+ const imported = importDropboxCsv(readFixtureText(import.meta.dirname, 'dropbox.csv'));
+ expect(imported).toHaveLength(5);
+
+ const gmail = byName(imported, 'Gmail');
+ expect(gmail.ServiceUrls?.[0]).toBe('https://gmail.com');
+ expect(gmail.Username).toBe('[email protected]');
+ expect(gmail.Password).toBe('gmailpass123');
+ expect(gmail.Notes).toBe('Important email account');
+
+ const github = byName(imported, 'GitHub');
+ expect(github.ServiceUrls?.[0]).toBe('https://github.com');
+ expect(github.Username).toBe('devuser');
+ expect(github.Password).toBe('devpass789');
+ expect(github.Notes).toBe('Development platform');
+
+ const secureNote = byName(imported, 'Secure Note');
+ expect(secureNote.ServiceUrls?.[0]).toBeUndefined();
+ expect(secureNote.Username).toBe('');
+ expect(secureNote.Password).toBe('');
+ expect(secureNote.Notes).toBe('Important information stored securely');
+ });
+});
diff --git a/core/client/src/transfer/__tests__/fixtures/dropbox.csv b/core/client/src/transfer/import/importers/dropbox/__tests__/dropbox.csv
similarity index 100%
rename from core/client/src/transfer/__tests__/fixtures/dropbox.csv
rename to core/client/src/transfer/import/importers/dropbox/__tests__/dropbox.csv
diff --git a/core/client/src/transfer/import/importers/EdgeCsvImporter.ts b/core/client/src/transfer/import/importers/edge/EdgeCsvImporter.ts
similarity index 68%
rename from core/client/src/transfer/import/importers/EdgeCsvImporter.ts
rename to core/client/src/transfer/import/importers/edge/EdgeCsvImporter.ts
index 48fa929bd..e189cbd46 100644
--- a/core/client/src/transfer/import/importers/EdgeCsvImporter.ts
+++ b/core/client/src/transfer/import/importers/edge/EdgeCsvImporter.ts
@@ -1,9 +1,8 @@
-import { readImportCsv } from '../readers/CsvImport';
-import { optionalText, text } from '../readers/CsvRecordMapper';
+import { readImportCsv } from '../../readers/CsvImport';
+import { optionalText, text } from '../../readers/CsvRecordMapper';
+import { parseUrls } from '../../readers/FieldParsers';
-import { parseUrls } from './shared/CredentialHelpers';
-
-import type { ImportedCredential } from '../models/ImportedCredential';
+import type { ImportedCredential } from '../../models/ImportedCredential';
const COLUMNS = {
name: text,
diff --git a/core/client/src/transfer/import/importers/edge/__tests__/EdgeCsvImporter.test.ts b/core/client/src/transfer/import/importers/edge/__tests__/EdgeCsvImporter.test.ts
new file mode 100644
index 000000000..84d88f0ff
--- /dev/null
+++ b/core/client/src/transfer/import/importers/edge/__tests__/EdgeCsvImporter.test.ts
@@ -0,0 +1,29 @@
+import { describe, expect, it } from 'vitest';
+
+import { readFixtureText, byName } from '../../../__tests__/testHelpers';
+import { importEdgeCsv } from '../EdgeCsvImporter';
+
+describe('EdgeCsvImporter', () => {
+ it('imports Edge CSV', () => {
+ const imported = importEdgeCsv(readFixtureText(import.meta.dirname, 'edge.csv'));
+ expect(imported).toHaveLength(4);
+
+ const exampleApp = byName(imported, 'example.app.tld');
+ expect(exampleApp.ServiceUrls?.[0]).toBe('https://example.app.tld/');
+ expect(exampleApp.Username).toBe('exampleu');
+ expect(exampleApp.Password).toBe('examplep');
+ expect(exampleApp.Notes).toBe('');
+
+ const google = byName(imported, 'google.nl');
+ expect(google.ServiceUrls?.[0]).toBe('https://google.nl/');
+ expect(google.Username).toBe('myuser');
+ expect(google.Password).toBe('mypass');
+ expect(google.Notes).toBe('Google note here microsoft edge');
+
+ const youtube = byName(imported, 'youtube.com');
+ expect(youtube.ServiceUrls?.[0]).toBe('https://youtube.com/');
+ expect(youtube.Username).toBe('youtubeuser');
+ expect(youtube.Password).toBe('ytpassword');
+ expect(youtube.Notes).toBe('Youtubenotes');
+ });
+});
diff --git a/core/client/src/transfer/__tests__/fixtures/edge.csv b/core/client/src/transfer/import/importers/edge/__tests__/edge.csv
similarity index 100%
rename from core/client/src/transfer/__tests__/fixtures/edge.csv
rename to core/client/src/transfer/import/importers/edge/__tests__/edge.csv
diff --git a/core/client/src/transfer/import/importers/EnpassCsvImporter.ts b/core/client/src/transfer/import/importers/enpass/EnpassCsvImporter.ts
similarity index 92%
rename from core/client/src/transfer/import/importers/EnpassCsvImporter.ts
rename to core/client/src/transfer/import/importers/enpass/EnpassCsvImporter.ts
index 7df6d5191..94af0426b 100644
--- a/core/client/src/transfer/import/importers/EnpassCsvImporter.ts
+++ b/core/client/src/transfer/import/importers/enpass/EnpassCsvImporter.ts
@@ -1,14 +1,13 @@
import { ItemTypes, type ItemType } from '@aliasvault/models/vault';
-import { parseDateExact, parseDateTime } from '../../shared/DateTimeUtils';
-import { isBlank } from '../../shared/StringUtils';
-import { parseCsvRows } from '../readers/CsvParser';
-
-import { parseUrls } from './shared/CredentialHelpers';
-
-import type { ImportedAlias } from '../models/ImportedAlias';
-import type { ImportedCredential } from '../models/ImportedCredential';
-import type { ImportedCreditcard } from '../models/ImportedCreditcard';
+import { parseDateExact, parseDateTime } from '../../../shared/DateTimeUtils';
+import { isBlank } from '../../../shared/StringUtils';
+import { parseCsvRows } from '../../readers/CsvParser';
+import { parseUrls } from '../../readers/FieldParsers';
+
+import type { ImportedAlias } from '../../models/ImportedAlias';
+import type { ImportedCredential } from '../../models/ImportedCredential';
+import type { ImportedCreditcard } from '../../models/ImportedCreditcard';
/**
* The fields of one Enpass row, looked up case-insensitively.
diff --git a/core/client/src/transfer/import/importers/enpass/__tests__/EnpassCsvImporter.test.ts b/core/client/src/transfer/import/importers/enpass/__tests__/EnpassCsvImporter.test.ts
new file mode 100644
index 000000000..86d1698ef
--- /dev/null
+++ b/core/client/src/transfer/import/importers/enpass/__tests__/EnpassCsvImporter.test.ts
@@ -0,0 +1,61 @@
+import { FieldKey, ItemTypes } from '@aliasvault/models/vault';
+import { describe, expect, it } from 'vitest';
+
+import { readFixtureText, byName, utc } from '../../../__tests__/testHelpers';
+import { convertToItems } from '../../../writers/ItemConverter';
+import { importEnpassCsv } from '../EnpassCsvImporter';
+
+describe('EnpassCsvImporter', () => {
+ it('imports Enpass CSV', () => {
+ const imported = importEnpassCsv(readFixtureText(import.meta.dirname, 'enpass.csv'));
+ expect(imported).toHaveLength(5);
+
+ const creditCard = byName(imported, 'Credit Card');
+ expect(creditCard.ItemType).toBe(ItemTypes.CreditCard);
+ expect(creditCard.Creditcard).toBeDefined();
+ expect(creditCard.Creditcard!.CardholderName).toBe('ccholder');
+ expect(creditCard.Creditcard!.Number).toBe('1234123412341234');
+ expect(creditCard.Creditcard!.Cvv).toBe('1234');
+ expect(creditCard.Creditcard!.Pin).toBe('1234');
+ expect(creditCard.Creditcard!.ExpiryMonth).toBe('12');
+ expect(creditCard.Creditcard!.ExpiryYear).toBe('28');
+
+ const google = byName(imported, 'Google');
+ expect(google.ItemType).toBe(ItemTypes.Login);
+ expect(google.Username).toBe('usergoogle');
+ expect(google.Email).toBe('[email protected]');
+ expect(google.Password).toBe('password');
+ expect(google.ServiceUrls?.[0]).toBe('https://accounts.google.com/');
+ expect(google.TwoFactorSecret).toBe('PLW4SB3PQ7MKVXY2MXF4NEXS6Y');
+ expect(google.Notes).toContain('Security question: secquestion');
+ expect(google.Notes).toContain('Security answer: secanswer');
+
+ const identity = byName(imported, 'Identity');
+ expect(identity.ItemType).toBe(ItemTypes.Alias);
+ expect(identity.Alias).toBeDefined();
+ expect(identity.Alias!.FirstName).toBe('John');
+ expect(identity.Alias!.LastName).toBe('Johnson');
+ expect(identity.Alias!.Gender).toBe('Male');
+ expect(identity.Alias!.BirthDate?.getTime()).toBe(utc(1970, 1, 1).getTime());
+
+ const password = byName(imported, 'Password');
+ expect(password.ItemType).toBe(ItemTypes.Login);
+ expect(password.Username).toBe('loginpw1');
+ expect(password.Password).toBe('password');
+
+ const secureNote = byName(imported, 'Securenote');
+ expect(secureNote.ItemType).toBe(ItemTypes.Note);
+ expect(secureNote.Notes).toBe('Note only content here');
+ });
+
+ it('converts Enpass credit cards', () => {
+ const imported = importEnpassCsv(readFixtureText(import.meta.dirname, 'enpass.csv'));
+ const item = convertToItems([byName(imported, 'Credit Card')])[0];
+
+ expect(item.ItemType).toBe(ItemTypes.CreditCard);
+ expect(item.FieldValues.find(fv => fv.FieldKey === FieldKey.CardNumber)?.Value).toBe('1234123412341234');
+ expect(item.FieldValues.find(fv => fv.FieldKey === FieldKey.CardCardholderName)?.Value).toBe('ccholder');
+ expect(item.FieldValues.find(fv => fv.FieldKey === FieldKey.CardCvv)?.Value).toBe('1234');
+ expect(item.FieldValues.find(fv => fv.FieldKey === FieldKey.CardPin)?.Value).toBe('1234');
+ });
+});
diff --git a/core/client/src/transfer/__tests__/fixtures/enpass.csv b/core/client/src/transfer/import/importers/enpass/__tests__/enpass.csv
similarity index 100%
rename from core/client/src/transfer/__tests__/fixtures/enpass.csv
rename to core/client/src/transfer/import/importers/enpass/__tests__/enpass.csv
diff --git a/core/client/src/transfer/import/importers/FirefoxCsvImporter.ts b/core/client/src/transfer/import/importers/firefox/FirefoxCsvImporter.ts
similarity index 73%
rename from core/client/src/transfer/import/importers/FirefoxCsvImporter.ts
rename to core/client/src/transfer/import/importers/firefox/FirefoxCsvImporter.ts
index 14a6db980..d91e216b7 100644
--- a/core/client/src/transfer/import/importers/FirefoxCsvImporter.ts
+++ b/core/client/src/transfer/import/importers/firefox/FirefoxCsvImporter.ts
@@ -1,9 +1,8 @@
-import { readImportCsv } from '../readers/CsvImport';
-import { text } from '../readers/CsvRecordMapper';
+import { readImportCsv } from '../../readers/CsvImport';
+import { text } from '../../readers/CsvRecordMapper';
+import { parseUrls } from '../../readers/FieldParsers';
-import { parseUrls } from './shared/CredentialHelpers';
-
-import type { ImportedCredential } from '../models/ImportedCredential';
+import type { ImportedCredential } from '../../models/ImportedCredential';
const COLUMNS = {
url: text,
diff --git a/core/client/src/transfer/import/importers/firefox/__tests__/FirefoxCsvImporter.test.ts b/core/client/src/transfer/import/importers/firefox/__tests__/FirefoxCsvImporter.test.ts
new file mode 100644
index 000000000..7b8b8f719
--- /dev/null
+++ b/core/client/src/transfer/import/importers/firefox/__tests__/FirefoxCsvImporter.test.ts
@@ -0,0 +1,21 @@
+import { describe, expect, it } from 'vitest';
+
+import { readFixtureText, byName } from '../../../__tests__/testHelpers';
+import { importFirefoxCsv } from '../FirefoxCsvImporter';
+
+describe('FirefoxCsvImporter', () => {
+ it('imports Firefox CSV', () => {
+ const imported = importFirefoxCsv(readFixtureText(import.meta.dirname, 'firefox.csv'));
+ expect(imported).toHaveLength(3);
+
+ const example = byName(imported, 'example.com');
+ expect(example.ServiceUrls?.[0]).toBe('https://example.com');
+ expect(example.Username).toBe('username-example');
+ expect(example.Password).toBe('examplepassword');
+
+ const youtube = byName(imported, 'youtube.com');
+ expect(youtube.ServiceUrls?.[0]).toBe('https://youtube.com');
+ expect(youtube.Username).toBe('youtubeusername');
+ expect(youtube.Password).toBe('youtubepassword');
+ });
+});
diff --git a/core/client/src/transfer/__tests__/fixtures/firefox.csv b/core/client/src/transfer/import/importers/firefox/__tests__/firefox.csv
similarity index 100%
rename from core/client/src/transfer/__tests__/fixtures/firefox.csv
rename to core/client/src/transfer/import/importers/firefox/__tests__/firefox.csv
diff --git a/core/client/src/transfer/import/importers/GenericCsvImporter.ts b/core/client/src/transfer/import/importers/generic/GenericCsvImporter.ts
similarity index 87%
rename from core/client/src/transfer/import/importers/GenericCsvImporter.ts
rename to core/client/src/transfer/import/importers/generic/GenericCsvImporter.ts
index b1a6a1ca4..3815901f7 100644
--- a/core/client/src/transfer/import/importers/GenericCsvImporter.ts
+++ b/core/client/src/transfer/import/importers/generic/GenericCsvImporter.ts
@@ -1,10 +1,9 @@
-import { isBlank, nullIfBlank } from '../../shared/StringUtils';
-import { readImportCsv } from '../readers/CsvImport';
-import { optionalText, text } from '../readers/CsvRecordMapper';
+import { isBlank, nullIfBlank } from '../../../shared/StringUtils';
+import { readImportCsv } from '../../readers/CsvImport';
+import { optionalText, text } from '../../readers/CsvRecordMapper';
+import { parseUrls } from '../../readers/FieldParsers';
-import { parseUrls } from './shared/CredentialHelpers';
-
-import type { ImportedCredential } from '../models/ImportedCredential';
+import type { ImportedCredential } from '../../models/ImportedCredential';
const COLUMNS = {
service_name: text,
diff --git a/core/client/src/transfer/import/importers/generic/__tests__/GenericCsvImporter.test.ts b/core/client/src/transfer/import/importers/generic/__tests__/GenericCsvImporter.test.ts
new file mode 100644
index 000000000..6fd72d49b
--- /dev/null
+++ b/core/client/src/transfer/import/importers/generic/__tests__/GenericCsvImporter.test.ts
@@ -0,0 +1,54 @@
+import { describe, expect, it } from 'vitest';
+
+import { byName } from '../../../__tests__/testHelpers';
+import { getGenericCsvTemplate, importGenericCsv } from '../GenericCsvImporter';
+
+describe('GenericCsvImporter', () => {
+ it('imports the generic CSV template', () => {
+ const imported = importGenericCsv(new TextDecoder().decode(getGenericCsvTemplate()));
+ expect(imported).toHaveLength(4);
+
+ const gmail = byName(imported, 'Gmail');
+ expect(gmail.ServiceUrls?.[0]).toBe('https://gmail.com');
+ expect(gmail.Username).toBe('[email protected]');
+ expect(gmail.Password).toBe('your_password');
+ expect(gmail.Notes).toBe('Important email account');
+ expect(gmail.TwoFactorSecret).toBe('');
+ expect(gmail.FolderPath).toBe('Personal');
+
+ const facebook = byName(imported, 'Facebook');
+ expect(facebook.ServiceUrls?.[0]).toBe('https://facebook.com');
+ expect(facebook.Username).toBe('your.username');
+ expect(facebook.Password).toBe('your_password');
+ expect(facebook.Notes).toBe('Social media account');
+ expect(facebook.TwoFactorSecret).toBe('');
+ expect(facebook.FolderPath).toBe('Personal/Social');
+
+ const github = byName(imported, 'GitHub');
+ expect(github.ServiceUrls?.[0]).toBe('https://github.com');
+ expect(github.Username).toBe('developer_username');
+ expect(github.Password).toBe('your_password');
+ expect(github.Notes).toBe('Development platform');
+ expect(github.TwoFactorSecret).toBe('your_totp_secret_here');
+ expect(github.FolderPath).toBe('Work');
+
+ const secureNote = byName(imported, 'Secure Note');
+ expect(secureNote.ServiceUrls?.[0]).toBeUndefined();
+ expect(secureNote.Username).toBe('');
+ expect(secureNote.Password).toBe('');
+ expect(secureNote.Notes).toBe('Important information or notes without login credentials');
+ expect(secureNote.TwoFactorSecret).toBe('');
+ expect(secureNote.FolderPath).toBeNull();
+ });
+
+ it('provides the generic CSV template', () => {
+ const template = new TextDecoder().decode(getGenericCsvTemplate());
+ expect(template).toContain('service_name,url,username,password,totp_secret,notes,folder');
+ expect(template).toContain('Gmail');
+ expect(template).toContain('Facebook');
+ expect(template).toContain('GitHub');
+ expect(template).toContain('Secure Note');
+ expect(template).toContain('[email protected]');
+ expect(template).toContain('your_totp_secret_here');
+ });
+});
diff --git a/core/client/src/transfer/import/importers/KeePassCsvImporter.ts b/core/client/src/transfer/import/importers/keepass/KeePassCsvImporter.ts
similarity index 77%
rename from core/client/src/transfer/import/importers/KeePassCsvImporter.ts
rename to core/client/src/transfer/import/importers/keepass/KeePassCsvImporter.ts
index 17b11c752..d3b393a4c 100644
--- a/core/client/src/transfer/import/importers/KeePassCsvImporter.ts
+++ b/core/client/src/transfer/import/importers/keepass/KeePassCsvImporter.ts
@@ -1,9 +1,8 @@
-import { readImportCsv } from '../readers/CsvImport';
-import { optionalText, text } from '../readers/CsvRecordMapper';
+import { readImportCsv } from '../../readers/CsvImport';
+import { optionalText, text } from '../../readers/CsvRecordMapper';
+import { parseUrls } from '../../readers/FieldParsers';
-import { parseUrls } from './shared/CredentialHelpers';
-
-import type { ImportedCredential } from '../models/ImportedCredential';
+import type { ImportedCredential } from '../../models/ImportedCredential';
const COLUMNS = {
Account: text,
diff --git a/core/client/src/transfer/import/importers/keepass/__tests__/KeePassCsvImporter.test.ts b/core/client/src/transfer/import/importers/keepass/__tests__/KeePassCsvImporter.test.ts
new file mode 100644
index 000000000..8322a3fe3
--- /dev/null
+++ b/core/client/src/transfer/import/importers/keepass/__tests__/KeePassCsvImporter.test.ts
@@ -0,0 +1,41 @@
+import { describe, expect, it } from 'vitest';
+
+import { readFixtureText, byName } from '../../../__tests__/testHelpers';
+import { importKeePassCsv } from '../KeePassCsvImporter';
+
+describe('KeePassCsvImporter', () => {
+ it('imports KeePass CSV', () => {
+ const imported = importKeePassCsv(readFixtureText(import.meta.dirname, 'keepass.csv'));
+ expect(imported).toHaveLength(2);
+
+ const sample = byName(imported, 'Sample Entry');
+ expect(sample.ServiceUrls?.[0]).toBe('https://keepass.info/');
+ expect(sample.Username).toBe('User Name');
+ expect(sample.Password).toBe('Password');
+ expect(sample.Notes).toBe('Notes');
+
+ const sample2 = byName(imported, 'Sample Entry #2');
+ expect(sample2.ServiceUrls?.[0]).toBe('https://keepass.info/help/kb/testform.html');
+ expect(sample2.Username).toBe('Michael321');
+ expect(sample2.Password).toBe('12345');
+ expect(sample2.Notes).toBe('');
+ });
+
+ it('imports KeePass CSV with special characters and double quotes', () => {
+ const imported = importKeePassCsv(readFixtureText(import.meta.dirname, 'keepass_special_chars.csv'));
+ expect(imported).toHaveLength(3);
+
+ const special = imported.find(c => c.ServiceName?.startsWith('Entry with'))!;
+ expect(special.ServiceName).toBe('Entry with "notes" special chars');
+ expect(special.ServiceUrls?.[0]).toBeUndefined();
+ expect(special.Username).toBe('');
+ expect(special.Password).toBe('DVfIsb4TGkL7oKCwyiet');
+ expect(special.Notes).toBe('Note "with quotes"\'as\'d as/d/asd/ z\'s\'sd a8e89A)_@()@\'":ÄS"d\';asd;á\'sd');
+
+ const sample = byName(imported, 'Sample Entry');
+ expect(sample.ServiceUrls?.[0]).toBe('https://keepass.info/');
+ expect(sample.Username).toBe('User Name');
+ expect(sample.Password).toBe('Password');
+ expect(sample.Notes).toBe('Notes');
+ });
+});
diff --git a/core/client/src/transfer/__tests__/fixtures/keepass.csv b/core/client/src/transfer/import/importers/keepass/__tests__/keepass.csv
similarity index 100%
rename from core/client/src/transfer/__tests__/fixtures/keepass.csv
rename to core/client/src/transfer/import/importers/keepass/__tests__/keepass.csv
diff --git a/core/client/src/transfer/__tests__/fixtures/keepass_special_chars.csv b/core/client/src/transfer/import/importers/keepass/__tests__/keepass_special_chars.csv
similarity index 100%
rename from core/client/src/transfer/__tests__/fixtures/keepass_special_chars.csv
rename to core/client/src/transfer/import/importers/keepass/__tests__/keepass_special_chars.csv
diff --git a/core/client/src/transfer/import/importers/KeePassXcCsvImporter.ts b/core/client/src/transfer/import/importers/keepassxc/KeePassXcCsvImporter.ts
similarity index 68%
rename from core/client/src/transfer/import/importers/KeePassXcCsvImporter.ts
rename to core/client/src/transfer/import/importers/keepassxc/KeePassXcCsvImporter.ts
index d95fc44d4..483ae4b2f 100644
--- a/core/client/src/transfer/import/importers/KeePassXcCsvImporter.ts
+++ b/core/client/src/transfer/import/importers/keepassxc/KeePassXcCsvImporter.ts
@@ -1,10 +1,9 @@
-import { nullIfBlank } from '../../shared/StringUtils';
-import { readImportCsv } from '../readers/CsvImport';
-import { optionalText, text } from '../readers/CsvRecordMapper';
+import { nullIfBlank } from '../../../shared/StringUtils';
+import { readImportCsv } from '../../readers/CsvImport';
+import { optionalText, text } from '../../readers/CsvRecordMapper';
+import { parseUrls } from '../../readers/FieldParsers';
-import { parseUrls } from './shared/CredentialHelpers';
-
-import type { ImportedCredential } from '../models/ImportedCredential';
+import type { ImportedCredential } from '../../models/ImportedCredential';
const COLUMNS = {
Group: text,
diff --git a/core/client/src/transfer/import/importers/keepassxc/__tests__/KeePassXcCsvImporter.test.ts b/core/client/src/transfer/import/importers/keepassxc/__tests__/KeePassXcCsvImporter.test.ts
new file mode 100644
index 000000000..9dfece3c8
--- /dev/null
+++ b/core/client/src/transfer/import/importers/keepassxc/__tests__/KeePassXcCsvImporter.test.ts
@@ -0,0 +1,43 @@
+import { describe, expect, it } from 'vitest';
+
+import { parseFolderPath } from '../../../../shared/FolderPaths';
+import { readFixtureText, byName } from '../../../__tests__/testHelpers';
+import { collectHierarchicalFolderPaths } from '../../../writers/ImportDuplicateDetection';
+import { importKeePassXcCsv } from '../KeePassXcCsvImporter';
+
+describe('KeePassXcCsvImporter', () => {
+ it('imports KeePassXC CSV', () => {
+ const imported = importKeePassXcCsv(readFixtureText(import.meta.dirname, 'keepassxc.csv'));
+ expect(imported).toHaveLength(3);
+
+ const sample = byName(imported, 'Sample Entry');
+ expect(sample.ServiceUrls?.[0]).toBe('https://keepass.info/');
+ expect(sample.Username).toBe('User Name');
+ expect(sample.Password).toBe('Password');
+ expect(sample.Notes).toBe('Notes');
+ expect(sample.TwoFactorSecret).toBe('');
+
+ const sample2 = byName(imported, 'Sample Entry #2');
+ expect(sample2.ServiceUrls?.[0]).toBe('https://keepass.info/help/kb/testform.html');
+ expect(sample2.Username).toBe('Michael321');
+ expect(sample2.Password).toBe('12345');
+ expect(sample2.Notes).toBe('');
+ expect(sample2.TwoFactorSecret).toBe('');
+
+ const nested = byName(imported, 'Nested Entry');
+ expect(nested.ServiceUrls?.[0]).toBe('https://example.com/');
+ expect(nested.Username).toBe('testuser');
+ expect(nested.Password).toBe('testpass123');
+ expect(nested.Notes).toBe('Nested folder test');
+ expect(nested.FolderPath).toBe('Database/Windows/Windowssub1');
+ });
+
+ it('imports KeePassXC groups with nesting', () => {
+ const imported = importKeePassXcCsv(readFixtureText(import.meta.dirname, 'keepassxc.csv'));
+
+ expect(collectHierarchicalFolderPaths(imported)).toEqual(['Database', 'Test1', 'Database/Windows', 'Database/Windows/Windowssub1']);
+
+ const nested = byName(imported, 'Nested Entry');
+ expect(parseFolderPath(nested.FolderPath)).toEqual(['Database', 'Windows', 'Windowssub1']);
+ });
+});
diff --git a/core/client/src/transfer/__tests__/fixtures/keepassxc.csv b/core/client/src/transfer/import/importers/keepassxc/__tests__/keepassxc.csv
similarity index 100%
rename from core/client/src/transfer/__tests__/fixtures/keepassxc.csv
rename to core/client/src/transfer/import/importers/keepassxc/__tests__/keepassxc.csv
diff --git a/core/client/src/transfer/import/importers/LastPassCsvImporter.ts b/core/client/src/transfer/import/importers/lastpass/LastPassCsvImporter.ts
similarity index 89%
rename from core/client/src/transfer/import/importers/LastPassCsvImporter.ts
rename to core/client/src/transfer/import/importers/lastpass/LastPassCsvImporter.ts
index 9e4809d9f..b7f2858d3 100644
--- a/core/client/src/transfer/import/importers/LastPassCsvImporter.ts
+++ b/core/client/src/transfer/import/importers/lastpass/LastPassCsvImporter.ts
@@ -1,13 +1,12 @@
import { ItemTypes } from '@aliasvault/models/vault';
-import { isBlank, nullIfBlank } from '../../shared/StringUtils';
-import { readImportCsv } from '../readers/CsvImport';
-import { optionalText, text } from '../readers/CsvRecordMapper';
+import { isBlank, nullIfBlank } from '../../../shared/StringUtils';
+import { readImportCsv } from '../../readers/CsvImport';
+import { optionalText, text } from '../../readers/CsvRecordMapper';
+import { parseUrls } from '../../readers/FieldParsers';
-import { parseUrls } from './shared/CredentialHelpers';
-
-import type { ImportedCredential } from '../models/ImportedCredential';
-import type { ImportedCreditcard } from '../models/ImportedCreditcard';
+import type { ImportedCredential } from '../../models/ImportedCredential';
+import type { ImportedCreditcard } from '../../models/ImportedCreditcard';
const COLUMNS = {
url: optionalText,
diff --git a/core/client/src/transfer/import/importers/lastpass/__tests__/LastPassCsvImporter.test.ts b/core/client/src/transfer/import/importers/lastpass/__tests__/LastPassCsvImporter.test.ts
new file mode 100644
index 000000000..8c3578118
--- /dev/null
+++ b/core/client/src/transfer/import/importers/lastpass/__tests__/LastPassCsvImporter.test.ts
@@ -0,0 +1,74 @@
+import { FieldKey, ItemTypes } from '@aliasvault/models/vault';
+import { describe, expect, it } from 'vitest';
+
+import { readFixtureText, byName, itemByName } from '../../../__tests__/testHelpers';
+import { convertToItems } from '../../../writers/ItemConverter';
+import { importLastPassCsv } from '../LastPassCsvImporter';
+
+describe('LastPassCsvImporter', () => {
+ it('imports LastPass CSV', () => {
+ const imported = importLastPassCsv(readFixtureText(import.meta.dirname, 'lastpass.csv'));
+ expect(imported).toHaveLength(5);
+
+ const example = byName(imported, 'Examplename');
+ expect(example.ServiceUrls?.[0]).toBe('https://example.com');
+ expect(example.Username).toBe('Exampleusername');
+ expect(example.Password).toBe('examplepassword');
+ expect(example.Notes).toBe('Examplenotes');
+ expect(example.TwoFactorSecret).toBe('');
+
+ // LastPass writes "http://" for entries without a URL.
+ const withoutUrl = byName(imported, 'Userwithouturlornotes');
+ expect(withoutUrl.ServiceUrls?.[0]).toBeUndefined();
+ expect(withoutUrl.Username).toBe('userwithouturlornotes');
+ expect(withoutUrl.Password).toBe('userpass');
+ expect(withoutUrl.Notes).toBe('');
+ expect(withoutUrl.TwoFactorSecret).toBe('');
+
+ // Secure notes use "http://sn".
+ const secureNote = byName(imported, 'securenote1');
+ expect(secureNote.ServiceUrls?.[0]).toBeUndefined();
+ expect(secureNote.Username).toBe('');
+ expect(secureNote.Password).toBe('');
+ expect(secureNote.Notes).toBe('Securenotecontent here');
+ expect(secureNote.TwoFactorSecret).toBe('');
+
+ const creditCard = byName(imported, 'Paymentcard1');
+ expect(creditCard.ServiceUrls?.[0]).toBeUndefined();
+ expect(creditCard.Username).toBe('');
+ expect(creditCard.Password).toBe('');
+ expect(creditCard.ItemType).toBe(ItemTypes.CreditCard);
+ expect(creditCard.Creditcard).toBeDefined();
+ expect(creditCard.Creditcard!.CardholderName).toBe('Cardname');
+ expect(creditCard.Creditcard!.Number).toBe('123456781234');
+ expect(creditCard.Creditcard!.Cvv).toBe('1234');
+ expect(creditCard.Notes).toBe('Creditcardnotes here');
+ expect(creditCard.TwoFactorSecret).toBe('');
+ });
+
+ it('detects LastPass secure notes', () => {
+ const items = convertToItems(importLastPassCsv(readFixtureText(import.meta.dirname, 'lastpass.csv')));
+ expect(itemByName(items, 'securenote1').ItemType).toBe(ItemTypes.Note);
+ });
+
+ it('detects and converts LastPass credit cards', () => {
+ const imported = importLastPassCsv(readFixtureText(import.meta.dirname, 'lastpass.csv'));
+ const creditCard = byName(imported, 'Paymentcard1');
+ expect(creditCard.ItemType).toBe(ItemTypes.CreditCard);
+ expect(creditCard.Creditcard!.CardholderName).toBe('Cardname');
+ expect(creditCard.Creditcard!.Number).toBe('123456781234');
+ expect(creditCard.Creditcard!.Cvv).toBe('1234');
+
+ const item = convertToItems([creditCard])[0];
+ expect(item.ItemType).toBe(ItemTypes.CreditCard);
+ expect(item.FieldValues.find(fv => fv.FieldKey === FieldKey.CardNumber)?.Value).toBe('123456781234');
+ expect(item.FieldValues.find(fv => fv.FieldKey === FieldKey.CardCardholderName)?.Value).toBe('Cardname');
+ });
+
+ it('imports LastPass folders', () => {
+ const imported = importLastPassCsv(readFixtureText(import.meta.dirname, 'lastpass.csv'));
+ const withFolder = imported.find(c => !!c.FolderPath);
+ expect(withFolder).toBeDefined();
+ expect(withFolder!.FolderPath).toBe('examplefolder');
+ });
+});
diff --git a/core/client/src/transfer/__tests__/fixtures/lastpass.csv b/core/client/src/transfer/import/importers/lastpass/__tests__/lastpass.csv
similarity index 100%
rename from core/client/src/transfer/__tests__/fixtures/lastpass.csv
rename to core/client/src/transfer/import/importers/lastpass/__tests__/lastpass.csv
diff --git a/core/client/src/transfer/import/importers/NordPassCsvImporter.ts b/core/client/src/transfer/import/importers/nordpass/NordPassCsvImporter.ts
similarity index 84%
rename from core/client/src/transfer/import/importers/NordPassCsvImporter.ts
rename to core/client/src/transfer/import/importers/nordpass/NordPassCsvImporter.ts
index 8e5451c4c..35d2aec04 100644
--- a/core/client/src/transfer/import/importers/NordPassCsvImporter.ts
+++ b/core/client/src/transfer/import/importers/nordpass/NordPassCsvImporter.ts
@@ -1,13 +1,12 @@
import { ItemTypes } from '@aliasvault/models/vault';
-import { isBlank, nonBlank, nullIfBlank } from '../../shared/StringUtils';
-import { readImportCsv } from '../readers/CsvImport';
-import { optionalText, text } from '../readers/CsvRecordMapper';
+import { isBlank, nonBlank, nullIfBlank } from '../../../shared/StringUtils';
+import { readImportCsv } from '../../readers/CsvImport';
+import { optionalText, text } from '../../readers/CsvRecordMapper';
+import { mapItemType, parseUrls } from '../../readers/FieldParsers';
-import { mapItemType, parseUrls } from './shared/CredentialHelpers';
-
-import type { ImportedCredential } from '../models/ImportedCredential';
-import type { ImportedCreditcard } from '../models/ImportedCreditcard';
+import type { ImportedCredential } from '../../models/ImportedCredential';
+import type { ImportedCreditcard } from '../../models/ImportedCreditcard';
const COLUMNS = {
name: text,
diff --git a/core/client/src/transfer/import/importers/nordpass/__tests__/NordPassCsvImporter.test.ts b/core/client/src/transfer/import/importers/nordpass/__tests__/NordPassCsvImporter.test.ts
new file mode 100644
index 000000000..f8561b1d7
--- /dev/null
+++ b/core/client/src/transfer/import/importers/nordpass/__tests__/NordPassCsvImporter.test.ts
@@ -0,0 +1,71 @@
+import { FieldKey, ItemTypes } from '@aliasvault/models/vault';
+import { describe, expect, it } from 'vitest';
+
+import { readFixtureText, byName } from '../../../__tests__/testHelpers';
+import { collectHierarchicalFolderPaths } from '../../../writers/ImportDuplicateDetection';
+import { convertToItems } from '../../../writers/ItemConverter';
+import { importNordPassCsv } from '../NordPassCsvImporter';
+
+describe('NordPassCsvImporter', () => {
+ it('imports NordPass CSV', () => {
+ const imported = importNordPassCsv(readFixtureText(import.meta.dirname, 'nordpass.csv'));
+ // The folder row is skipped.
+ expect(imported).toHaveLength(4);
+
+ const password = byName(imported, 'Password title');
+ expect(password.ServiceUrls?.[0]).toBe('http://google.nl');
+ expect(password.Username).toBe('[email protected]');
+ expect(password.Password).toBe('password');
+ expect(password.FolderPath).toBe('Business');
+ expect(password.ItemType).toBe(ItemTypes.Login);
+ expect(password.Notes).toContain('[{"type":"text","label":"CustomFieldName1","value":"Test"}]');
+
+ const secureNote = byName(imported, 'SecureNote1');
+ expect(secureNote.ServiceUrls?.[0]).toBeUndefined();
+ expect(secureNote.Username).toBe('');
+ expect(secureNote.Password).toBe('');
+ expect(secureNote.ItemType).toBe(ItemTypes.Note);
+ expect(secureNote.Notes).toContain('This is my secure note content');
+ expect(secureNote.Notes).toContain('Test test');
+
+ const creditCard = byName(imported, 'Creditcard Visa');
+ expect(creditCard.ItemType).toBe(ItemTypes.CreditCard);
+ expect(creditCard.Creditcard).toBeDefined();
+ expect(creditCard.Creditcard!.CardholderName).toBe('Holdername');
+ expect(creditCard.Creditcard!.Number).toBe('1234123412341234123');
+ expect(creditCard.Creditcard!.Cvv).toBe('1231');
+ expect(creditCard.Creditcard!.Pin).toBe('1231');
+ expect(creditCard.Creditcard!.ExpiryMonth).toBe('12');
+ expect(creditCard.Creditcard!.ExpiryYear).toBe('28');
+
+ const rootItem = byName(imported, 'Root item');
+ expect(rootItem.Username).toBe('rootuser');
+ expect(rootItem.Password).toBe('rootpass');
+ expect(rootItem.FolderPath).toBeNull();
+ expect(rootItem.ItemType).toBe(ItemTypes.Login);
+ });
+
+ it('collects NordPass folders', () => {
+ const imported = importNordPassCsv(readFixtureText(import.meta.dirname, 'nordpass.csv'));
+ expect(collectHierarchicalFolderPaths(imported)).toContain('Business');
+ expect(imported.find(c => c.FolderPath === 'Business')!.ServiceName).toBe('Password title');
+ });
+
+ it('detects and converts NordPass credit cards', () => {
+ const imported = importNordPassCsv(readFixtureText(import.meta.dirname, 'nordpass.csv'));
+ const creditCard = byName(imported, 'Creditcard Visa');
+ expect(creditCard.ItemType).toBe(ItemTypes.CreditCard);
+ expect(creditCard.Creditcard!.CardholderName).toBe('Holdername');
+ expect(creditCard.Creditcard!.Number).toBe('1234123412341234123');
+ expect(creditCard.Creditcard!.Cvv).toBe('1231');
+ expect(creditCard.Creditcard!.Pin).toBe('1231');
+ expect(creditCard.Creditcard!.ExpiryMonth).toBe('12');
+ expect(creditCard.Creditcard!.ExpiryYear).toBe('28');
+
+ const item = convertToItems([creditCard])[0];
+ expect(item.ItemType).toBe(ItemTypes.CreditCard);
+ expect(item.FieldValues.find(fv => fv.FieldKey === FieldKey.CardNumber)?.Value).toBe('1234123412341234123');
+ expect(item.FieldValues.find(fv => fv.FieldKey === FieldKey.CardCardholderName)?.Value).toBe('Holdername');
+ expect(item.FieldValues.find(fv => fv.FieldKey === FieldKey.CardPin)?.Value).toBe('1231');
+ });
+});
diff --git a/core/client/src/transfer/__tests__/fixtures/nordpass.csv b/core/client/src/transfer/import/importers/nordpass/__tests__/nordpass.csv
similarity index 100%
rename from core/client/src/transfer/__tests__/fixtures/nordpass.csv
rename to core/client/src/transfer/import/importers/nordpass/__tests__/nordpass.csv
diff --git a/core/client/src/transfer/import/importers/onepassword/OnePassword1puxImporter.ts b/core/client/src/transfer/import/importers/onepassword/OnePassword1puxImporter.ts
index 26cc628f4..bae35e114 100644
--- a/core/client/src/transfer/import/importers/onepassword/OnePassword1puxImporter.ts
+++ b/core/client/src/transfer/import/importers/onepassword/OnePassword1puxImporter.ts
@@ -3,9 +3,8 @@ import { FieldTypes, ItemTypes, type FieldType, type ItemType } from '@aliasvaul
import { formatDateOnly, fromUnixTimeSeconds } from '../../../shared/DateTimeUtils';
import { isBlank, nonBlank, nullIfBlank } from '../../../shared/StringUtils';
import { ImportException, ImportStage } from '../../models/ImportException';
+import { addAttachment, addCustomField, convertArchiveItems, openArchive, readArchiveJson } from '../../readers/ArchiveImport';
import { readStringAtPath } from '../../readers/JsonReader';
-import { convertArchiveItems, openArchive, readArchiveJson } from '../shared/ArchiveImport';
-import { addAttachment, addCustomField } from '../shared/CredentialHelpers';
import { OnePasswordCategories, OnePasswordPersonalVaultType, parseOnePassword1puxAttributes, parseOnePassword1puxData, parseOnePasswordItem, type OnePasswordField, type OnePasswordFieldValue, type OnePasswordItem, type OnePasswordVault } from './OnePassword1pux';
diff --git a/core/client/src/transfer/import/importers/onepassword/OnePasswordCsvImporter.ts b/core/client/src/transfer/import/importers/onepassword/OnePasswordCsvImporter.ts
index 702b1883b..ed5526b35 100644
--- a/core/client/src/transfer/import/importers/onepassword/OnePasswordCsvImporter.ts
+++ b/core/client/src/transfer/import/importers/onepassword/OnePasswordCsvImporter.ts
@@ -1,7 +1,7 @@
import { nullIfBlank } from '../../../shared/StringUtils';
import { readImportCsv } from '../../readers/CsvImport';
import { optionalText, text } from '../../readers/CsvRecordMapper';
-import { parseUrls } from '../shared/CredentialHelpers';
+import { parseUrls } from '../../readers/FieldParsers';
import type { ImportedCredential } from '../../models/ImportedCredential';
diff --git a/core/client/src/transfer/__tests__/fixtures/1password_8.1pux b/core/client/src/transfer/import/importers/onepassword/__tests__/1password_8.1pux
similarity index 100%
rename from core/client/src/transfer/__tests__/fixtures/1password_8.1pux
rename to core/client/src/transfer/import/importers/onepassword/__tests__/1password_8.1pux
diff --git a/core/client/src/transfer/__tests__/fixtures/1password_8.csv b/core/client/src/transfer/import/importers/onepassword/__tests__/1password_8.csv
similarity index 100%
rename from core/client/src/transfer/__tests__/fixtures/1password_8.csv
rename to core/client/src/transfer/import/importers/onepassword/__tests__/1password_8.csv
diff --git a/core/client/src/transfer/import/importers/onepassword/__tests__/OnePassword1puxImporter.test.ts b/core/client/src/transfer/import/importers/onepassword/__tests__/OnePassword1puxImporter.test.ts
new file mode 100644
index 000000000..a30a9946e
--- /dev/null
+++ b/core/client/src/transfer/import/importers/onepassword/__tests__/OnePassword1puxImporter.test.ts
@@ -0,0 +1,75 @@
+import { ItemTypes } from '@aliasvault/models/vault';
+import { describe, expect, it } from 'vitest';
+
+import { readFixtureBytes, byName, itemByName } from '../../../__tests__/testHelpers';
+import { convertToItems } from '../../../writers/ItemConverter';
+import { importOnePassword1pux } from '../OnePassword1puxImporter';
+
+describe('OnePassword1puxImporter', () => {
+ it('imports a 1Password .1pux export', () => {
+ const imported = (importOnePassword1pux(readFixtureBytes(import.meta.dirname, '1password_8.1pux'))).Credentials;
+ expect(imported).toHaveLength(6);
+
+ const login = byName(imported, 'Example Login');
+ expect(login.Username).toBe('jdoe');
+ expect(login.Password).toBe('mySecurePassword123');
+ expect(login.ServiceUrls).toEqual(['https://example.com']);
+ expect(login.TwoFactorSecret).toBe('otpauth://totp/Example:jdoe?secret=JBSWY3DPEHPK3PXP&issuer=Example');
+ expect(login.Notes).toBe('My login notes here');
+ // The single "Personal" vault is promoted to root.
+ expect(login.FolderPath).toBeNull();
+ expect(login.ItemType).toBe(ItemTypes.Login);
+ expect(login.Tags).toHaveLength(2);
+ expect(login.Tags).toContain('work');
+ expect(login.Tags).toContain('important');
+ expect(login.CustomFieldValues!.find(f => f.Label === 'Recovery Email')!.Value).toBe('[email protected]');
+
+ // Timestamps come from Unix time.
+ expect(login.CreatedAt?.getTime()).toBe(1614298956 * 1000);
+ expect(login.UpdatedAt?.getTime()).toBe(1635346445 * 1000);
+
+ const card = byName(imported, 'My Visa Card');
+ expect(card.Notes).toBe('Primary credit card');
+ expect(card.FolderPath).toBeNull();
+ expect(card.ItemType).toBe(ItemTypes.CreditCard);
+ expect(card.Creditcard!.CardholderName).toBe('John Doe');
+ expect(card.Creditcard!.Number).toBe('4111111111111111');
+ expect(card.Creditcard!.Cvv).toBe('123');
+ expect(card.Creditcard!.Pin).toBe('1234');
+ expect(card.Creditcard!.ExpiryYear).toBe('2025');
+ expect(card.Creditcard!.ExpiryMonth).toBe('12');
+
+ const identity = byName(imported, 'My Identity');
+ expect(identity.ItemType).toBe(ItemTypes.Alias);
+ expect(identity.Alias!.FirstName).toBe('Jane');
+ expect(identity.Alias!.LastName).toBe('Smith');
+ expect(identity.Alias!.Gender).toBe('Female');
+ expect(identity.Alias!.BirthDate?.getTime()).toBe(631152000 * 1000);
+
+ const note = byName(imported, 'Secure Note');
+ expect(note.Notes).toBe('This is a secure note with important information.');
+ expect(note.ItemType).toBe(ItemTypes.Note);
+
+ const workLogin = byName(imported, 'Work Portal');
+ expect(workLogin.Username).toBe('admin');
+ expect(workLogin.Password).toBe('WorkPassword789!');
+ expect(workLogin.FolderPath).toBe('Work');
+ expect(workLogin.ItemType).toBe(ItemTypes.Login);
+
+ const doc = byName(imported, 'Sample Document');
+ expect(doc.Notes).toBe('Test document with attachment');
+ expect(doc.FolderPath).toBeNull();
+ expect(doc.ItemType).toBe(ItemTypes.Note);
+ expect(doc.Attachments).toHaveLength(1);
+ expect(doc.Attachments![0].Filename).toBe('sample-document.pdf');
+ expect(doc.Attachments![0].Blob.length).toBeGreaterThan(0);
+ expect(new TextDecoder().decode(doc.Attachments![0].Blob)).toContain('Sample document content');
+
+ const convertedItems = convertToItems(imported);
+ expect(convertedItems).toHaveLength(6);
+ const convertedLogin = itemByName(convertedItems, 'Example Login');
+ expect(convertedLogin.ItemType).toBe(ItemTypes.Login);
+ expect(convertedLogin.TotpCodes).toHaveLength(1);
+ expect(convertedLogin.TotpCodes[0].SecretKey).toBe('JBSWY3DPEHPK3PXP');
+ });
+});
diff --git a/core/client/src/transfer/import/importers/onepassword/__tests__/OnePasswordCsvImporter.test.ts b/core/client/src/transfer/import/importers/onepassword/__tests__/OnePasswordCsvImporter.test.ts
new file mode 100644
index 000000000..5defe9c29
--- /dev/null
+++ b/core/client/src/transfer/import/importers/onepassword/__tests__/OnePasswordCsvImporter.test.ts
@@ -0,0 +1,23 @@
+import { describe, expect, it } from 'vitest';
+
+import { readFixtureText, byName } from '../../../__tests__/testHelpers';
+import { importOnePasswordCsv } from '../OnePasswordCsvImporter';
+
+describe('OnePasswordCsvImporter', () => {
+ it('imports 1Password CSV', () => {
+ const imported = importOnePasswordCsv(readFixtureText(import.meta.dirname, '1password_8.csv'));
+ expect(imported).toHaveLength(4);
+
+ const twoFactor = imported.find(c => c.Username === 'username2fa')!;
+ expect(twoFactor.ServiceName).toBe('Test record 2 with 2FA');
+ expect(twoFactor.Password).toBe('password2fa');
+ expect(twoFactor.TwoFactorSecret).toBe('otpauth://totp/Strongbox?secret=PLW4SB3PQ7MKVXY2MXF4NEXS6Y&period=30&algorithm=SHA1&digits=6');
+ expect(twoFactor.Notes).toBe('Notes about 2FA record');
+
+ const account = byName(imported, '1Password Account (dpatel)');
+ expect(account.ServiceUrls?.[0]).toBe('https://my.1password.com');
+ expect(account.Username).toBe('[email protected]');
+ expect(account.Password).toBe('passwordexample');
+ expect(account.Notes).toBe('You can use this login to sign in to your account on 1password.com.');
+ });
+});
diff --git a/core/client/src/transfer/import/importers/protonpass/ProtonPassCsvImporter.ts b/core/client/src/transfer/import/importers/protonpass/ProtonPassCsvImporter.ts
index 3378c5b37..f23ceba1f 100644
--- a/core/client/src/transfer/import/importers/protonpass/ProtonPassCsvImporter.ts
+++ b/core/client/src/transfer/import/importers/protonpass/ProtonPassCsvImporter.ts
@@ -3,7 +3,7 @@ import { ItemTypes } from '@aliasvault/models/vault';
import { nullIfBlank } from '../../../shared/StringUtils';
import { readImportCsv } from '../../readers/CsvImport';
import { optionalText, text } from '../../readers/CsvRecordMapper';
-import { mapItemType, parseUrls } from '../shared/CredentialHelpers';
+import { mapItemType, parseUrls } from '../../readers/FieldParsers';
import type { ImportedCredential } from '../../models/ImportedCredential';
diff --git a/core/client/src/transfer/import/importers/protonpass/ProtonPassZipImporter.ts b/core/client/src/transfer/import/importers/protonpass/ProtonPassZipImporter.ts
index f401392cf..79391fed5 100644
--- a/core/client/src/transfer/import/importers/protonpass/ProtonPassZipImporter.ts
+++ b/core/client/src/transfer/import/importers/protonpass/ProtonPassZipImporter.ts
@@ -3,9 +3,9 @@ import { FieldTypes, ItemTypes } from '@aliasvault/models/vault';
import { fromUnixTimeSeconds } from '../../../shared/DateTimeUtils';
import { isBlank, nonBlank, nullIfBlank } from '../../../shared/StringUtils';
import { ImportException, ImportStage } from '../../models/ImportException';
+import { addAttachment, addCustomField, convertArchiveItems, openArchive, readArchiveJson } from '../../readers/ArchiveImport';
+import { mapItemType } from '../../readers/FieldParsers';
import { readStringAtPath } from '../../readers/JsonReader';
-import { convertArchiveItems, openArchive, readArchiveJson } from '../shared/ArchiveImport';
-import { addAttachment, addCustomField, mapItemType } from '../shared/CredentialHelpers';
import { ProtonPassItemStates, parseProtonPassItem, parseProtonPassJsonExport, type ProtonPassContent, type ProtonPassItem } from './ProtonPassJson';
diff --git a/core/client/src/transfer/import/importers/protonpass/__tests__/ProtonPassCsvImporter.test.ts b/core/client/src/transfer/import/importers/protonpass/__tests__/ProtonPassCsvImporter.test.ts
new file mode 100644
index 000000000..ce64d48ce
--- /dev/null
+++ b/core/client/src/transfer/import/importers/protonpass/__tests__/ProtonPassCsvImporter.test.ts
@@ -0,0 +1,34 @@
+import { ItemTypes } from '@aliasvault/models/vault';
+import { describe, expect, it } from 'vitest';
+
+import { readFixtureText, byName } from '../../../__tests__/testHelpers';
+import { importProtonPassCsv } from '../ProtonPassCsvImporter';
+
+describe('ProtonPassCsvImporter', () => {
+ it('imports ProtonPass CSV', () => {
+ const imported = importProtonPassCsv(readFixtureText(import.meta.dirname, 'protonpass.csv'));
+ expect(imported).toHaveLength(4);
+
+ const proton1 = byName(imported, 'Test proton 1');
+ expect(proton1.ServiceUrls?.[0]).toBe('https://www.website.com/');
+ expect(proton1.Username).toBe('user1');
+ expect(proton1.Password).toBe('pass1');
+ expect(proton1.TwoFactorSecret).toBe('otpauth://totp/Strongbox?secret=PLW4SB3PQ7MKVXY2MXF4NEXS6Y&algorithm=SHA1&digits=6&period=30');
+
+ const proton2 = byName(imported, 'Test proton2');
+ expect(proton2.Username).toBe('testuser2');
+ expect(proton2.Password).toBe('testpassword2');
+
+ const withoutPass = byName(imported, 'testwithoutpass');
+ expect(withoutPass.Username).toBe('testuser');
+ expect(withoutPass.Password).toBe('');
+
+ expect(byName(imported, 'Test alias').Email).toBe('[email protected]');
+ });
+
+ it('imports ProtonPass types and vaults', () => {
+ const imported = importProtonPassCsv(readFixtureText(import.meta.dirname, 'protonpass.csv'));
+ expect(imported.filter(c => !!c.FolderPath).length).toBeGreaterThan(0);
+ expect(imported.find(c => c.ItemType === ItemTypes.Login)).toBeDefined();
+ });
+});
diff --git a/core/client/src/transfer/import/importers/protonpass/__tests__/ProtonPassZipImporter.test.ts b/core/client/src/transfer/import/importers/protonpass/__tests__/ProtonPassZipImporter.test.ts
new file mode 100644
index 000000000..9a58073b1
--- /dev/null
+++ b/core/client/src/transfer/import/importers/protonpass/__tests__/ProtonPassZipImporter.test.ts
@@ -0,0 +1,70 @@
+import { ItemTypes } from '@aliasvault/models/vault';
+import { describe, expect, it } from 'vitest';
+
+import { readFixtureBytes, byName, itemByName } from '../../../__tests__/testHelpers';
+import { convertToItems } from '../../../writers/ItemConverter';
+import { importProtonPassZip } from '../ProtonPassZipImporter';
+
+describe('ProtonPassZipImporter', () => {
+ it('imports a Proton Pass .zip export', () => {
+ const imported = (importProtonPassZip(readFixtureBytes(import.meta.dirname, 'protonpass.zip'))).Credentials;
+ expect(imported).toHaveLength(7);
+
+ const loginWithTotp = byName(imported, 'Test proton 1');
+ expect(loginWithTotp.ItemType).toBe(ItemTypes.Login);
+ expect(loginWithTotp.Username).toBe('user1');
+ expect(loginWithTotp.Password).toBe('pass1');
+ expect(loginWithTotp.ServiceUrls).toEqual(['https://www.website.com/']);
+ expect(loginWithTotp.TwoFactorSecret?.startsWith('otpauth://totp/')).toBe(true);
+ // The "Personal" vault is promoted to root.
+ expect(loginWithTotp.FolderPath).toBeNull();
+ expect(loginWithTotp.Email).toBeNull();
+ expect(loginWithTotp.CreatedAt?.getTime()).toBe(1744362003 * 1000);
+
+ const alias = byName(imported, 'Test alias');
+ expect(alias.ItemType).toBe(ItemTypes.Login);
+ expect(alias.Email).toBe('[email protected]');
+ expect(alias.Username).toBe('[email protected]');
+ expect(alias.Password).toBeUndefined();
+ expect(alias.FolderPath).toBeNull();
+
+ const loginNoUrls = byName(imported, 'Test proton2');
+ expect(loginNoUrls.Username).toBe('testuser2');
+ expect(loginNoUrls.Password).toBe('testpassword2');
+ expect(loginNoUrls.ServiceUrls).toBeUndefined();
+ expect(loginNoUrls.TwoFactorSecret).toBeNull();
+
+ const loginNoPass = byName(imported, 'testwithoutpass');
+ expect(loginNoPass.Username).toBe('testuser');
+ expect(loginNoPass.Password).toBeNull();
+
+ const loginWithNote = byName(imported, 'Customfields');
+ expect(loginWithNote.Username).toBe('usernamecustom');
+ expect(loginWithNote.Password).toBe('passwordecustom');
+ expect(loginWithNote.Notes).toBe('Notecustom');
+ expect(loginWithNote.ServiceUrls).toEqual(['http://example.com/']);
+
+ const note = byName(imported, 'Customnote');
+ expect(note.ItemType).toBe(ItemTypes.Note);
+ expect(note.Notes).toBe('Customnotecontent');
+
+ const card = byName(imported, 'Testcreditcard');
+ expect(card.ItemType).toBe(ItemTypes.CreditCard);
+ expect(card.Notes).toBe('Custom note for creditcard');
+ expect(card.FolderPath).toBeNull();
+ expect(card.Creditcard!.CardholderName).toBe('J Johnson');
+ expect(card.Creditcard!.Number).toBe('1234123412341234123');
+ expect(card.Creditcard!.Cvv).toBe('123');
+ expect(card.Creditcard!.Pin).toBe('1234');
+ expect(card.Creditcard!.ExpiryYear).toBe('2029');
+ expect(card.Creditcard!.ExpiryMonth).toBe('06');
+
+ // Conversion extracts the TOTP secret from the URI.
+ const convertedItems = convertToItems(imported);
+ expect(convertedItems).toHaveLength(7);
+ const convertedLogin = itemByName(convertedItems, 'Test proton 1');
+ expect(convertedLogin.ItemType).toBe(ItemTypes.Login);
+ expect(convertedLogin.TotpCodes).toHaveLength(1);
+ expect(convertedLogin.TotpCodes[0].SecretKey).toBe('PLW4SB3PQ7MKVXY2MXF4NEXS6Y');
+ });
+});
diff --git a/core/client/src/transfer/__tests__/fixtures/protonpass.csv b/core/client/src/transfer/import/importers/protonpass/__tests__/protonpass.csv
similarity index 100%
rename from core/client/src/transfer/__tests__/fixtures/protonpass.csv
rename to core/client/src/transfer/import/importers/protonpass/__tests__/protonpass.csv
diff --git a/core/client/src/transfer/import/importers/RoboformCsvImporter.ts b/core/client/src/transfer/import/importers/roboform/RoboformCsvImporter.ts
similarity index 73%
rename from core/client/src/transfer/import/importers/RoboformCsvImporter.ts
rename to core/client/src/transfer/import/importers/roboform/RoboformCsvImporter.ts
index 93674e542..9ea777fae 100644
--- a/core/client/src/transfer/import/importers/RoboformCsvImporter.ts
+++ b/core/client/src/transfer/import/importers/roboform/RoboformCsvImporter.ts
@@ -1,12 +1,11 @@
import { ItemTypes } from '@aliasvault/models/vault';
-import { isBlank, nullIfBlank } from '../../shared/StringUtils';
-import { readImportCsv } from '../readers/CsvImport';
-import { optionalText, text } from '../readers/CsvRecordMapper';
+import { isBlank, nullIfBlank } from '../../../shared/StringUtils';
+import { readImportCsv } from '../../readers/CsvImport';
+import { optionalText, text } from '../../readers/CsvRecordMapper';
+import { parseUrls } from '../../readers/FieldParsers';
-import { parseUrls } from './shared/CredentialHelpers';
-
-import type { ImportedCredential } from '../models/ImportedCredential';
+import type { ImportedCredential } from '../../models/ImportedCredential';
const COLUMNS = {
Name: text,
diff --git a/core/client/src/transfer/import/importers/roboform/__tests__/RoboformCsvImporter.test.ts b/core/client/src/transfer/import/importers/roboform/__tests__/RoboformCsvImporter.test.ts
new file mode 100644
index 000000000..88d38e20b
--- /dev/null
+++ b/core/client/src/transfer/import/importers/roboform/__tests__/RoboformCsvImporter.test.ts
@@ -0,0 +1,62 @@
+import { FieldKey, ItemTypes } from '@aliasvault/models/vault';
+import { describe, expect, it } from 'vitest';
+
+import { readFixtureText, byName, itemByName } from '../../../__tests__/testHelpers';
+import { collectHierarchicalFolderPaths } from '../../../writers/ImportDuplicateDetection';
+import { convertToItems } from '../../../writers/ItemConverter';
+import { importRoboformCsv } from '../RoboformCsvImporter';
+
+describe('RoboformCsvImporter', () => {
+ it('imports RoboForm CSV', () => {
+ const imported = importRoboformCsv(readFixtureText(import.meta.dirname, 'roboform.csv'));
+ expect(imported).toHaveLength(5);
+
+ const com = byName(imported, 'Com');
+ expect(com.ServiceUrls?.[0]).toBe('https://www.example.com.com');
+ expect(com.Username).toBe('username1');
+ expect(com.Password).toBe('password1');
+ expect(com.Notes ?? '').toBe('');
+ expect(com.FolderPath).toBeNull();
+ expect(com.ItemType).toBe(ItemTypes.Login);
+
+ const example = byName(imported, 'Example');
+ expect(example.ServiceUrls?.[0]).toBe('https://www.example.com');
+ expect(example.Username).toBe('exampleusername');
+ expect(example.Password).toBe('examplepassword');
+ expect(example.Notes).toBe('Examplenote');
+ expect(example.FolderPath).toBeNull();
+ expect(example.ItemType).toBe(ItemTypes.Login);
+
+ const safeNote = byName(imported, 'Safenotename');
+ expect(safeNote.ServiceUrls?.[0]).toBeUndefined();
+ expect(safeNote.Username ?? '').toBe('');
+ expect(safeNote.Password ?? '').toBe('');
+ expect(safeNote.Notes).toBe('Safenote content example here');
+ expect(safeNote.ItemType).toBe(ItemTypes.Note);
+
+ const business = byName(imported, 'Business');
+ expect(business.ServiceUrls?.[0]).toBe('https://www.business.com');
+ expect(business.Username).toBe('businessusername');
+ expect(business.Password).toBe('businesspassword');
+ expect(business.FolderPath).toBe('Business');
+ expect(business.ItemType).toBe(ItemTypes.Login);
+
+ const multiline = byName(imported, 'Multiline safenote');
+ expect(multiline.Notes?.startsWith('First note line')).toBe(true);
+ expect(multiline.Notes).toContain('Fourth note line after a blank one');
+ expect(multiline.ItemType).toBe(ItemTypes.Note);
+ });
+
+ it('imports RoboForm folders', () => {
+ const imported = importRoboformCsv(readFixtureText(import.meta.dirname, 'roboform.csv'));
+ expect(collectHierarchicalFolderPaths(imported)).toContain('Business');
+ expect(imported.find(c => c.FolderPath === 'Business')!.ServiceName).toBe('Business');
+ });
+
+ it('detects RoboForm secure notes', () => {
+ const items = convertToItems(importRoboformCsv(readFixtureText(import.meta.dirname, 'roboform.csv')));
+ const secureNote = itemByName(items, 'Safenotename');
+ expect(secureNote.ItemType).toBe(ItemTypes.Note);
+ expect(secureNote.FieldValues.find(fv => fv.FieldKey === FieldKey.NotesContent)?.Value).toBe('Safenote content example here');
+ });
+});
diff --git a/core/client/src/transfer/__tests__/fixtures/roboform.csv b/core/client/src/transfer/import/importers/roboform/__tests__/roboform.csv
similarity index 100%
rename from core/client/src/transfer/__tests__/fixtures/roboform.csv
rename to core/client/src/transfer/import/importers/roboform/__tests__/roboform.csv
diff --git a/core/client/src/transfer/import/importers/shared/CredentialHelpers.ts b/core/client/src/transfer/import/importers/shared/CredentialHelpers.ts
deleted file mode 100644
index 9113aa3e4..000000000
--- a/core/client/src/transfer/import/importers/shared/CredentialHelpers.ts
+++ /dev/null
@@ -1,80 +0,0 @@
-import { FieldTypes, ItemTypes, type FieldType, type ItemType } from '@aliasvault/models/vault';
-
-import { isBlank } from '../../../shared/StringUtils';
-
-import type { ImportedCredential } from '../../models/ImportedCredential';
-
-/**
- * Split a URL column that may hold several comma separated URLs.
- * @param url - The URL text
- * @returns The URLs, or null when there are none
- */
-export function parseUrls(url: string | null | undefined): string[] | null {
- const urls = (url ?? '').split(',').map(u => u.trim()).filter(u => u.length > 0);
- return urls.length > 0 ? urls : null;
-}
-
-/**
- * Map a source's item type name to an item type.
- * @param value - The source's type name
- * @param types - Lower case type names to item types
- * @returns The item type, Login for unknown names, or null when the name is empty
- */
-export function mapItemType(value: string | null | undefined, types: Readonly<Record<string, ItemType>>): ItemType | null {
- if (isBlank(value)) {
- return null;
- }
- const key = value.toLowerCase();
- return Object.hasOwn(types, key) ? types[key] : ItemTypes.Login;
-}
-
-/**
- * Add a user-defined field to a credential; empty labels or values are skipped.
- * @param credential - The credential
- * @param label - The field label
- * @param value - The field value
- * @param fieldType - The field type, Text by default
- */
-export function addCustomField(credential: ImportedCredential, label: string | null | undefined, value: string | null | undefined, fieldType: FieldType = FieldTypes.Text): void {
- if (isBlank(label) || isBlank(value)) {
- return;
- }
-
- credential.CustomFieldValues ??= [];
- credential.CustomFieldValues.push({
- DefinitionId: crypto.randomUUID(),
- Label: label,
- Value: value,
- FieldType: fieldType,
- IsMultiValue: false,
- IsHidden: fieldType === FieldTypes.Hidden || fieldType === FieldTypes.Password,
- EnableHistory: false,
- Weight: 0,
- ValueWeight: 0,
- ApplicableToTypes: null,
- });
-}
-
-/**
- * Add an attachment to a credential.
- * @param credential - The credential
- * @param filename - The file name
- * @param data - The file data
- */
-export function addAttachment(credential: ImportedCredential, filename: string, data: Uint8Array): void {
- credential.Attachments ??= [];
- credential.Attachments.push({ Filename: filename, Blob: data });
-}
-
-/**
- * Append a block of text to a credential's notes, separated by an empty line.
- * @param credential - The credential
- * @param lines - The lines to append.
- */
-export function appendNotes(credential: ImportedCredential, lines: string[]): void {
- if (lines.length === 0) {
- return;
- }
- const block = lines.join('\n');
- credential.Notes = isBlank(credential.Notes) ? block : `${credential.Notes}\n\n${block}`;
-}
diff --git a/core/client/src/transfer/import/importers/StrongboxCsvImporter.ts b/core/client/src/transfer/import/importers/strongbox/StrongboxCsvImporter.ts
similarity index 71%
rename from core/client/src/transfer/import/importers/StrongboxCsvImporter.ts
rename to core/client/src/transfer/import/importers/strongbox/StrongboxCsvImporter.ts
index 60155e53b..fff6ae7fe 100644
--- a/core/client/src/transfer/import/importers/StrongboxCsvImporter.ts
+++ b/core/client/src/transfer/import/importers/strongbox/StrongboxCsvImporter.ts
@@ -1,9 +1,8 @@
-import { readImportCsv } from '../readers/CsvImport';
-import { optionalText, text } from '../readers/CsvRecordMapper';
+import { readImportCsv } from '../../readers/CsvImport';
+import { optionalText, text } from '../../readers/CsvRecordMapper';
+import { parseUrls } from '../../readers/FieldParsers';
-import { parseUrls } from './shared/CredentialHelpers';
-
-import type { ImportedCredential } from '../models/ImportedCredential';
+import type { ImportedCredential } from '../../models/ImportedCredential';
const COLUMNS = {
Title: text,
diff --git a/core/client/src/transfer/import/importers/strongbox/__tests__/StrongboxCsvImporter.test.ts b/core/client/src/transfer/import/importers/strongbox/__tests__/StrongboxCsvImporter.test.ts
new file mode 100644
index 000000000..23d617cc8
--- /dev/null
+++ b/core/client/src/transfer/import/importers/strongbox/__tests__/StrongboxCsvImporter.test.ts
@@ -0,0 +1,22 @@
+import { describe, expect, it } from 'vitest';
+
+import { readFixtureText, byName } from '../../../__tests__/testHelpers';
+import { importStrongboxCsv } from '../StrongboxCsvImporter';
+
+describe('StrongboxCsvImporter', () => {
+ it('imports Strongbox CSV', () => {
+ const imported = importStrongboxCsv(readFixtureText(import.meta.dirname, 'strongbox.csv'));
+ expect(imported).toHaveLength(6);
+
+ const tutaNota = byName(imported, 'TutaNota');
+ expect(tutaNota.Username).toBe('[email protected]');
+ expect(tutaNota.Password).toBe('blabla');
+ expect(tutaNota.TwoFactorSecret).toBe('otpauth://totp/Strongbox?secret=PLW4SB3PQ7MKVXY2MXF4NEXS6Y&algorithm=SHA1&digits=6&period=30');
+ expect(tutaNota.Notes).toContain('Recovery code for main account');
+
+ const sample = byName(imported, 'Sample');
+ expect(sample.ServiceUrls?.[0]).toBe('https://strongboxsafe.com');
+ expect(sample.Username).toBe('username');
+ expect(sample.Password).toBe('&3V_$z?Aiw-_x+nbYj');
+ });
+});
diff --git a/core/client/src/transfer/__tests__/fixtures/strongbox.csv b/core/client/src/transfer/import/importers/strongbox/__tests__/strongbox.csv
similarity index 100%
rename from core/client/src/transfer/__tests__/fixtures/strongbox.csv
rename to core/client/src/transfer/import/importers/strongbox/__tests__/strongbox.csv
diff --git a/core/client/src/transfer/import/importers/shared/ArchiveImport.ts b/core/client/src/transfer/import/readers/ArchiveImport.ts
similarity index 65%
rename from core/client/src/transfer/import/importers/shared/ArchiveImport.ts
rename to core/client/src/transfer/import/readers/ArchiveImport.ts
index 1f715ac58..6113e0e55 100644
--- a/core/client/src/transfer/import/importers/shared/ArchiveImport.ts
+++ b/core/client/src/transfer/import/readers/ArchiveImport.ts
@@ -1,10 +1,14 @@
-import { ZipArchive } from '../../../shared/ZipArchive';
-import { ImportException, ImportStage } from '../../models/ImportException';
-import { JsonException, parseJson } from '../../readers/JsonReader';
+import { FieldTypes, type FieldType } from '@aliasvault/models/vault';
-import type { ImportedCredential } from '../../models/ImportedCredential';
-import type { ImportFailure } from '../../models/ImportFailure';
-import type { ImportFileResult } from '../../models/ImportFileResult';
+import { isBlank } from '../../shared/StringUtils';
+import { ZipArchive } from '../../shared/ZipArchive';
+import { ImportException, ImportStage } from '../models/ImportException';
+
+import { JsonException, parseJson } from './JsonReader';
+
+import type { ImportedCredential } from '../models/ImportedCredential';
+import type { ImportFailure } from '../models/ImportFailure';
+import type { ImportFileResult } from '../models/ImportFileResult';
/**
* Open an uploaded ZIP archive.
@@ -93,3 +97,41 @@ export function buildItemFailure(index: number, title: string | null, error: unk
function errorMessage(error: unknown): string {
return error instanceof Error ? error.message : String(error);
}
+
+/**
+ * Add a user-defined field to a credential; empty labels or values are skipped.
+ * @param credential - The credential
+ * @param label - The field label
+ * @param value - The field value
+ * @param fieldType - The field type, Text by default
+ */
+export function addCustomField(credential: ImportedCredential, label: string | null | undefined, value: string | null | undefined, fieldType: FieldType = FieldTypes.Text): void {
+ if (isBlank(label) || isBlank(value)) {
+ return;
+ }
+
+ credential.CustomFieldValues ??= [];
+ credential.CustomFieldValues.push({
+ DefinitionId: crypto.randomUUID(),
+ Label: label,
+ Value: value,
+ FieldType: fieldType,
+ IsMultiValue: false,
+ IsHidden: fieldType === FieldTypes.Hidden || fieldType === FieldTypes.Password,
+ EnableHistory: false,
+ Weight: 0,
+ ValueWeight: 0,
+ ApplicableToTypes: null,
+ });
+}
+
+/**
+ * Add an attachment to a credential.
+ * @param credential - The credential
+ * @param filename - The file name
+ * @param data - The file data
+ */
+export function addAttachment(credential: ImportedCredential, filename: string, data: Uint8Array): void {
+ credential.Attachments ??= [];
+ credential.Attachments.push({ Filename: filename, Blob: data });
+}
diff --git a/core/client/src/transfer/import/readers/FieldParsers.ts b/core/client/src/transfer/import/readers/FieldParsers.ts
new file mode 100644
index 000000000..3f550cf44
--- /dev/null
+++ b/core/client/src/transfer/import/readers/FieldParsers.ts
@@ -0,0 +1,27 @@
+import { ItemTypes, type ItemType } from '@aliasvault/models/vault';
+
+import { isBlank } from '../../shared/StringUtils';
+
+/**
+ * Split a URL column that may hold several comma separated URLs.
+ * @param url - The URL text
+ * @returns The URLs, or null when there are none
+ */
+export function parseUrls(url: string | null | undefined): string[] | null {
+ const urls = (url ?? '').split(',').map(u => u.trim()).filter(u => u.length > 0);
+ return urls.length > 0 ? urls : null;
+}
+
+/**
+ * Map a source's item type name to an item type.
+ * @param value - The source's type name
+ * @param types - Lower case type names to item types
+ * @returns The item type, Login for unknown names, or null when the name is empty
+ */
+export function mapItemType(value: string | null | undefined, types: Readonly<Record<string, ItemType>>): ItemType | null {
+ if (isBlank(value)) {
+ return null;
+ }
+ const key = value.toLowerCase();
+ return Object.hasOwn(types, key) ? types[key] : ItemTypes.Login;
+}
diff --git a/core/client/src/transfer/import/readers/__tests__/ArchiveImport.test.ts b/core/client/src/transfer/import/readers/__tests__/ArchiveImport.test.ts
new file mode 100644
index 000000000..6d9bad349
--- /dev/null
+++ b/core/client/src/transfer/import/readers/__tests__/ArchiveImport.test.ts
@@ -0,0 +1,78 @@
+import { describe, expect, it } from 'vitest';
+
+import { createZipArchive, textToZipBytes } from '../../../shared/ZipArchive';
+import { importBitwardenZip } from '../../importers/bitwarden/BitwardenZipImporter';
+import { ImportException, ImportStage } from '../../models/ImportException';
+import { buildItemFailure } from '../ArchiveImport';
+import { JsonException } from '../JsonReader';
+
+import type { ImportFileResult } from '../../models/ImportFileResult';
+
+describe('ArchiveImport', () => {
+ it('reports a corrupt archive as an Archive stage failure', () => {
+ const corruptBytes = new TextEncoder().encode('definitely not a zip');
+
+ let caught: unknown;
+ try {
+ importBitwardenZip(corruptBytes);
+ } catch (error) {
+ caught = error;
+ }
+
+ expect(caught).toBeInstanceOf(ImportException);
+ expect((caught as ImportException).stage).toBe(ImportStage.Archive);
+ expect((caught as ImportException).message).toContain('not a valid ZIP archive');
+ });
+
+ it('reports a missing manifest as a Parse stage failure', () => {
+ const zipBytes = createZipArchive({});
+
+ let caught: unknown;
+ try {
+ importBitwardenZip(zipBytes);
+ } catch (error) {
+ caught = error;
+ }
+
+ expect(caught).toBeInstanceOf(ImportException);
+ expect((caught as ImportException).stage).toBe(ImportStage.Parse);
+ expect((caught as ImportException).message).toContain('data.json');
+ expect((caught as ImportException).message).toContain('not found');
+ });
+
+ it('reports malformed JSON with the parse error', () => {
+ const zipBytes = createZipArchive({ 'data.json': textToZipBytes('{"encrypted":false,"folders":[],"items":[{') });
+
+ let caught: unknown;
+ try {
+ importBitwardenZip(zipBytes);
+ } catch (error) {
+ caught = error;
+ }
+
+ expect(caught).toBeInstanceOf(ImportException);
+ expect((caught as ImportException).stage).toBe(ImportStage.Parse);
+ expect((caught as ImportException).message).toContain('data.json');
+ expect((caught as ImportException).message).toContain('Failed to parse');
+ expect((caught as ImportException).innerError).toBeInstanceOf(JsonException);
+ });
+
+ it('collects a malformed item as a per-item failure', () => {
+ const zipBytes = createZipArchive({ 'data.json': textToZipBytes('{"encrypted":false,"folders":[],"items":[{"name":"Broken","type":"not-a-number"},{"type":1,"name":"Fine","login":{"username":"u","password":"p"}}]}') });
+
+ const result: ImportFileResult = importBitwardenZip(zipBytes);
+
+ expect(result.Credentials).toHaveLength(1);
+ expect(result.Credentials[0].ServiceName).toBe('Fine');
+ expect(result.FailedItems).toHaveLength(1);
+ expect(result.FailedItems[0].Index).toBe(0);
+ expect(result.FailedItems[0].ItemTitle).toBe('Broken');
+ expect(result.FailedItems[0].ExceptionType).toBe('JsonException');
+ });
+
+ it('builds per-item failures the same way for every archive importer', () => {
+ const failure = buildItemFailure(3, 'Title', new JsonException('bad'));
+ expect(failure.ExceptionType).toBe('JsonException');
+ expect(failure.Message).toContain('bad');
+ });
+});
diff --git a/core/client/src/transfer/import/writers/__tests__/ItemConverter.test.ts b/core/client/src/transfer/import/writers/__tests__/ItemConverter.test.ts
new file mode 100644
index 000000000..a2811daa6
--- /dev/null
+++ b/core/client/src/transfer/import/writers/__tests__/ItemConverter.test.ts
@@ -0,0 +1,42 @@
+import { TOTP_DEFAULT_ALGORITHM, TOTP_DEFAULT_DIGITS, TOTP_DEFAULT_PERIOD } from '@aliasvault/models/vault';
+import { describe, expect, it } from 'vitest';
+
+import { itemByName } from '../../__tests__/testHelpers';
+import { convertToItems } from '../ItemConverter';
+
+import type { ImportedCredential } from '../../models/ImportedCredential';
+
+describe('convertToItems', () => {
+ it('keeps the TOTP parameters of an imported otpauth URI', () => {
+ const credentials: ImportedCredential[] = [
+ { ServiceName: 'Sha512Service', TwoFactorSecret: 'otpauth://totp/Sha512Service:[email protected]?secret=JBSWY3DPEHPK3PXP&issuer=Sha512Service&algorithm=SHA512&digits=8&period=60' },
+ { ServiceName: 'PlainService', TwoFactorSecret: 'JBSWY3DPEHPK3PXP' },
+ ];
+
+ const items = convertToItems(credentials);
+
+ const withParameters = itemByName(items, 'Sha512Service').TotpCodes[0];
+ const withDefaults = itemByName(items, 'PlainService').TotpCodes[0];
+ expect(withParameters.Algorithm).toBe('SHA512');
+ expect(withParameters.Digits).toBe(8);
+ expect(withParameters.Period).toBe(60);
+ expect(withDefaults.Algorithm).toBe(TOTP_DEFAULT_ALGORITHM);
+ expect(withDefaults.Digits).toBe(TOTP_DEFAULT_DIGITS);
+ expect(withDefaults.Period).toBe(TOTP_DEFAULT_PERIOD);
+ });
+
+ it('assigns folders when converting to items', () => {
+ const credentials: ImportedCredential[] = [
+ { ServiceName: 'Test Service', FolderPath: 'Work/Projects', Username: 'user1', Password: 'pass1' },
+ { ServiceName: 'Test Service 2', FolderPath: 'Personal', Username: 'user2', Password: 'pass2' },
+ { ServiceName: 'No Folder', Username: 'user3', Password: 'pass3' },
+ ];
+ const folderMapping = new Map([['Work/Projects', crypto.randomUUID()], ['Personal', crypto.randomUUID()]]);
+
+ const items = convertToItems(credentials, folderMapping);
+
+ expect(items[0].FolderId).toBe(folderMapping.get('Work/Projects'));
+ expect(items[1].FolderId).toBe(folderMapping.get('Personal'));
+ expect(items[2].FolderId).toBeNull();
+ });
+});
diff --git a/core/client/vitest.config.ts b/core/client/vitest.config.ts
index 7c090ca86..023cd93af 100644
--- a/core/client/vitest.config.ts
+++ b/core/client/vitest.config.ts
@@ -5,5 +5,6 @@ export default defineConfig({
environment: 'node',
include: ['src/**/*.test.ts'],
setupFiles: ['./vitest.setup.ts'],
+ fsModuleCache: true,
},
});