public void VerifyQueryStringFieldsAreMaskedCorrectly() { var apiLog = new ApiLog(); var cc = "4111111111111111"; var maskedCC = "411111******1111"; var query = "PARAM1= aa ¶mCC= " + cc + " ¶m2= aaa ¶m3= aaaaa "; var filter = new TextLogMaskingFilter(new QueryStringMaskingRule("queryField", new TextMaskingRule[] { new TextMaskingRule { Field = "param1", Mask = Masks.DefaultMask }, new TextMaskingRule { Field = "paramcc", Mask = Masks.CreditCardMask } })); apiLog.TrySetValue("queryField", query); apiLog.TrySetValue("queryFieldNotToBeMasked", query); var masked = filter.Apply(apiLog); var fields = masked.GetFields(); var maskedQueryField = fields.First(x => x.Key == "queryField").Value; var maskedQueryFieldNoToBeMasked = fields.First(x => x.Key == "queryFieldNotToBeMasked").Value; Assert.Equal("PARAM1=**¶mCC=" + maskedCC + "¶m2= aaa ¶m3= aaaaa ", maskedQueryField); Assert.Equal(query, maskedQueryFieldNoToBeMasked); }
public void VerifyWhenCustomMaskSpecified_FieldsAreMaskedCorrectly() { var apiLog = new ApiLog(); var filter = new DelegateFilter((ILog log) => { var copy = new List <KeyValuePair <string, object> >(); var fields = log.GetFields(); foreach (var field in fields) { if (field.Key == "fieldToMask") { copy.Add(new KeyValuePair <string, object>(field.Key, Masks.DefaultMask.Mask(field.Value.ToString()))); } else if (field.Key == "fieldNotToMask") { copy.Add(field); } } return(new SimpleLog(log.Id, log.LogTime, copy)); }); apiLog.TrySetValue("fieldToMask", "ValueToMask"); apiLog.TrySetValue("fieldNotToMask", "ValueNotToMask"); var masked = filter.Apply(apiLog); var maskedFields = masked.GetFields(); var maskedField = maskedFields.First(x => x.Key == "fieldToMask").Value; var notMaskedField = maskedFields.First(x => x.Key == "fieldNotToMask").Value; Assert.Equal(maskedField, "V*********k"); Assert.Equal(notMaskedField, "ValueNotToMask"); }
public void VerifyTextFieldsAreMaskedCorrectly() { var apiLog = new ApiLog(); var cc = "4111111111111111"; var maskedCC = "411111******1111"; var filter = new TextLogMaskingFilter(new List <TextMaskingRule> { new TextMaskingRule { Field = "textField", Mask = Masks.DefaultMask }, new TextMaskingRule { Field = "textFieldCC", Mask = Masks.CreditCardMask } }); apiLog.TrySetValue("textField", "textFieldValue"); apiLog.TrySetValue("textFieldCC", cc); apiLog.TrySetValue("textFieldNotToBeMasked", "textFieldNotToBeMaskedValue"); var masked = filter.Apply(apiLog); var fields = masked.GetFields(); var maskedTextField = fields.First(x => x.Key == "textField").Value; var maskedTextFieldCC = fields.First(x => x.Key == "textFieldCC").Value; var maskedTextFieldNoToBeMasked = fields.First(x => x.Key == "textFieldNotToBeMasked").Value; Assert.Equal("t************e", maskedTextField); Assert.Equal(maskedCC, maskedTextFieldCC); Assert.Equal("textFieldNotToBeMaskedValue", maskedTextFieldNoToBeMasked); }
public void VerifyJSONFieldsAreMaskedCorrectly() { var apiLog = new ApiLog(); var cc = "4111111111111111"; var maskedCC = "411111******1111"; var filter = new StreamLogMaskingFilter(new List <JsonPayloadMaskingRule> { new JsonPayloadMaskingRule("jsonfield", new PayloadFieldMaskingRule [] { new PayloadFieldMaskingRule { Path = "param1" }, new PayloadFieldMaskingRule { Path = "param2" }, new PayloadFieldMaskingRule { Path = "param3" }, new PayloadFieldMaskingRule { Path = "param4.childParam" }, new PayloadFieldMaskingRule { Path = "param4.childParamCC", Mask = Masks.CreditCardMask } }) }); var json = string.Format(@"{{ ""PARAM1"": "" aa "", ""param2"": "" aaaa "", ""param3"": "" aaaaa "", ""param4"": {{ ""childParam"": ""ccccc"", ""childParamCC"": ""{0}"" }} }}", cc); apiLog.TrySetValue("jsonField", new Payload(json)); apiLog.TrySetValue("jsonFieldNotToBeMasked", new Payload(json)); var masked = filter.Apply(apiLog); var fields = masked.GetFields(); var maskedJsonField = (fields.First(x => x.Key == "jsonField").Value as Payload).GetString(); var maskedJsonFieldNoToBeMasked = (fields.First(x => x.Key == "jsonFieldNotToBeMasked").Value as Payload).GetString(); Assert.Equal(string.Format(Regex.Replace(@"{{ ""PARAM1"": ""**"", ""param2"": ""a***"", ""param3"": ""a***a"", ""param4"": {{ ""childParam"": ""c***c"", ""childParamCC"": ""{0}"" }} }}", @"\s|\t|\n|\r", ""), maskedCC), maskedJsonField); Assert.Equal(json, maskedJsonFieldNoToBeMasked); }
public void VerifyWhenMaskingFieldAsPayloadFails_ValueIsSetToDefaultMaskingFailureValue() { var apiLog = new ApiLog(); var filter = new StreamLogMaskingFilter(new List <JsonPayloadMaskingRule> { new JsonPayloadMaskingRule("jsonfield", new PayloadFieldMaskingRule [] { new PayloadFieldMaskingRule { Path = "param1", Mask = new FuncMask(new Func <string, string>((string value) => { throw new Exception("MaskingFailed"); })) } }) }); var json = string.Format(@"{{ ""PARAM1"": "" aa "" }}"); apiLog.TrySetValue("jsonField", new Payload(json)); var masked = filter.Apply(apiLog); var fields = masked.GetFields(); var maskedJsonField = fields.First(x => x.Key == "jsonField").Value.ToString(); Assert.Equal(KeyStore.Masking.MaskingFailed, maskedJsonField); Assert.True(Boolean.Parse(fields.First(x => x.Key == KeyStore.Masking.MaskingFailedKey).Value.ToString())); }
public void VerifyWhenMaskingFieldAsTextFails_ValueIsSetToDefaultMaskingFailureValue() { var apiLog = new ApiLog(); var filter = new TextLogMaskingFilter(new List <TextMaskingRule> { new TextMaskingRule { Field = "textField", Mask = new FuncMask(new Func <string, string>((string value) => { throw new Exception("MaskingFailed"); })) } }); apiLog.TrySetValue("textField", "textFieldValue"); var masked = filter.Apply(apiLog); var fields = masked.GetFields(); var maskedTextField = fields.First(x => x.Key == "textField").Value; Assert.Equal(maskedTextField, KeyStore.Masking.MaskingFailed); Assert.True(Boolean.Parse(fields.First(x => x.Key == KeyStore.Masking.MaskingFailedKey).Value.ToString())); }
public void VerifyXmlFieldsAreMaskedCorrectly() { var apiLog = new ApiLog(); var cc = "4111111111111111"; var maskedCC = "411111******1111"; var filter = new StreamLogMaskingFilter(new List <PayloadMaskingRule> { new XmlPayloadMaskingRule("xmlField", new Dictionary <string, string> { { "oski", "http://oski.io/my_custom_ns" } }, new PayloadFieldMaskingRule[] { new PayloadFieldMaskingRule { Path = "/root/node1/node1Child1/@node1Child1Attr" }, new PayloadFieldMaskingRule { Path = "/root/node1/node1Child1/text()" }, new PayloadFieldMaskingRule { Path = "/root/node1/node1Child2/text()" }, new PayloadFieldMaskingRule { Path = "/root/node1/node1Child3/text()" }, new PayloadFieldMaskingRule { Path = "/root/oski:node2/text()" }, new PayloadFieldMaskingRule { Path = "/root/nodeCC/text()", Mask = Masks.CreditCardMask } }) }); var xml = string.Format(@"<?xml version=""1.0"" encoding=""utf-8""?> <root> <node1> <node1Child1 node1Child1Attr="" attr_value ""> ab </node1Child1> <node1Child2> abcd </node1Child2> <node1Child3> abcde </node1Child3> </node1> <node2 xmlns=""http://oski.io/my_custom_ns"">uvwxyz</node2> <nodeCC>{0}</nodeCC> <node3>pqrst</node3> </root>", cc); apiLog.TrySetValue("xmlField", new Payload(xml)); apiLog.TrySetValue("xmlFieldNotToBeMasked", new Payload(xml)); var masked = filter.Apply(apiLog); var fields = masked.GetFields(); var maskedXmlField = (fields.First(x => x.Key == "xmlField").Value as Payload).GetString(); var maskedXmlFieldNoToBeMasked = (fields.First(x => x.Key == "xmlFieldNotToBeMasked").Value as Payload).GetString(); Assert.Equal(string.Format(Regex.Replace(Regex.Replace(@"<?xml version=""1.0"" encoding=""utf-8""?> <root> <node1> <node1Child1 node1Child1Attr=""a********e"">**</node1Child1> <node1Child2>a***</node1Child2> <node1Child3>a***e</node1Child3> </node1> <node2 xmlns=""http://oski.io/my_custom_ns"">u****z</node2> <nodeCC>{0}</nodeCC> <node3>pqrst</node3> </root>", @"\t|\n|\r", ""), @">\s*<", "><"), maskedCC), maskedXmlField); Assert.Equal(maskedXmlFieldNoToBeMasked, xml); }