Skip to content

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

Update history modal tests

Leendert de Borst969446a2b4a9
diff --git a/apps/browser-extension/tests/e2e/90-vault-upgrade.spec.ts b/apps/browser-extension/tests/e2e/90-vault-upgrade.spec.ts
index 2ea847e7e..3139c569b 100644
--- a/apps/browser-extension/tests/e2e/90-vault-upgrade.spec.ts
+++ b/apps/browser-extension/tests/e2e/90-vault-upgrade.spec.ts
@@ -112,10 +112,14 @@ async function expectLegacyItemContent(client: TestClient, item: LegacyVaultItem
if (item.passwordHistory) {
await main.getByRole('button', { name: 'View history' }).click();
const history = popup.locator('input[id^="history-"]');
- await expect(history).toHaveCount(item.passwordHistory.length);
- // Newest first.
+ // Newest first, without the newest record when it holds the current password.
+ const expectedHistory = [...item.passwordHistory].reverse();
+ if (expectedHistory[0] === item.fields.find(field => field.key === 'login.password')?.value) {
+ expectedHistory.shift();
+ }
+ await expect(history).toHaveCount(expectedHistory.length);
const shown = await history.evaluateAll(inputs => inputs.map(input => (input as HTMLInputElement).value));
- expect(shown).toEqual([...item.passwordHistory].reverse());
+ expect(shown).toEqual(expectedHistory);
await popup.getByRole('button', { name: 'Close', exact: true }).click();
await expect(history).toHaveCount(0);
}
diff --git a/apps/web/tests/e2e/90-vault-upgrade.spec.ts b/apps/web/tests/e2e/90-vault-upgrade.spec.ts
index a9bb9a352..858029875 100644
--- a/apps/web/tests/e2e/90-vault-upgrade.spec.ts
+++ b/apps/web/tests/e2e/90-vault-upgrade.spec.ts
@@ -140,10 +140,14 @@ async function expectLegacyItemContent(app: WebApp, item: LegacyVaultItem): Prom
if (item.passwordHistory) {
await main.getByRole('button', { name: 'View history' }).click();
const history = page.locator('#fieldHistoryModal');
- await expect(history.locator('input')).toHaveCount(item.passwordHistory.length);
- // Newest first.
+ // Newest first, without the newest record when it holds the current password.
+ const expectedHistory = [...item.passwordHistory].reverse();
+ if (expectedHistory[0] === item.fields.find(field => field.key === 'login.password')?.value) {
+ expectedHistory.shift();
+ }
+ await expect(history.locator('input')).toHaveCount(expectedHistory.length);
const shown = await history.locator('input').evaluateAll(inputs => inputs.map(input => (input as HTMLInputElement).value));
- expect(shown).toEqual([...item.passwordHistory].reverse());
+ expect(shown).toEqual(expectedHistory);
await history.getByRole('button', { name: 'Close' }).click();
await expect(history).toHaveCount(0);
}
diff --git a/core/rust/src/vault_sync/engine.rs b/core/rust/src/vault_sync/engine.rs
index 0d66ac258..264ec8eb4 100644
--- a/core/rust/src/vault_sync/engine.rs
+++ b/core/rust/src/vault_sync/engine.rs
@@ -389,6 +389,9 @@ async fn commit_pulled_vault(ctx: &mut Ctx, pulled: &PulledVault) -> SyncResult<
let stored = ctx.store_vault(&pulled.encrypted_vault, pulled.needs_first_write, Some(ctx.mutation_sequence), Some(pulled.personal_revision)).await?;
if !stored.success {
ctx.log("[Sync] Mutation detected during sync, re-syncing...").await;
+ ctx.is_dirty = true;
+ ctx.mutation_sequence = stored.mutation_sequence;
+ ctx.request.dirty_scopes.clear();
return Ok(Some(Flow::Resync { outdated: false }));
}
if pulled.needs_first_write {
diff --git a/core/rust/src/vault_sync/tests/sync.rs b/core/rust/src/vault_sync/tests/sync.rs
index 6457b5539..21a48b52d 100644
--- a/core/rust/src/vault_sync/tests/sync.rs
+++ b/core/rust/src/vault_sync/tests/sync.rs
@@ -324,6 +324,24 @@ fn outdated_bucket_only_push_merges_the_server_bucket_instead_of_overwriting_it(
s.server.borrow().assert_converged(&s.host);
}
+#[test]
+fn a_mutation_during_a_pull_is_merged_by_the_next_round_instead_of_refusing_every_store() {
+ let mut s = synced(|db| insert_item(db, ITEM_A, "Server item"));
+
+ // Another device adds an item, and this one saves an item while its sync pulls that change.
+ insert_item(&s.db, ITEM_C, "Other device item");
+ s.publish(8);
+ s.host.edit_before_next_sync_store = Some(Box::new(|db| insert_item(db, ITEM_B, "Local item")));
+
+ let result = s.host.sync();
+
+ assert_eq!(result["success"], true, "{}", result);
+ assert_eq!(s.host.item_names(), vec!["Local item", "Other device item", "Server item"]);
+ assert_eq!(s.host.vault_writes().len(), 1, "the merged vault is written once");
+ assert!(!s.host.is_dirty, "the raced change reached the server");
+ s.server.borrow().assert_converged(&s.host);
+}
+
#[test]
fn a_write_the_server_keeps_refusing_gives_up_after_three_resyncs() {
let mut s = synced(|db| insert_item(db, ITEM_A, "Server item"));
diff --git a/core/rust/src/vault_sync/tests/test_host.rs b/core/rust/src/vault_sync/tests/test_host.rs
index a9a177938..a76b30d1f 100644
--- a/core/rust/src/vault_sync/tests/test_host.rs
+++ b/core/rust/src/vault_sync/tests/test_host.rs
@@ -42,6 +42,8 @@ pub struct TestHost {
pub requests: Vec<RecordedRequest>,
pub responders: Vec<Responder>,
pub logs: Vec<String>,
+ /// A local edit the app makes while a sync runs: applied right before the next sync store (one with an expected sequence).
+ pub edit_before_next_sync_store: Option<Box<dyn FnOnce(&Connection)>>,
}
/// The current client schema.
@@ -107,6 +109,7 @@ impl TestHost {
requests: Vec::new(),
responders: Vec::new(),
logs: Vec::new(),
+ edit_before_next_sync_store: None,
}
}
@@ -248,6 +251,11 @@ impl TestHost {
self.rekeyed_stores += 1;
self.vault_key = key;
}
+ if expected_mutation_seq.is_some() {
+ if let Some(change) = self.edit_before_next_sync_store.take() {
+ self.edit(change);
+ }
+ }
// Like the app hosts: a sync store is refused after a mutation, and either kind may mark the vault dirty.
if expected_mutation_seq.is_some_and(|expected| expected != self.mutation_sequence) {
json!({ "success": false, "mutationSequence": self.mutation_sequence })