From f66272cb88d4fe7d88300d6ec5d8ab53e0a97cca Mon Sep 17 00:00:00 2001 From: Dzejkop Date: Mon, 5 Aug 2024 21:24:44 +0200 Subject: [PATCH] Reintroduce uniqueness check --- .../database/014_reintroduce_root_uniqueness.down.sql | 5 +++++ schemas/database/014_reintroduce_root_uniqueness.up.sql | 3 +++ src/database/mod.rs | 9 ++++++--- 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 schemas/database/014_reintroduce_root_uniqueness.down.sql create mode 100644 schemas/database/014_reintroduce_root_uniqueness.up.sql diff --git a/schemas/database/014_reintroduce_root_uniqueness.down.sql b/schemas/database/014_reintroduce_root_uniqueness.down.sql new file mode 100644 index 00000000..aa59048e --- /dev/null +++ b/schemas/database/014_reintroduce_root_uniqueness.down.sql @@ -0,0 +1,5 @@ +-- Same as migration 011_drop_root_uniqueness.sql + +DROP INDEX identities_root_key; + +CREATE INDEX identities_root ON identities (root); diff --git a/schemas/database/014_reintroduce_root_uniqueness.up.sql b/schemas/database/014_reintroduce_root_uniqueness.up.sql new file mode 100644 index 00000000..9364a87d --- /dev/null +++ b/schemas/database/014_reintroduce_root_uniqueness.up.sql @@ -0,0 +1,3 @@ +DROP INDEX identities_root; + +CREATE UNIQUE INDEX identities_root_key ON identities (root); diff --git a/src/database/mod.rs b/src/database/mod.rs index 92de9212..61ee8cfa 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -1176,7 +1176,7 @@ mod test { } #[tokio::test] - async fn can_insert_same_root_multiple_times() -> anyhow::Result<()> { + async fn can_not_insert_same_root_multiple_times() -> anyhow::Result<()> { let docker = Cli::default(); let (db, _db_container) = setup_db(&docker).await?; let identities = mock_identities(2); @@ -1185,8 +1185,11 @@ mod test { db.insert_pending_identity(0, &identities[0], &roots[0]) .await?; - db.insert_pending_identity(1, &identities[1], &roots[0]) - .await?; + let res = db + .insert_pending_identity(1, &identities[1], &roots[0]) + .await; + + assert!(res.is_err(), "Inserting duplicate root should fail"); let root_state = db .get_root_state(&roots[0])