[InlineData("<xml></xml>")] // xml public void OnErrorRedactIsNone(string json) { var redactor = new JsonRedactor(new RedactorOptions { OnErrorRedact = OnErrorRedact.None }); var result = redactor.Redact(json); Assert.Equal(json, result); }
[InlineData("<xml></xml>")] // xml public void OnErrorRedactIsAll(string json) { var redactor = new JsonRedactor(new RedactorOptions { OnErrorRedact = OnErrorRedact.All }); var result = redactor.Redact(json); Assert.Equal(RedactorOptions.DefaultMask, result); }
public void FormattingIs(JsonRedactorFormatting formatting, string expectedResult) { var redactor = new JsonRedactor(new JsonRedactorOptions { Redacts = new[] { "a" }, Formatting = formatting }); var result = redactor.Redact(BasicJsonExample); Assert.Equal(expectedResult, result); }
public void ComplexTypeHandlingIs(ComplexTypeHandling complexTypeHandling, string expectedResult) { var redactor = new JsonRedactor(new RedactorOptions { ComplexTypeHandling = complexTypeHandling, Redacts = new[] { "d", "i" } }); var result = redactor.Redact(ComplexJsonExample); Assert.Equal(expectedResult, result); }
[InlineData("[" + BasicJsonExample + "]", "[{\"a\":\"[REDACTED]\",\"b\":2}]")] // json array public void StringComparisonIsOrdinalIgnoreCase(string json, string expectedResult) { var redactor = new JsonRedactor(new RedactorOptions { Redacts = new[] { "A" }, StringComparison = StringComparison.OrdinalIgnoreCase }); var result = redactor.Redact(json); Assert.Equal(expectedResult, result); }
[InlineData("X\\Y", "{\"a\":\"X\\\\Y\",\"b\":2}")] // contains backslash public void MaskIs(string mask, string expectedResult) { var redactor = new JsonRedactor(new JsonRedactorOptions { Mask = mask, Redacts = new[] { "a" }, }); var result = redactor.Redact(BasicJsonExample); Assert.Equal(expectedResult, result); }
public void RealWorldExample() { var json = JsonConvert.SerializeObject(SampleData.UserBillingHistory); var redacts = new[] { "password", "passwordHistory", "socialSecurityNumber", }; var ifIsRedacts = new[] { new IfIsRedact { If = "type", Is = "check", Redact = "checkNumber" }, new IfIsRedact { If = "type", Is = "creditCard", Redact = "creditCardData" }, }; var expectedValueRedactions = new[] { // using "" for string @"""P@ssw0rd5""", // password @"""P@ssw0rd1""", @"""P@ssw0rd2""", @"""P@ssw0rd3""", // passwordHistory @"1234567890", // socialSecurityNumber @"""2468""", // checkNumber @"""Visa""", @"""4111111111111111""", @"""04/25""", @"""258""", @"false", // creditCardData }; var redactor = new JsonRedactor(new RedactorOptions { ComplexTypeHandling = ComplexTypeHandling.RedactDescendants, Redacts = redacts, IfIsRedacts = ifIsRedacts }); var result = redactor.Redact(json); var jsonMask = $@"""{RedactorOptions.DefaultMask}"""; var expectedResult = json; foreach (var expectedValueRedaction in expectedValueRedactions) { expectedResult = expectedResult.Replace(expectedValueRedaction, jsonMask); } Assert.Equal(expectedResult, result); }