Skip to content

Commit 6fac8eb

Browse files
authored
Merge pull request #24 from CyberSource/log-utility-fix
Log utility fix
2 parents ff3dd0b + 9d696d5 commit 6fac8eb

File tree

124 files changed

+3144
-601
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+3144
-601
lines changed

cybersource-rest-auth-netstandard/AuthenticationSdk/AuthenticationSdk/AuthenticationSdk.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.1</TargetFramework>
55
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
6-
<Version>0.0.1.4</Version>
6+
<Version>0.0.1.5</Version>
77
<Authors>CyberSource</Authors>
88
<Product>Authentication_SDK</Product>
99
<Description />
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.Collections.Generic;
2+
3+
namespace AuthenticationSdk.util
4+
{
5+
public class AuthenticationTags
6+
{
7+
private static Dictionary<string, string> authenticationTags = new Dictionary<string, string>();
8+
private static bool isLoaded = false;
9+
10+
public static Dictionary<string, string> getAuthenticationTags()
11+
{
12+
if (isLoaded)
13+
{
14+
return authenticationTags;
15+
}
16+
17+
int authenticationTagsCount = SensitiveDataConfigurationType.authenticationTags.Length;
18+
19+
for (int i = 0; i < authenticationTagsCount; i++)
20+
{
21+
string tagName = SensitiveDataConfigurationType.authenticationTags[i].tagName;
22+
string pattern = SensitiveDataConfigurationType.authenticationTags[i].pattern;
23+
string replacement = SensitiveDataConfigurationType.authenticationTags[i].replacement;
24+
25+
if (!string.IsNullOrEmpty(pattern))
26+
{
27+
pattern = $"{tagName} : {pattern}";
28+
}
29+
30+
replacement = $"{replacement}";
31+
32+
authenticationTags.Add(pattern, replacement);
33+
}
34+
35+
isLoaded = true;
36+
37+
return authenticationTags;
38+
}
39+
}
40+
}

cybersource-rest-auth-netstandard/AuthenticationSdk/AuthenticationSdk/util/LogUtility.cs

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,94 @@
11
using NLog;
22
using System;
33
using System.Collections.Generic;
4-
using System.Reflection;
54
using System.Text;
65
using System.Text.RegularExpressions;
76

87
namespace AuthenticationSdk.util
98
{
109
public class LogUtility
1110
{
12-
private static Dictionary<string, string> sensitiveTags = new Dictionary<string, string>();
13-
private static Dictionary<string, string> authenticationTags = new Dictionary<string, string>();
11+
private Dictionary<string, string> sensitiveTags;
12+
private Dictionary<string, string> authenticationTags;
1413

15-
private static void LoadSensitiveDataConfiguration()
14+
public LogUtility()
1615
{
17-
sensitiveTags.Clear();
18-
authenticationTags.Clear();
19-
20-
int sensitiveTagsCount = SensitiveDataConfigurationType.sensitiveTags.Length;
21-
22-
for (int i = 0; i < sensitiveTagsCount; i++)
23-
{
24-
string tagName = SensitiveDataConfigurationType.sensitiveTags[i].tagName;
25-
string pattern = SensitiveDataConfigurationType.sensitiveTags[i].pattern;
26-
string replacement = SensitiveDataConfigurationType.sensitiveTags[i].replacement;
27-
28-
if (!string.IsNullOrEmpty(pattern))
29-
{
30-
pattern = $"\\\"{tagName}\\\":\\\"{pattern}\\\"";
31-
}
32-
else
33-
{
34-
pattern = $"\\\"{tagName}\\\":\\\".+\\\"";
35-
}
36-
37-
replacement = $"\"{tagName}\":\"{replacement}\"";
16+
sensitiveTags = new Dictionary<string, string>();
17+
authenticationTags = new Dictionary<string, string>();
18+
}
3819

39-
sensitiveTags.Add(pattern, replacement);
40-
}
20+
/// <summary>
21+
/// mutex to ensure that the operation is thread safe
22+
/// </summary>
23+
private static readonly object mutex = new object();
4124

42-
int authenticationTagsCount = SensitiveDataConfigurationType.authenticationTags.Length;
25+
/// <summary>
26+
/// check if the dictionaries have already been loaded
27+
/// </summary>
28+
private static bool loaded = false;
4329

44-
for (int i = 0; i < authenticationTagsCount; i++)
30+
private void LoadSensitiveDataConfiguration()
31+
{
32+
lock(mutex)
4533
{
46-
string tagName = SensitiveDataConfigurationType.authenticationTags[i].tagName;
47-
string pattern = SensitiveDataConfigurationType.authenticationTags[i].pattern;
48-
string replacement = SensitiveDataConfigurationType.authenticationTags[i].replacement;
49-
50-
if (!string.IsNullOrEmpty(pattern))
34+
if (loaded)
5135
{
52-
pattern = $"{tagName} : {pattern}";
36+
return;
5337
}
5438

55-
replacement = $"{replacement}";
39+
sensitiveTags.Clear();
40+
authenticationTags.Clear();
5641

57-
authenticationTags.Add(pattern, replacement);
42+
sensitiveTags = SensitiveTags.getSensitiveTags();
43+
authenticationTags = AuthenticationTags.getAuthenticationTags();
44+
45+
loaded = true;
5846
}
5947
}
6048

61-
public static string MaskSensitiveData(string str)
49+
public string MaskSensitiveData(string str)
6250
{
6351
LoadSensitiveDataConfiguration();
6452

65-
foreach (KeyValuePair<string, string> tag in sensitiveTags)
53+
try
54+
{
55+
foreach (KeyValuePair<string, string> tag in sensitiveTags)
56+
{
57+
str = Regex.Replace(str, tag.Key, tag.Value);
58+
}
59+
}
60+
catch (Exception e)
6661
{
67-
str = Regex.Replace(str, tag.Key, tag.Value);
62+
throw e;
6863
}
6964

70-
foreach (KeyValuePair<string, string> tag in authenticationTags)
65+
try
66+
{
67+
foreach (KeyValuePair<string, string> tag in authenticationTags)
68+
{
69+
str = Regex.Replace(str, tag.Key, tag.Value);
70+
}
71+
}
72+
catch (Exception e)
7173
{
72-
str = Regex.Replace(str, tag.Key, tag.Value);
74+
throw e;
7375
}
7476

7577
return str;
7678
}
7779

78-
public static bool IsMaskingEnabled(Logger logger)
80+
public bool IsMaskingEnabled(Logger logger)
7981
{
82+
if (!(logger.Factory.Configuration?.Variables?.ContainsKey("enableMasking") ?? false))
83+
{
84+
logger.Warn("NLog configuration is missing key/value pair: enableMasking. Assuming true");
85+
return true;
86+
}
87+
8088
return logger.Factory.Configuration.Variables["enableMasking"].ToString().ToLower().Contains("true");
8189
}
8290

83-
public static string ConvertDictionaryToString(Dictionary<string, string> dict)
91+
public string ConvertDictionaryToString(Dictionary<string, string> dict)
8492
{
8593
var stringBuilder = new StringBuilder();
8694

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System.Collections.Generic;
2+
3+
namespace AuthenticationSdk.util
4+
{
5+
public class SensitiveTags
6+
{
7+
private static Dictionary<string, string> sensitiveTags = new Dictionary<string, string>();
8+
private static bool isLoaded = false;
9+
10+
public static Dictionary<string, string> getSensitiveTags()
11+
{
12+
if (isLoaded)
13+
{
14+
return sensitiveTags;
15+
}
16+
17+
int sensitiveTagsCount = SensitiveDataConfigurationType.sensitiveTags.Length;
18+
19+
for (int i = 0; i < sensitiveTagsCount; i++)
20+
{
21+
string tagName = SensitiveDataConfigurationType.sensitiveTags[i].tagName;
22+
string pattern = SensitiveDataConfigurationType.sensitiveTags[i].pattern;
23+
string replacement = SensitiveDataConfigurationType.sensitiveTags[i].replacement;
24+
25+
if (!string.IsNullOrEmpty(pattern))
26+
{
27+
pattern = $"\\\"{tagName}\\\":\\\"{pattern}\\\"";
28+
}
29+
else
30+
{
31+
pattern = $"\\\"{tagName}\\\":\\\".+\\\"";
32+
}
33+
34+
replacement = $"\"{tagName}\":\"{replacement}\"";
35+
36+
sensitiveTags.Add(pattern, replacement);
37+
}
38+
39+
isLoaded = true;
40+
41+
return sensitiveTags;
42+
}
43+
}
44+
}

cybersource-rest-client-netstandard/cybersource-rest-client-netstandard.Test/Model/CreatePaymentRequestTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,22 @@ public void TokenInformationTest()
209209
// TODO unit test for the property 'TokenInformation'
210210
}
211211
/// <summary>
212+
/// Test the property 'InvoiceDetails'
213+
/// </summary>
214+
[Test]
215+
public void InvoiceDetailsTest()
216+
{
217+
// TODO unit test for the property 'InvoiceDetails'
218+
}
219+
/// <summary>
220+
/// Test the property 'ProcessorInformation'
221+
/// </summary>
222+
[Test]
223+
public void ProcessorInformationTest()
224+
{
225+
// TODO unit test for the property 'ProcessorInformation'
226+
}
227+
/// <summary>
212228
/// Test the property 'RiskInformation'
213229
/// </summary>
214230
[Test]

cybersource-rest-client-netstandard/cybersource-rest-client-netstandard.Test/Model/PtsV2PaymentsCapturesPost201ResponseOrderInformationAmountDetailsTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ public void CurrencyTest()
8080
{
8181
// TODO unit test for the property 'Currency'
8282
}
83+
/// <summary>
84+
/// Test the property 'ProcessorTransactionFee'
85+
/// </summary>
86+
[Test]
87+
public void ProcessorTransactionFeeTest()
88+
{
89+
// TODO unit test for the property 'ProcessorTransactionFee'
90+
}
8391

8492
}
8593

cybersource-rest-client-netstandard/cybersource-rest-client-netstandard.Test/Model/PtsV2PaymentsPost201ResponseProcessorInformationTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,22 @@ public void RetrievalReferenceNumberTest()
288288
{
289289
// TODO unit test for the property 'RetrievalReferenceNumber'
290290
}
291+
/// <summary>
292+
/// Test the property 'PaymentUrl'
293+
/// </summary>
294+
[Test]
295+
public void PaymentUrlTest()
296+
{
297+
// TODO unit test for the property 'PaymentUrl'
298+
}
299+
/// <summary>
300+
/// Test the property 'CompleteUrl'
301+
/// </summary>
302+
[Test]
303+
public void CompleteUrlTest()
304+
{
305+
// TODO unit test for the property 'CompleteUrl'
306+
}
291307

292308
}
293309

cybersource-rest-client-netstandard/cybersource-rest-client-netstandard.Test/Model/Ptsv2paymentsBuyerInformationTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,22 @@ public void HashedPasswordTest()
113113
// TODO unit test for the property 'HashedPassword'
114114
}
115115
/// <summary>
116+
/// Test the property 'Gender'
117+
/// </summary>
118+
[Test]
119+
public void GenderTest()
120+
{
121+
// TODO unit test for the property 'Gender'
122+
}
123+
/// <summary>
124+
/// Test the property 'Language'
125+
/// </summary>
126+
[Test]
127+
public void LanguageTest()
128+
{
129+
// TODO unit test for the property 'Language'
130+
}
131+
/// <summary>
116132
/// Test the property 'MobilePhone'
117133
/// </summary>
118134
[Test]

cybersource-rest-client-netstandard/cybersource-rest-client-netstandard.Test/Model/Ptsv2paymentsClientReferenceInformationTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ public void CodeTest()
7373
// TODO unit test for the property 'Code'
7474
}
7575
/// <summary>
76+
/// Test the property 'ReconciliationId'
77+
/// </summary>
78+
[Test]
79+
public void ReconciliationIdTest()
80+
{
81+
// TODO unit test for the property 'ReconciliationId'
82+
}
83+
/// <summary>
7684
/// Test the property 'PausedRequestId'
7785
/// </summary>
7886
[Test]

cybersource-rest-client-netstandard/cybersource-rest-client-netstandard.Test/Model/Ptsv2paymentsDeviceInformationTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ public void UseRawFingerprintSessionIdTest()
105105
// TODO unit test for the property 'UseRawFingerprintSessionId'
106106
}
107107
/// <summary>
108+
/// Test the property 'DeviceType'
109+
/// </summary>
110+
[Test]
111+
public void DeviceTypeTest()
112+
{
113+
// TODO unit test for the property 'DeviceType'
114+
}
115+
/// <summary>
108116
/// Test the property 'RawData'
109117
/// </summary>
110118
[Test]

0 commit comments

Comments
 (0)