public void OnErrorRedactIsNone(string description, string xml) { var redactor = new XmlRedactor(new RedactorOptions { OnErrorRedact = OnErrorRedact.None }); var result = redactor.Redact(xml); Assert.Equal(xml, result); }
public void OnErrorRedactIsAll(string description, string xml) { var redactor = new XmlRedactor(new RedactorOptions { OnErrorRedact = OnErrorRedact.All }); var result = redactor.Redact(xml); Assert.Equal(RedactorOptions.DefaultMask, result); }
public void FormattingIs(XmlRedactorFormatting formatting, string expectedResult) { var redactor = new XmlRedactor(new XmlRedactorOptions { Redacts = new[] { "a" }, Formatting = formatting }); var result = redactor.Redact(BasicXmlExample); Assert.Equal(expectedResult, result); }
public void ComplexTypeHandlingIs(ComplexTypeHandling complexTypeHandling, string expectedResult) { var redactor = new XmlRedactor(new XmlRedactorOptions { ComplexTypeHandling = complexTypeHandling, Redacts = new[] { "d" } }); var result = redactor.Redact(ComplexXmlExample); Assert.Equal(expectedResult, result); }
public void StringComparisonIsOrdinalIgnoreCase(string description, string xml, string expectedResult) { var redactor = new XmlRedactor(new RedactorOptions { Redacts = new[] { "A", "A@B" }, StringComparison = StringComparison.OrdinalIgnoreCase }); var result = redactor.Redact(xml); Assert.Equal(expectedResult, result); }
public void StringComparisonIsOrdinal(string description, string xml, string _) { var redactor = new XmlRedactor(new RedactorOptions { Redacts = new[] { "A", "A@B" }, StringComparison = StringComparison.Ordinal }); var result = redactor.Redact(xml); Assert.Equal(xml, result); }
public void MaskIs(string description, string mask, string expectedResult) { var redactor = new XmlRedactor(new XmlRedactorOptions { Redacts = new[] { "a", "b@c" }, Mask = mask }); var result = redactor.Redact(BasicXmlExample); Assert.Equal(expectedResult, result); }
public void RedactSampleData() { var json = $"{{root:{JsonConvert.SerializeObject(SampleData.UserBillingHistory)}}}"; var xml = JsonConvert.DeserializeXNode(json).ToString(SaveOptions.DisableFormatting); 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 XmlRedactor(new RedactorOptions { ComplexTypeHandling = ComplexTypeHandling.RedactDescendants, Redacts = redacts, IfIsRedacts = ifIsRedacts }); var result = redactor.Redact(xml); var xmlMask = RedactorOptions.DefaultMask; var expectedResult = xml; foreach (var expectedValueRedaction in expectedValueRedactions) { expectedResult = expectedResult.Replace(expectedValueRedaction, xmlMask); } Assert.Equal(expectedResult, result); }