-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e16b912
commit 8ed5d30
Showing
2 changed files
with
38 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,11 +12,13 @@ namespace WebJobs.Extensions.DurableTask.Tests.V2 | |
public class EndToEndTraceHelperTests | ||
{ | ||
[Theory] | ||
[InlineData(true, true)] | ||
[InlineData(false, true)] | ||
[InlineData(true, false)] | ||
[InlineData(false, false)] | ||
public void StringSanitizerTest(bool shouldTraceRawData, bool testNullInput) | ||
[InlineData(true, "DO NOT LOG ME")] | ||
[InlineData(false, "DO NOT LOG ME")] | ||
[InlineData(true, null)] | ||
[InlineData(false, null)] | ||
public void StringSanitizerTest( | ||
bool shouldTraceRawData, | ||
string? possiblySensitiveData) | ||
{ | ||
// set up trace helper | ||
var nullLogger = new NullLogger<EndToEndTraceHelper>(); | ||
|
@@ -25,30 +27,23 @@ public void StringSanitizerTest(bool shouldTraceRawData, bool testNullInput) | |
traceReplayEvents: false, // has not effect on sanitizer | ||
shouldTraceRawData: shouldTraceRawData); | ||
|
||
// prepare sensitive data to sanitize | ||
string possibleSensitiveData = "DO NOT LOG ME"; | ||
|
||
// run sanitizer | ||
traceHelper.SanitizeString( | ||
rawPayload: testNullInput ? null : possibleSensitiveData, | ||
rawPayload: possiblySensitiveData, | ||
out string iLoggerString, | ||
out string kustoTableString); | ||
|
||
// expected: sanitized string should not contain the sensitive data | ||
Assert.DoesNotContain(possibleSensitiveData, kustoTableString); | ||
// skip this check if data is null | ||
if (possiblySensitiveData != null) | ||
{ | ||
Assert.DoesNotContain(possiblySensitiveData, kustoTableString); | ||
} | ||
|
||
if (shouldTraceRawData) | ||
{ | ||
if (testNullInput) | ||
{ | ||
// If provided input is null, it is logged as "(null)" | ||
Assert.Equal("(null)", iLoggerString); | ||
} | ||
else | ||
{ | ||
// Otherwise, we expect to see the data as-is | ||
Assert.Equal(possibleSensitiveData, iLoggerString); | ||
} | ||
string expectedString = possiblySensitiveData ?? string.Empty; | ||
Assert.Equal(expectedString, iLoggerString); | ||
} | ||
else | ||
{ | ||
|
@@ -60,11 +55,13 @@ public void StringSanitizerTest(bool shouldTraceRawData, bool testNullInput) | |
|
||
Check warning on line 55 in test/FunctionsV2/EndToEndTraceHelperTests.cs GitHub Actions / build
Check warning on line 55 in test/FunctionsV2/EndToEndTraceHelperTests.cs GitHub Actions / build
Check warning on line 55 in test/FunctionsV2/EndToEndTraceHelperTests.cs GitHub Actions / build
|
||
|
||
[Theory] | ||
[InlineData(true, true)] | ||
[InlineData(false, true)] | ||
[InlineData(true, false)] | ||
[InlineData(false, false)] | ||
public void ExceptionSanitizerTest(bool shouldTraceRawData, bool testNullInput) | ||
[InlineData(true, "DO NOT LOG ME")] | ||
[InlineData(false, "DO NOT LOG ME")] | ||
[InlineData(true, null)] | ||
[InlineData(false, null)] | ||
public void ExceptionSanitizerTest( | ||
bool shouldTraceRawData, | ||
string? possiblySensitiveData) | ||
{ | ||
// set up trace helper | ||
var nullLogger = new NullLogger<EndToEndTraceHelper>(); | ||
|
@@ -74,25 +71,34 @@ public void ExceptionSanitizerTest(bool shouldTraceRawData, bool testNullInput) | |
shouldTraceRawData: shouldTraceRawData); | ||
|
||
// exception to sanitize | ||
var possiblySensitiveData = "DO NOT LOG ME"; | ||
var exception = new Exception(possiblySensitiveData); | ||
Exception? exception = null; | ||
if (possiblySensitiveData != null) | ||
{ | ||
exception = new Exception(possiblySensitiveData); | ||
} | ||
|
||
// run sanitizer | ||
traceHelper.SanitizeException( | ||
exception: testNullInput ? null : exception, | ||
exception: exception, | ||
out string iLoggerString, | ||
out string kustoTableString); | ||
|
||
// exception message should not be part of the sanitized strings | ||
Assert.DoesNotContain(possiblySensitiveData, kustoTableString); | ||
// skip this check if data is null | ||
if (possiblySensitiveData != null) | ||
{ | ||
Assert.DoesNotContain(possiblySensitiveData, kustoTableString); | ||
} | ||
|
||
if (shouldTraceRawData) | ||
{ | ||
var expectedString = testNullInput ? string.Empty : exception.ToString(); | ||
var expectedString = exception?.ToString() ?? string.Empty; | ||
Assert.Equal(expectedString, iLoggerString); | ||
} | ||
else | ||
{ | ||
// If raw data is not being traced, | ||
// kusto and the ilogger should get the same data | ||
Assert.Equal(iLoggerString, kustoTableString); | ||
} | ||
} | ||
|