Skip to content

Commit 0344c96

Browse files
committed
Update test
1 parent 9c95aca commit 0344c96

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/NetAnalyzers/UnitTests/Microsoft.NetCore.Analyzers/Data/ReviewSQLQueriesForSecurityVulnerabilitiesTests_FlowAnalysis.cs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3349,7 +3349,9 @@ End Sub
33493349
[Fact]
33503350
public async Task FlowAnalysis_PointsTo_ReferenceType_BaseDerived_IfStatement_NoDiagnosticAsync()
33513351
{
3352-
await VerifyCS.VerifyAnalyzerAsync($@"
3352+
await new VerifyCS.Test
3353+
{
3354+
TestCode = $@"
33533355
{SetupCodeCSharp}
33543356
33553357
class Command1 : Command
@@ -3389,12 +3391,22 @@ void M1(string param)
33893391
}}
33903392
33913393
string str = t.B.Field; // t.B now points to either b or d, both of which have .Field = """"
3394+
// However, we are forced to be conservative in our analysis due to
3395+
// potential false positives from multiple variables pointing to the same set, i.e. b or d.
3396+
// See https://github.com/dotnet/roslyn-analyzers/issues/6520 for an example.
33923397
Command c = new Command1(str, str);
33933398
}}
3394-
}}
3395-
");
3399+
}}",
3400+
ExpectedDiagnostics =
3401+
{
3402+
// /0/Test0.cs(126,21): warning CA2100: Review if the query string passed to 'Command1.Command1(string cmd, string parameter2)' in 'M1', accepts any user input
3403+
GetCSharpResultAt(126, 21, "Command1.Command1(string cmd, string parameter2)", "M1"),
3404+
}
3405+
}.RunAsync();
33963406

3397-
await VerifyVB.VerifyAnalyzerAsync($@"
3407+
await new VerifyVB.Test
3408+
{
3409+
TestCode = $@"
33983410
{SetupCodeBasic}
33993411
34003412
Class Command1
@@ -3429,9 +3441,18 @@ Dim b As New Base()
34293441
t.B = b ' t.B now points to b
34303442
End If
34313443
Dim str As String = t.B.Field ' t.B now points to either b or d, both of which have .Field = """"
3444+
' However, we are forced to be conservative in our analysis due to
3445+
' potential false positives from multiple variables pointing to the same set, i.e. b or d.
3446+
' See https://github.com/dotnet/roslyn-analyzers/issues/6520 for an example.
34323447
Dim c As Command = New Command1(str, str)
34333448
End Sub
3434-
End Class");
3449+
End Class",
3450+
ExpectedDiagnostics =
3451+
{
3452+
// /0/Test0.vb(159,28): warning CA2100: Review if the query string passed to 'Sub Command1.New(cmd As String, parameter2 As String)' in 'M1', accepts any user input
3453+
GetBasicResultAt(159, 28, "Sub Command1.New(cmd As String, parameter2 As String)", "M1")
3454+
}
3455+
}.RunAsync();
34353456
}
34363457

34373458
[Trait(Traits.DataflowAnalysis, Traits.Dataflow.PointsToAnalysis)]

0 commit comments

Comments
 (0)