示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
        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);
        }
示例#8
0
        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);
        }