From 752c9f967c38f355e0f336eadba8913fc43ee3c9 Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Wed, 24 Jan 2024 15:24:57 +0100 Subject: [PATCH] Test strange IDs and minor fix to handle APP ID. --- .../ShardedSnapshotStore.cs | 2 +- .../TestSuite.ApiTests/ContentUpdateTests.cs | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/ShardedSnapshotStore.cs b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/ShardedSnapshotStore.cs index 398ac08b0f..fbbe1c2d9f 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/ShardedSnapshotStore.cs +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/ShardedSnapshotStore.cs @@ -91,7 +91,7 @@ private static DomainId GetAppId(DomainId key) // This is a leaky abstraction, but the only option to implement that in a fast way. var parts = key.ToString().Split(DomainId.IdSeparator); - if (parts.Length != 2) + if (parts.Length < 2) { throw new InvalidOperationException("The key does not contain an app id."); } diff --git a/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs b/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs index 46afeaa4a2..3c7f059850 100644 --- a/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs +++ b/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs @@ -330,6 +330,28 @@ public async Task Should_create_content_with_custom_id_and_upsert() Assert.Equal(3, content.Data.Number); } + [Theory] + [InlineData("e5f7c399-6024-4367-9538-b7de4bced0f9' UNION ALL SELECT NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL-- vIGQ")] + [InlineData("e5f7c399-6024-4367-9538-b7de4bced0f9') UNION ALL SELECT 59,59,59,'qkjvq'||'FWUHnOHbQqCmewsQoKRPxqUXmHZMTtqHmyYoRhwu'||'qvpkq',59-- dLuxn")] + public async Task Should_create_and_delete_content_with_strange_id(string id) + { + // STEP 1: Upsert a new item with a custom id. + var content_0 = await _.Contents.UpsertAsync(id, new TestEntityData(), ContentUpsertOptions.AsPublish); + + Assert.Equal(id, content_0.Id); + + // STEP 2: Find content + var content_1 = await _.Contents.GetAsync(id); + + Assert.Equal(id, content_1.Id); + + + // STEP 3: Delete content. + await _.Contents.DeleteAsync(id); + + await Assert.ThrowsAnyAsync(() => _.Contents.GetAsync(id)); + } + [Theory] [InlineData(ContentStrategies.Update.Normal)] [InlineData(ContentStrategies.Update.Upsert)]