Skip to content

Commit f319468

Browse files
committed
Added failing tests for data exclusions
1 parent be68dcc commit f319468

File tree

3 files changed

+94
-3
lines changed

3 files changed

+94
-3
lines changed

src/Exceptionless/Serializer/DefaultJsonSerializer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.IO;
@@ -69,7 +69,7 @@ public virtual object Deserialize(string json, Type type) {
6969
return JsonConvert.DeserializeObject(json, type, _serializerSettings);
7070
}
7171

72-
private bool ShouldSerialize(JsonTextWriterWithDepth jw, JsonProperty property, object obj, int maxDepth, IEnumerable<string> excludedPropertyNames) {
72+
private bool ShouldSerialize(JsonTextWriterWithDepth jw, JsonProperty property, object obj, int maxDepth, IList<string> excludedPropertyNames) {
7373
try {
7474
if (excludedPropertyNames != null && (property.UnderlyingName.AnyWildcardMatches(excludedPropertyNames, true) || property.PropertyName.AnyWildcardMatches(excludedPropertyNames, true)))
7575
return false;

src/Platforms/Exceptionless.AspNetCore/RequestInfoCollector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private static object GetPostData(HttpContext context, ExceptionlessConfiguratio
131131
"*SessionId*"
132132
};
133133

134-
private static Dictionary<string, string> ToDictionary(this IRequestCookieCollection cookies, IEnumerable<string> exclusions) {
134+
private static Dictionary<string, string> ToDictionary(this IRequestCookieCollection cookies, IList<string> exclusions) {
135135
var d = new Dictionary<string, string>();
136136

137137
foreach (var kvp in cookies) {
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Exceptionless.Extensions;
4+
using Exceptionless.Models;
5+
using Xunit;
6+
7+
namespace Exceptionless.Tests.Configuration {
8+
public class DataExclusionTests {
9+
[Fact]
10+
public void WillIgnoreNullKey() {
11+
var ev = new Event();
12+
ev.SetProperty(null, "test");
13+
Assert.Empty(ev.Data);
14+
}
15+
16+
[Fact]
17+
public void WillIgnoreNullValue() {
18+
var ev = new Event();
19+
ev.SetProperty("test", null);
20+
Assert.Empty(ev.Data);
21+
}
22+
23+
[Fact]
24+
public void WillIgnoreExcludedKey() {
25+
var ev = new Event();
26+
ev.SetProperty("Credit Card Number", "test", excludedPropertyNames: new [] { "Credit Card Number" });
27+
Assert.Empty(ev.Data);
28+
}
29+
30+
[Fact]
31+
public void CanHandleSortedList() {
32+
var values = new SortedList<string, string> {
33+
{ "apple", "test" },
34+
{ "Credit Card Number", "4444 4444 4444 4444" }
35+
};
36+
37+
var ev = new Event();
38+
ev.SetProperty(nameof(values), values, excludedPropertyNames: new [] { "Credit Card Number" });
39+
Assert.Single(ev.Data);
40+
Assert.Contains(nameof(values), ev.Data.Keys);
41+
Assert.Equal("{\"apple\":\"test\"}", ev.Data.GetString(nameof(values)));
42+
}
43+
44+
[Fact]
45+
public void CanHandleDictionary() {
46+
var values = new Dictionary<string, string> {
47+
{ "apple", "test" },
48+
{ "Credit Card Number", "4444 4444 4444 4444" }
49+
};
50+
51+
var ev = new Event();
52+
ev.SetProperty(nameof(values), values, excludedPropertyNames: new [] { "Credit Card Number" });
53+
Assert.Single(ev.Data);
54+
Assert.Contains(nameof(values), ev.Data.Keys);
55+
Assert.Equal("{\"apple\":\"test\"}", ev.Data.GetString(nameof(values)));
56+
}
57+
58+
[Fact]
59+
public void CanHandleObject() {
60+
var order = new Order {
61+
Id = "1234",
62+
CardLast4 = "4444",
63+
Data = new Dictionary<string, string> {
64+
{ nameof(Order.CardLast4), "5555" }
65+
}
66+
};
67+
68+
var ev = new Event();
69+
ev.SetProperty(nameof(order), order, excludedPropertyNames: new [] { nameof(order.CardLast4) });
70+
Assert.Single(ev.Data);
71+
72+
Assert.Equal("{\"id\":\"1234\"}", ev.Data.GetString(nameof(order)));
73+
}
74+
75+
[InlineData("Credit*", true)]
76+
[InlineData("*Number*", true)]
77+
[InlineData("Credit Card", false)]
78+
[InlineData("Credit Card Number", true)]
79+
[Theory]
80+
public void CanCheckWildCardMatches(string exclusion, bool isMatch) {
81+
const string key = "Credit Card Number";
82+
Assert.True(key.AnyWildcardMatches(new []{ exclusion }) == isMatch);
83+
}
84+
85+
public class Order {
86+
public string Id { get; set; }
87+
public string CardLast4 { get; set; }
88+
public IDictionary<string, string> Data { get; set; }
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)