File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed
test/Serilog.Enrichers.Sensitive.Tests.Unit Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change 1
1
using System . Collections . Generic ;
2
- using System . Linq ;
3
2
using Serilog . Core ;
4
- using Serilog . Events ;
5
3
using Serilog . Sinks . InMemory ;
6
4
using Serilog . Sinks . InMemory . Assertions ;
7
5
using Xunit ;
@@ -22,6 +20,7 @@ public WhenMaskingDestructuredObject()
22
20
. Enrich . WithSensitiveDataMasking ( options =>
23
21
{
24
22
options . MaskingOperators = new List < IMaskingOperator > { new EmailAddressMaskingOperator ( ) } ;
23
+ options . MaskProperties . Add ( "SensitiveProperty" ) ;
25
24
} )
26
25
. CreateLogger ( ) ;
27
26
}
@@ -90,12 +89,30 @@ public void GivenLogMessageWithDestructuredObjectPropertyWithoutSensitiveDataInN
90
89
. WithProperty ( "TestProperty" )
91
90
. WithValue ( "also not sensitive" ) ;
92
91
}
92
+
93
+ [ Fact ]
94
+ public void GivenConfigurationToMaskSpecificPropertyAndLoggingADestructuredObject_PropertyOnObjectIsMasked ( )
95
+ {
96
+ var testObject = new TestObject ( ) ;
97
+
98
+ _logger . Information ( "Test message {@TestObject}" , testObject ) ;
99
+
100
+ _sink
101
+ . Should ( )
102
+ . HaveMessage ( "Test message {@TestObject}" )
103
+ . Appearing ( )
104
+ . Once ( )
105
+ . WithProperty ( "TestObject" )
106
+ . HavingADestructuredObject ( )
107
+ . WithProperty ( "SensitiveProperty" )
108
+ . WithValue ( "***MASKED***" ) ;
109
+ }
93
110
}
94
111
95
112
public class TestObject
96
113
{
97
114
public string TestProperty { get ; set ; } = "james.bond@universalexports.com" ;
98
-
115
+ public string SensitiveProperty { get ; set ; } = "Super sensitive data" ;
99
116
public NestedTestObject Nested { get ; set ; } = new NestedTestObject ( ) ;
100
117
}
101
118
You can’t perform that action at this time.
0 commit comments