Skip to content

Commit 8e6d1c9

Browse files
committed
Add more tests
1 parent 15c9439 commit 8e6d1c9

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

tracer/test/Datadog.Trace.Security.IntegrationTests/IAST/IastInstrumentationUnitTests.cs

+15-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System.Net.Http;
1616
using System.Net.Mail;
1717
using System.Reflection;
18+
using System.Runtime.CompilerServices;
1819
using System.Runtime.InteropServices;
1920
using System.Security.Cryptography;
2021
using System.Text;
@@ -150,6 +151,9 @@ public List<string> GetAspects()
150151
[InlineData(typeof(SmtpClient), "Send", new[] { "Void Send(System.String, System.String, System.String, System.String)" }, true)]
151152
[InlineData(typeof(SmtpClient), "SendAsync", new[] { "Void SendAsync(System.String, System.String, System.String, System.String, System.Object)" }, true)]
152153
[InlineData(typeof(SmtpClient), "SendMailAsync", new[] { "System.Threading.Tasks.Task SendMailAsync(System.String, System.String, System.String, System.String, System.Threading.CancellationToken)", "System.Threading.Tasks.Task SendMailAsync(System.String, System.String, System.String, System.String)" }, true)]
154+
#if NET6_0_OR_GREATER
155+
[InlineData(typeof(DefaultInterpolatedStringHandler), null, new[] { "Void AppendFormatted(System.ReadOnlySpan`1[System.Char], Int32, System.String)" }, true)]
156+
#endif
153157
[Trait("Category", "EndToEnd")]
154158
[Trait("RunOnWindows", "True")]
155159
public void TestMethodsAspectCover(Type typeToCheck, string methodToCheck, string[] overloadsToExclude = null, bool excludeParameterlessMethods = false)
@@ -305,6 +309,9 @@ public void TestFileClassMethodsAspectCover()
305309
[InlineData(typeof(Assembly))]
306310
#endif
307311
[InlineData(typeof(Assembly), new string[] { "System.Reflection.Assembly::Load(System.String,System.Security.Policy.Evidence)" })]
312+
#if NET6_0_OR_GREATER
313+
[InlineData(typeof(DefaultInterpolatedStringHandler), null)]
314+
#endif
308315
[Trait("Category", "EndToEnd")]
309316
[Trait("RunOnWindows", "True")]
310317
public void TestAllAspectsHaveACorrespondingMethod(Type type, string[] aspectsToExclude = null)
@@ -389,7 +396,7 @@ private string NormalizeName(string signature)
389396

390397
return signature.Replace(" ", string.Empty).Replace("[T]", string.Empty).Replace("<!!0>", string.Empty)
391398
.Replace("[", "<").Replace("]", ">").Replace(",...", string.Empty).Replace("System.", string.Empty)
392-
.Replace("ByRef", string.Empty);
399+
.Replace("ByRef", string.Empty).Replace("!!0", "T");
393400
}
394401

395402
private bool MethodShouldBeChecked(MethodBase method)
@@ -445,7 +452,13 @@ private void TestMethodOverloads(Type typeToCheck, string methodToCheck, List<st
445452
Output.WriteLine("Checking: " + methodSignature);
446453
if (MethodShouldBeChecked(method) && overloadsToExcludeNormalized?.Contains(methodSignature) != true)
447454
{
448-
var isCovered = aspects.Any(x => NormalizeName(x).Contains(methodSignature) && x.Contains(typeToCheck.FullName));
455+
var isCovered = aspects.Any(x =>
456+
{
457+
var normalized = NormalizeName(x);
458+
var contains = normalized.Contains(methodSignature);
459+
var xcontains = x.Contains(typeToCheck.FullName);
460+
return contains && xcontains;
461+
});
449462
isCovered.Should().BeTrue(method.ToString() + " is not covered");
450463
}
451464
}

tracer/test/test-applications/integrations/Samples.InstrumentedTests/Vulnerabilities/String/DefaultInterpolatedStringHandlerTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,17 @@ public void GivenImplicitInterpolatedString_WhenAddingTaintedValuesNested_GetStr
245245
{
246246
const int number = 42;
247247
var date = new DateTime(2024, 11, 22, 15, 30, 0);
248-
const decimal decimalValue = 123.456m;
248+
const decimal decimalValue = 123;
249249
const bool booleanValue = true;
250250
const char charValue = 'A';
251251
var nestedInterpolatedString1 = $"Nested1 {TaintedValue} and {number}";
252252
var nestedInterpolatedString2 = $"Nested2 {nestedInterpolatedString1} with date {date:yyyy-MM-dd}";
253-
var complexString = $"Complex {nestedInterpolatedString2} and decimal {decimalValue:F2} and boolean {booleanValue}";
253+
var complexString = $"Complex {nestedInterpolatedString2} and decimal {decimalValue} and boolean {booleanValue}";
254254

255255
var nestedString = $"Hello {$"{TaintedValue + "Hello"} - {complexString}"}";
256256
var finalString = $"Final {nestedString} and char {charValue} with additional {UntaintedValue} and number {number} and date {date:HH:mm:ss}";
257257

258-
finalString.Should().Be("Final Hello Hello - Complex Nested2 Nested1 tainted and 42 with date 2024-11-22 and decimal 123.46 and boolean True and char A with additional untainted and number 42 and date 15:30:00");
258+
finalString.Should().Be("Final Hello taintedHello - Complex Nested2 Nested1 tainted and 42 with date 2024-11-22 and decimal 123 and boolean True and char A with additional untainted and number 42 and date 15:30:00");
259259
AssertTainted(finalString);
260260
}
261261

0 commit comments

Comments
 (0)