diff --git a/src/CoreTests/Partitioning/partitioning_configuration.cs b/src/CoreTests/Partitioning/partitioning_configuration.cs index bf0d91064a..823926e32b 100644 --- a/src/CoreTests/Partitioning/partitioning_configuration.cs +++ b/src/CoreTests/Partitioning/partitioning_configuration.cs @@ -1,5 +1,6 @@ using System.Linq; using System.Threading.Tasks; +using Marten; using Marten.Schema; using Marten.Schema.Indexing.Unique; using Marten.Storage; @@ -264,4 +265,52 @@ public async Task unique_index_on_partitioned_table_can_be_applied_to_database() // that don't include all partition columns await theStore.Storage.ApplyAllConfiguredChangesToDatabaseAsync(); } + + [Fact] + public async Task cannot_query_within_child_collections_across_partition_tenants() + { + StoreOptions(opts => + { + opts.Schema.For() + .MultiTenantedWithPartitioning(x => + { + x.ByHash(Enumerable.Range(0, 2).Select(i => $"h{i:000}").ToArray()); + }); + }); + var targetBlue1 = Target.Random(); + targetBlue1.NestedObject = new([Target.Random()]); + targetBlue1.NestedObject.Targets[0].String = "not a green list"; + await using (var blue = theStore.LightweightSession("Blue")) + { + blue.Store(targetBlue1); + await blue.SaveChangesAsync(); + } + + var targetRed1 = Target.Random(); + targetRed1.NestedObject = new([Target.Random()]); + targetRed1.NestedObject.Targets[0].String = "not a green list"; + await using(var blue = theStore.LightweightSession("Blue")) + { + blue.Store(targetRed1); + await blue.SaveChangesAsync(); + } + + await using (var red = theStore.QuerySession("Red")) + { + (await red.Query() + .Where(x => x.NestedObject.Targets.Any(i => i.String != null && i.String == "not a green list")) + .ToListAsync()) + .ShouldHaveSingleItem() + .Id.ShouldBe(targetRed1.Id); + } + + await using (var blue = theStore.QuerySession("Blue")) + { + (await blue.Query() + .Where(x => x.NestedObject.Targets.Any(i => i.String != null && i.String == "not a green list")) + .ToListAsync()) + .ShouldHaveSingleItem() + .Id.ShouldBe(targetBlue1.Id); + } + } } diff --git a/src/DocumentDbTests/MultiTenancy/conjoined_multi_tenancy_with_partitioning.cs b/src/DocumentDbTests/MultiTenancy/conjoined_multi_tenancy_with_partitioning.cs index f5e02fbda4..b264ed7835 100644 --- a/src/DocumentDbTests/MultiTenancy/conjoined_multi_tenancy_with_partitioning.cs +++ b/src/DocumentDbTests/MultiTenancy/conjoined_multi_tenancy_with_partitioning.cs @@ -1,8 +1,11 @@ using System; +using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using JasperFx; using Marten; +using Marten.Linq; using Marten.Schema; using Marten.Storage; using Marten.Testing; @@ -29,6 +32,10 @@ public class conjoined_multi_tenancy_with_partitioning: OneOffConfigurationsCont public conjoined_multi_tenancy_with_partitioning() { + targetBlue1.NestedObject = new([Target.Random()]); + targetBlue1.NestedObject.Targets[0].String = "not a green list"; + targetRed1.NestedObject = new([Target.Random()]); + targetRed1.NestedObject.Targets[0].String = "not a green list"; StoreOptions(opts => { opts.Policies.AllDocumentsAreMultiTenantedWithPartitioning(x => @@ -84,6 +91,28 @@ public async Task cannot_load_by_id_across_tenants() } } + [Fact] + public async Task cannot_query_within_child_collections_across_tenants() + { + await using (var red = theStore.QuerySession("Red")) + { + (await red.Query() + .Where(x => x.NestedObject.Targets.Any(i => i.String != null && i.String == "not a green list")) + .ToListAsync()) + .ShouldHaveSingleItem() + .Id.ShouldBe(targetRed1.Id); + } + + await using (var blue = theStore.QuerySession("Blue")) + { + (await blue.Query() + .Where(x => x.NestedObject.Targets.Any(i => i.String != null && i.String == "not a green list")) + .ToListAsync()) + .ShouldHaveSingleItem() + .Id.ShouldBe(targetBlue1.Id); + } + } + [Fact] public async Task cannot_load_json_by_id_across_tenants_async() {