Skip to content

Commit

Permalink
Fix null key and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
dudikeleti committed Feb 10, 2025
1 parent 8c1de94 commit d84d94d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
18 changes: 13 additions & 5 deletions tracer/src/Datadog.Trace/Debugger/Snapshots/Redaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ internal static bool IsRedactedType(Type? type)
return false;
}

var redactedType = _redactedTypesCache.GetOrAdd(type, CheckForRedactedType);
return redactedType;
}

private static bool CheckForRedactedType(Type type)
{
Type? genericDefinition = null;
if (type.IsGenericType)
{
Expand Down Expand Up @@ -271,20 +277,22 @@ internal static bool IsRedactedKeyword(string name)
return false;
}

return !TryNormalize(name, out var result) || RedactKeywords.Contains(result);
var redactedKeyword = _redactedKeywordsCache.GetOrAdd(
name,
n => !TryNormalize(n, out var result) || RedactKeywords.Contains(result));

return redactedKeyword;
}

internal static bool ShouldRedact(string name, Type type, out RedactionReason redactionReason)
{
var redactedKeyword = _redactedKeywordsCache.GetOrAdd(name, IsRedactedKeyword);
if (redactedKeyword)
if (IsRedactedKeyword(name))
{
redactionReason = RedactionReason.Identifier;
return true;
}

var redactedType = _redactedTypesCache.GetOrAdd(type, IsRedactedType);
if (redactedType)
if (IsRedactedType(type))
{
redactionReason = RedactionReason.Type;
return true;
Expand Down
3 changes: 2 additions & 1 deletion tracer/test/Datadog.Trace.Tests/Debugger/RedactionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ public void SetConfig_DuplicateEntries_Test()
}

[Theory]
[InlineData("password", typeof(System.Security.SecureString), RedactionReason.Type)]
[InlineData("", typeof(System.Security.SecureString), RedactionReason.Type)]
[InlineData("password", typeof(System.Security.SecureString), RedactionReason.Identifier)]
[InlineData("api_key", typeof(string), RedactionReason.Identifier)]
[InlineData("normal", typeof(string), RedactionReason.None)]
internal void ShouldRedact_CombinedScenarios_Test(string name, Type type, RedactionReason expectedReason)
Expand Down

0 comments on commit d84d94d

Please sign in to comment.