public void Should_be_able_to_apply_filter_using_delegatefilter() { var filter = new TextLogMaskingFilter(new TextMaskingRule() { Field = "txid", Mask = Masks.DefaultMask }); var delegateFilter = new DelegateFilter(filter.Apply); var id = Convert.ToString(Guid.NewGuid()); var apiLog = Utility.GetApiLog(); apiLog.Id = id; var filteredLog = delegateFilter.Apply(apiLog); var formatter = JsonLogFormatter.Instance; var firehoseSink = Utility.GetFirehoseSink(); var redisSink = Utility.GetRedisSink(); var compositeSink = Utility.GetCompositeSink(formatter, redisSink, firehoseSink); var logWriter = new LogWriter(formatter, compositeSink); logWriter.WriteAsync(filteredLog).GetAwaiter().GetResult(); //Thread.Sleep(60000); var logData = Utility.GetEsLogDataById(id); var esLogId = string.Empty; var expected = "1*********3"; string actual; logData.TryGetValue("txid", out actual); Assert.Equal(expected, actual); }
public void MaskCompleteValue_Should_Mast_Entire_Value() { var id = Convert.ToString(Guid.NewGuid()); var apiLog = Utility.GetApiLog(); apiLog.Id = id; var filter = new TextLogMaskingFilter(new TextMaskingRule() { Field = "txid", Mask = Masks.MaskCompleteValue }); var maskedLog = filter.Apply(apiLog); var formatter = JsonLogFormatter.Instance; var firehoseSink = Utility.GetFirehoseSink(); var redisSink = Utility.GetRedisSink(); var compositeSink = Utility.GetCompositeSink(formatter, redisSink, firehoseSink); var logWriter = new LogWriter(formatter, compositeSink); logWriter.WriteAsync(maskedLog).GetAwaiter().GetResult(); //Thread.Sleep(60000); var logData = Utility.GetEsLogDataById(id); var esLogId = string.Empty; var expected = "***********"; string actual; logData.TryGetValue("txid", out actual); Assert.Equal(expected, actual); }
public void Should_Not_Mask_NullOrEmpty_TextLog() { var id = Convert.ToString(Guid.NewGuid()); var apiLog = Utility.GetApiLog(); apiLog.Id = id; apiLog.TransactionId = string.Empty; var filter = new TextLogMaskingFilter(new TextMaskingRule() { Field = "txid", Mask = Masks.DoNotMaskNullOrEmpty }); var maskedLog = filter.Apply(apiLog); var formatter = JsonLogFormatter.Instance; var firehoseSink = Utility.GetFirehoseSink(); var redisSink = Utility.GetRedisSink(); var compositeSink = Utility.GetCompositeSink(formatter, redisSink, firehoseSink); var logWriter = new LogWriter(formatter, compositeSink); logWriter.WriteAsync(maskedLog).GetAwaiter().GetResult(); //Thread.Sleep(60000); var logData = Utility.GetEsLogDataById(id); var esLogId = string.Empty; string actual; logData.TryGetValue("txid", out actual); Assert.AreEqual(string.Empty, actual); }
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 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 Should_Be_Able_To_Add_Filters_Using_MaskingDelegate() { var loggingFilter = new LoggingFilter(new List <ILogFilter>()); var filter = new TextLogMaskingFilter(new TextMaskingRule() { Field = "txid", Mask = Masks.DefaultMask }); var filter1 = new TextLogMaskingFilter(new TextMaskingRule() { Field = "verb", Mask = Masks.DefaultMask }); loggingFilter.ConfigureMaskingDelegate(filter.Apply).Apply(); loggingFilter.ConfigureMaskingDelegate(filter1.Apply).Apply(); var id = Convert.ToString(Guid.NewGuid()); var apiLog = Utility.GetApiLog(); apiLog.Id = id; var formatter = JsonLogFormatter.Instance; var firehoseSink = Utility.GetFirehoseSink(); var redisSink = Utility.GetRedisSink(); var compositeSink = Utility.GetCompositeSink(formatter, redisSink, firehoseSink); var logWriter = new LogWriter(formatter, compositeSink, loggingFilter.Filters); logWriter.WriteAsync(apiLog).GetAwaiter().GetResult(); //Thread.Sleep(60000); var logData = Utility.GetEsLogDataById(id); var esLogId = string.Empty; var expected = "1*********3"; string actual; logData.TryGetValue("txid", out actual); var expected1 = "v***"; string actual1; logData.TryGetValue("verb", out actual1); Assert.Equal(expected, actual); Assert.Equal(expected1, actual1); }
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 Should_Display_MaskingFailed_For_Invalid_Querystring() { var id = Convert.ToString(Guid.NewGuid()); var apiLog = Utility.GetApiLog(); apiLog.Id = id; List <TextMaskingRule> _rules = new List <TextMaskingRule>(); _rules.Add(new TextMaskingRule() { Field = "param1", Mask = Masks.MaskCompleteValue }); _rules.Add(new TextMaskingRule() { Field = "param2", Mask = Masks.MaskCompleteValue }); var queryStringMaskingRule = new QueryStringMaskingRule("Verb", _rules.ToArray()); var filter = new TextLogMaskingFilter(new QueryStringMaskingRule[] { queryStringMaskingRule }); var maskedLog = filter.Apply(apiLog); var formatter = JsonLogFormatter.Instance; var firehoseSink = Utility.GetFirehoseSink(); var redisSink = Utility.GetRedisSink(); var compositeSink = Utility.GetCompositeSink(formatter, redisSink, firehoseSink); var logWriter = new LogWriter(formatter, compositeSink); logWriter.WriteAsync(maskedLog).GetAwaiter().GetResult(); //Thread.Sleep(60000); var logData = Utility.GetEsLogDataById(id); var esLogId = string.Empty; var expected = "Masking Failed"; string actual; logData.TryGetValue("verb", out actual); Assert.Equal(expected, actual); }
public void Default_Mask_Should_Mask_Value_Based_On_Length() { var id = Convert.ToString(Guid.NewGuid()); var apiLog = Utility.GetApiLog(); apiLog.Id = id; apiLog.SetValue("test1", "ab"); apiLog.SetValue("test2", "abcd"); apiLog.SetValue("test3", "abcdefg"); var rule1 = new TextMaskingRule() { Field = "test1", Mask = Masks.DefaultMask }; var rule2 = new TextMaskingRule() { Field = "test2", Mask = Masks.DefaultMask }; var rule3 = new TextMaskingRule() { Field = "test3", Mask = Masks.DefaultMask }; var filter = new TextLogMaskingFilter(new List <TextMaskingRule> { rule1, rule2, rule3 }); var maskedLog = filter.Apply(apiLog); var formatter = JsonLogFormatter.Instance; var firehoseSink = Utility.GetFirehoseSink(); var redisSink = Utility.GetRedisSink(); var compositeSink = Utility.GetCompositeSink(formatter, redisSink, firehoseSink); var logWriter = new LogWriter(formatter, compositeSink); logWriter.WriteAsync(maskedLog).GetAwaiter().GetResult(); //Thread.Sleep(60000); var logData = Utility.GetEsLogDataById(id); var esLogId = string.Empty; var expected1 = "**"; string actual1; logData.TryGetValue("test1", out actual1); var expected2 = "a***"; string actual2; logData.TryGetValue("test2", out actual2); var expected3 = "a*****g"; string actual3; logData.TryGetValue("test3", out actual3); Assert.Equal(expected1, actual1); }