Skip to content

Commit 3180d8f

Browse files
committed
C#: Add some source/sink examples where lifting is applied.
1 parent 64ac52e commit 3180d8f

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

csharp/ql/test/utils/modelgenerator/dataflow/CaptureSinkModels.ext.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ extensions:
44
extensible: sinkModel
55
data:
66
- [ "Sinks", "NewSinks", False, "Sink", "(System.Object)", "", "Argument[0]", "test-sink", "manual"]
7+
- [ "Sinks", "NewSinks", False, "Sink2", "(System.Object)", "", "Argument[0]", "test-sink2", "manual"]
78
- [ "Sinks", "NewSinks", False, "ManualSinkAlreadyDefined", "(System.Object)", "", "Argument[0]", "test-sink", "manual"]
89

910
- addsTo:

csharp/ql/test/utils/modelgenerator/dataflow/CaptureSourceModels.ext.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ extensions:
44
extensible: sourceModel
55
data:
66
- ["Sources", "NewSources", False, "ManualSourceAlreadyDefined", "()", "", "ReturnValue", "test-source", "manual"]
7+
- ["Sources", "NewSources", False, "Source1", "()", "", "ReturnValue", "source-kind-1", "manual"]
8+
- ["Sources", "NewSources", False, "Source2", "()", "", "ReturnValue", "source-kind-2", "manual"]
79

810
- addsTo:
911
pack: codeql/csharp-all

csharp/ql/test/utils/modelgenerator/dataflow/Sinks.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ public class NewSinks
1414

1515
// Sink defined in the extensible file next to the test.
1616
// neutral=Sinks;NewSinks;Sink;(System.Object);summary;df-generated
17-
public void Sink(object o) => throw null;
17+
public static void Sink(object o) => throw null;
18+
19+
// Sink defined in the extensible file next to the test.
20+
// neutral=Sinks;NewSinks;Sink2;(System.Object);summary;df-generated
21+
public static void Sink2(object o) => throw null;
1822

1923
// New sink
2024
// sink=Sinks;NewSinks;false;WrapResponseWrite;(System.Object);;Argument[0];html-injection;df-generated
@@ -105,6 +109,32 @@ public void ManualSinkAlreadyDefined(object o)
105109
{
106110
Sink(o);
107111
}
112+
113+
public abstract class DataWriter
114+
{
115+
// neutral=Sinks;NewSinks+DataWriter;Write;(System.Object);summary;df-generated
116+
public abstract void Write(object o);
117+
}
118+
119+
public class DataWriterKind1 : DataWriter
120+
{
121+
// sink=Sinks;NewSinks+DataWriter;true;Write;(System.Object);;Argument[0];test-sink;df-generated
122+
// neutral=Sinks;NewSinks+DataWriterKind1;Write;(System.Object);summary;df-generated
123+
public override void Write(object o)
124+
{
125+
Sink(o);
126+
}
127+
}
128+
129+
public class DataWriterKind2 : DataWriter
130+
{
131+
// sink=Sinks;NewSinks+DataWriter;true;Write;(System.Object);;Argument[0];test-sink2;df-generated
132+
// neutral=Sinks;NewSinks+DataWriterKind2;Write;(System.Object);summary;df-generated
133+
public override void Write(object o)
134+
{
135+
Sink2(o);
136+
}
137+
}
108138
}
109139

110140
public class CompoundSinks

csharp/ql/test/utils/modelgenerator/dataflow/Sources.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ namespace Sources;
44

55
public class NewSources
66
{
7+
// Defined as source in the extensions file next to the test.
8+
// neutral=Sources;NewSources;Source1;();summary;df-generated
9+
public static string Source1() => throw null;
10+
11+
// Defined as source in the extensions file next to the test.
12+
// neutral=Sources;NewSources;Source2;();summary;df-generated
13+
public static string Source2() => throw null;
14+
15+
716
// New source
817
// source=Sources;NewSources;false;WrapConsoleReadLine;();;ReturnValue;local;df-generated
918
// neutral=Sources;NewSources;WrapConsoleReadLine;();summary;df-generated
@@ -79,4 +88,30 @@ public string ManualSourceAlreadyDefined()
7988
{
8089
return Console.ReadLine();
8190
}
91+
92+
public abstract class DataReader
93+
{
94+
// neutral=Sources;NewSources+DataReader;Read;();summary;df-generated
95+
public abstract string Read();
96+
}
97+
98+
public class DataReaderKind1 : DataReader
99+
{
100+
// source=Sources;NewSources+DataReader;true;Read;();;ReturnValue;source-kind-1;df-generated
101+
// neutral=Sources;NewSources+DataReaderKind1;Read;();summary;df-generated
102+
public override string Read()
103+
{
104+
return Source1();
105+
}
106+
}
107+
108+
public class DataReaderKind2 : DataReader
109+
{
110+
// source=Sources;NewSources+DataReader;true;Read;();;ReturnValue;source-kind-2;df-generated
111+
// neutral=Sources;NewSources+DataReaderKind2;Read;();summary;df-generated
112+
public override string Read()
113+
{
114+
return Source2();
115+
}
116+
}
82117
}

0 commit comments

Comments
 (0)