diff --git a/src/Libraries/Microsoft.Extensions.Compliance.Redaction/RedactorProvider.cs b/src/Libraries/Microsoft.Extensions.Compliance.Redaction/RedactorProvider.cs index 0963784fa80..18a356d1a10 100644 --- a/src/Libraries/Microsoft.Extensions.Compliance.Redaction/RedactorProvider.cs +++ b/src/Libraries/Microsoft.Extensions.Compliance.Redaction/RedactorProvider.cs @@ -37,6 +37,12 @@ public Redactor GetRedactor(DataClassificationSet classifications) private static FrozenDictionary GetClassRedactorMap(IEnumerable redactors, Dictionary map) { + if (!map.ContainsKey(DataClassification.None)) + { + map.Add(DataClassification.None, typeof(NullRedactor)); + redactors = [.. redactors, NullRedactor.Instance]; + } + var dict = new Dictionary(map.Count); foreach (var m in map) { @@ -45,6 +51,7 @@ private static FrozenDictionary GetClassRedacto if (r.GetType() == m.Value) { dict[m.Key] = r; + break; } } } diff --git a/test/Libraries/Microsoft.Extensions.Compliance.Redaction.Tests/RedactorProviderTests.cs b/test/Libraries/Microsoft.Extensions.Compliance.Redaction.Tests/RedactorProviderTests.cs index 0a7c97f34f1..9a69e83be50 100644 --- a/test/Libraries/Microsoft.Extensions.Compliance.Redaction.Tests/RedactorProviderTests.cs +++ b/test/Libraries/Microsoft.Extensions.Compliance.Redaction.Tests/RedactorProviderTests.cs @@ -10,6 +10,16 @@ namespace Microsoft.Extensions.Compliance.Redaction.Test; public class RedactorProviderTests { + [Fact] + public void RedactorProvider_Returns_NullRedactor_For_NoneDataClassification() + { + var redactorProvider = new RedactorProvider( + redactors: [ErasingRedactor.Instance], + options: Microsoft.Extensions.Options.Options.Create(new RedactorProviderOptions())); + + Assert.IsType(redactorProvider.GetRedactor(DataClassification.None)); + } + [Fact] public void RedactorProvider_Returns_Redactor_For_Every_Data_Classification() { @@ -38,13 +48,15 @@ public void RedactorProvider_Returns_Redactor_For_Data_Classifications() redactors: new Redactor[] { ErasingRedactor.Instance, NullRedactor.Instance }, options: Microsoft.Extensions.Options.Options.Create(opt)); - var r1 = redactorProvider.GetRedactor(_dataClassification1); - var r2 = redactorProvider.GetRedactor(_dataClassification2); - var r3 = redactorProvider.GetRedactor(_dataClassification3); + Redactor r1 = redactorProvider.GetRedactor(_dataClassification1); + Redactor r2 = redactorProvider.GetRedactor(_dataClassification2); + Redactor r3 = redactorProvider.GetRedactor(_dataClassification3); + Redactor r4 = redactorProvider.GetRedactor(DataClassification.None); - Assert.Equal(typeof(ErasingRedactor), r1.GetType()); - Assert.Equal(typeof(NullRedactor), r2.GetType()); - Assert.Equal(typeof(ErasingRedactor), r3.GetType()); + Assert.IsType(r1); + Assert.IsType(r2); + Assert.IsType(r3); + Assert.IsType(r4); } [Fact]