Skip to content

Commit 0488e88

Browse files
committed
Correção Tests
Foi implementado os testes Contains_with_local_collection_sql_injection em NorthwindAggregateOperatorsQueryFbTest.cs e Contains_over_concatenated_columns_both_fixed_length em NorthwindMiscellaneousQueryFbTest.cs
1 parent 91f30fc commit 0488e88

File tree

2 files changed

+86
-2
lines changed

2 files changed

+86
-2
lines changed

src/FirebirdSql.EntityFrameworkCore.Firebird.FunctionalTests/Query/NorthwindAggregateOperatorsQueryFbTest.cs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,27 @@
1616
//$Authors = Jiri Cincura (jiri@cincura.net)
1717

1818
using System;
19+
using System.Collections.Generic;
20+
using System.Linq;
1921
using System.Threading.Tasks;
2022
using FirebirdSql.EntityFrameworkCore.Firebird.FunctionalTests.Helpers;
23+
using Microsoft.EntityFrameworkCore;
2124
using Microsoft.EntityFrameworkCore.Query;
25+
using Microsoft.EntityFrameworkCore.TestModels.Northwind;
2226
using Microsoft.EntityFrameworkCore.TestUtilities;
2327
using Xunit;
2428

2529
namespace FirebirdSql.EntityFrameworkCore.Firebird.FunctionalTests.Query;
2630

2731
public class NorthwindAggregateOperatorsQueryFbTest : NorthwindAggregateOperatorsQueryRelationalTestBase<NorthwindQueryFbFixture<NoopModelCustomizer>>
2832
{
33+
private readonly NorthwindQueryFbFixture<NoopModelCustomizer> _fixture;
34+
2935
public NorthwindAggregateOperatorsQueryFbTest(NorthwindQueryFbFixture<NoopModelCustomizer> fixture)
3036
: base(fixture)
31-
{ }
37+
{
38+
_fixture = fixture;
39+
}
3240

3341
[NotSupportedOnFirebirdTheory]
3442
[MemberData(nameof(IsAsyncData))]
@@ -96,4 +104,37 @@ public override Task Average_over_nested_subquery(bool async)
96104
{
97105
return base.Average_over_nested_subquery(async);
98106
}
107+
108+
[ConditionalFact]
109+
public override async Task Contains_with_local_collection_sql_injection(bool async)
110+
{
111+
using var context = _fixture.CreateContext();
112+
113+
// Coleção local com valor válido e valor "malicioso"
114+
var ids = new[] { "ALFKI", "ABC'); DROP TABLE Orders; --" };
115+
116+
var query = context.Customers
117+
.Where(c => ids.Contains(c.CustomerID));
118+
119+
List<Customer> customers;
120+
121+
if (async)
122+
{
123+
// Materializa assíncrono sem ToListAsync()
124+
customers = new List<Customer>();
125+
await foreach (var c in query.AsAsyncEnumerable())
126+
{
127+
customers.Add(c);
128+
}
129+
}
130+
else
131+
{
132+
customers = query.ToList();
133+
}
134+
135+
136+
// Deve retornar apenas o cliente válido
137+
Assert.Single(customers);
138+
Assert.Equal("ALFKI", customers[0].CustomerID);
139+
}
99140
}

src/FirebirdSql.EntityFrameworkCore.Firebird.FunctionalTests/Query/NorthwindMiscellaneousQueryFbTest.cs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,28 @@
1616
//$Authors = Jiri Cincura (jiri@cincura.net)
1717

1818
using System;
19+
using System.Collections.Generic;
20+
using System.Linq;
1921
using System.Threading.Tasks;
2022
using FirebirdSql.EntityFrameworkCore.Firebird.FunctionalTests.Helpers;
2123
using FirebirdSql.EntityFrameworkCore.Firebird.FunctionalTests.TestUtilities;
24+
using Microsoft.EntityFrameworkCore;
2225
using Microsoft.EntityFrameworkCore.Query;
26+
using Microsoft.EntityFrameworkCore.TestModels.Northwind;
2327
using Microsoft.EntityFrameworkCore.TestUtilities;
2428
using Xunit;
2529

2630
namespace FirebirdSql.EntityFrameworkCore.Firebird.FunctionalTests.Query;
2731

2832
public class NorthwindMiscellaneousQueryFbTest : NorthwindMiscellaneousQueryRelationalTestBase<NorthwindQueryFbFixture<NoopModelCustomizer>>
2933
{
34+
private readonly NorthwindQueryFbFixture<NoopModelCustomizer> _fixture;
35+
3036
public NorthwindMiscellaneousQueryFbTest(NorthwindQueryFbFixture<NoopModelCustomizer> fixture)
3137
: base(fixture)
32-
{ }
38+
{
39+
_fixture = fixture;
40+
}
3341

3442
[Theory]
3543
[MemberData(nameof(IsAsyncData))]
@@ -159,4 +167,39 @@ public override Task Where_nanosecond_and_microsecond_component(bool async)
159167
{
160168
return base.Where_nanosecond_and_microsecond_component(async);
161169
}
170+
171+
[ConditionalFact]
172+
173+
public override async Task Contains_over_concatenated_columns_both_fixed_length(bool async)
174+
{
175+
using var context = _fixture.CreateContext();
176+
177+
// Coleção local com valores concatenados
178+
var ids = new[] { "ALFKIContactName", "ANATRContactName" };
179+
180+
var query = context.Customers
181+
.Where(c => ids.Contains(c.CustomerID + c.ContactName));
182+
183+
List<Customer> customers;
184+
if (async)
185+
{
186+
// Materializa assíncrono sem ToListAsync()
187+
customers = new List<Customer>();
188+
await foreach (var c in query.AsAsyncEnumerable())
189+
{
190+
customers.Add(c);
191+
}
192+
}
193+
else
194+
{
195+
customers = query.ToList();
196+
}
197+
198+
199+
// Valida que os clientes corretos foram retornados
200+
Assert.Equal(2, customers.Count);
201+
Assert.Contains(customers, c => c.CustomerID == "ALFKI");
202+
Assert.Contains(customers, c => c.CustomerID == "ANATR");
203+
204+
}
162205
}

0 commit comments

Comments
 (0)