Skip to content

Commit ea54432

Browse files
authored
Merge pull request #25 from CyberSource/cache-fix
Changes for cache fix and Feb-Mar 2022 API changes
2 parents 106c144 + 809d7a1 commit ea54432

File tree

36 files changed

+1144
-122
lines changed

36 files changed

+1144
-122
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.5</Version>
6+
<Version>0.0.1.6</Version>
77
<Authors>CyberSource</Authors>
88
<Product>Authentication_SDK</Product>
99
<Description />

cybersource-rest-auth-netstandard/AuthenticationSdk/AuthenticationSdk/core/Authorize.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public HttpToken GetSignature()
4141

4242
Enumerations.ValidateRequestType(_merchantConfig.RequestType);
4343

44-
if (String.IsNullOrEmpty(_merchantConfig.MerchantId) || String.IsNullOrEmpty(_merchantConfig.MerchantKeyId) || String.IsNullOrEmpty(_merchantConfig.MerchantSecretKey))
44+
if (string.IsNullOrEmpty(_merchantConfig.MerchantId) || string.IsNullOrEmpty(_merchantConfig.MerchantKeyId) || string.IsNullOrEmpty(_merchantConfig.MerchantSecretKey))
4545
{
4646
throw new Exception("Missing or Empty Credentials : MerchantID or MerchantKeyID or MerchantSecretKey");
4747
}
@@ -94,7 +94,7 @@ public JwtToken GetToken()
9494

9595
Enumerations.ValidateRequestType(_merchantConfig.RequestType);
9696

97-
if (String.IsNullOrEmpty(_merchantConfig.MerchantId) || String.IsNullOrEmpty(_merchantConfig.KeyAlias) || String.IsNullOrEmpty(_merchantConfig.KeyPass))
97+
if (string.IsNullOrEmpty(_merchantConfig.MerchantId) || string.IsNullOrEmpty(_merchantConfig.KeyAlias) || string.IsNullOrEmpty(_merchantConfig.KeyPass))
9898
{
9999
throw new Exception("Missing or Empty Credentials : MerchantID or KeyAlias or KeyPassphrase");
100100
}
@@ -138,7 +138,7 @@ public OAuthToken GetOAuthToken()
138138

139139
Enumerations.ValidateRequestType(_merchantConfig.RequestType);
140140

141-
if (String.IsNullOrEmpty(_merchantConfig.AccessToken) || String.IsNullOrEmpty(_merchantConfig.RefreshToken))
141+
if (string.IsNullOrEmpty(_merchantConfig.AccessToken) || string.IsNullOrEmpty(_merchantConfig.RefreshToken))
142142
{
143143
throw new Exception("Missing or Empty Credentials : AccessToken or RefreshToken");
144144
}

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

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,53 @@
44
using System.Runtime.Caching;
55
using System.Security.Cryptography;
66
using System.Security.Cryptography.X509Certificates;
7+
using System.Text.RegularExpressions;
78

89
namespace AuthenticationSdk.util
910
{
1011
public static class Cache
1112
{
13+
/// <summary>
14+
/// mutex to ensure that the operation is thread safe
15+
/// </summary>
16+
private static readonly object mutex = new object();
17+
1218
public static X509Certificate2 FetchCachedCertificate(string p12FilePath, string keyPassword)
1319
{
1420
try
1521
{
16-
ObjectCache cache = MemoryCache.Default;
17-
18-
// If no entry found from cache, create a cache entry and return the created object
19-
if (!(cache["certiFromP12File"] is X509Certificate2 cachedCertificateFromP12File))
22+
lock(mutex)
2023
{
21-
var policy = new CacheItemPolicy();
22-
var filePaths = new List<string>();
23-
var cachedFilePath = Path.GetFullPath(p12FilePath);
24-
filePaths.Add(cachedFilePath);
25-
policy.ChangeMonitors.Add(new HostFileChangeMonitor(filePaths));
26-
27-
var certificate = new X509Certificate2(p12FilePath, keyPassword);
28-
cache.Set("certiFromP12File", certificate, policy);
29-
return certificate;
30-
}
24+
ObjectCache cache = MemoryCache.Default;
25+
26+
// (^([a-z]|[A-Z]):(?=\\(?![\0-\37<>:"/\\|?*])|\/(?![\0-\37<>:"/\\|?*])|$)|^\\(?=[\\\/][^\0-\37<>:"/\\|?*]+)|^(?=(\\|\/)$)|^\.(?=(\\|\/)$)|^\.\.(?=(\\|\/)$)|^(?=(\\|\/)[^\0-\37<>:"/\\|?*]+)|^\.(?=(\\|\/)[^\0-\37<>:"/\\|?*]+)|^\.\.(?=(\\|\/)[^\0-\37<>:"/\\|?*]+))((\\|\/)[^\0-\37<>:"/\\|?*]+|(\\|\/)$)*()$
3127

32-
// otherwise return the cache entry
33-
return cachedCertificateFromP12File;
28+
var pattern = "(^([a-z]|[A-Z]):(?=\\\\(?![\\0-\\37<>:\"/\\\\|?*])|\\/(?![\\0-\\37<>:\"/\\\\|?*])|$)|^\\\\(?=[\\\\\\/][^\\0-\\37<>:\"/\\\\|?*]+)|^(?=(\\\\|\\/)$)|^\\.(?=(\\\\|\\/)$)|^\\.\\.(?=(\\\\|\\/)$)|^(?=(\\\\|\\/)[^\\0-\\37<>:\"/\\\\|?*]+)|^\\.(?=(\\\\|\\/)[^\\0-\\37<>:\"/\\\\|?*]+)|^\\.\\.(?=(\\\\|\\/)[^\\0-\\37<>:\"/\\\\|?*]+))((\\\\|\\/)([^\\0-\\37<>:\"/\\\\|?*]+|(\\\\|\\/)$))*()$";
29+
30+
var matches = Regex.Match(p12FilePath, pattern);
31+
var certFile = matches.Groups[11].ToString();
32+
33+
if (!cache.Contains(certFile))
34+
{
35+
var policy = new CacheItemPolicy();
36+
var filePaths = new List<string>();
37+
var cachedFilePath = Path.GetFullPath(p12FilePath);
38+
filePaths.Add(cachedFilePath);
39+
policy.ChangeMonitors.Add(new HostFileChangeMonitor(filePaths));
40+
41+
var certificate = new X509Certificate2(p12FilePath, keyPassword);
42+
cache.Set(certFile, certificate, policy);
43+
return certificate;
44+
}
45+
else if (cache[certFile] is X509Certificate2 cachedCertificateFromP12File)
46+
{
47+
return cachedCertificateFromP12File;
48+
}
49+
else
50+
{
51+
return null;
52+
}
53+
}
3454
}
3555
catch (CryptographicException e)
3656
{
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,26 @@
2323
namespace CyberSource.Test
2424
{
2525
/// <summary>
26-
/// Class for testing TssV2TransactionsPost201ResponseEmbeddedClientReferenceInformationPartner
26+
/// Class for testing TssV2TransactionsGet200ResponseClientReferenceInformationPartner
2727
/// </summary>
2828
/// <remarks>
2929
/// This file is automatically generated by Swagger Codegen.
3030
/// Please update the test case below to test the model.
3131
/// </remarks>
3232
[TestFixture]
33-
public class TssV2TransactionsPost201ResponseEmbeddedClientReferenceInformationPartnerTests
33+
public class TssV2TransactionsGet200ResponseClientReferenceInformationPartnerTests
3434
{
35-
// TODO uncomment below to declare an instance variable for TssV2TransactionsPost201ResponseEmbeddedClientReferenceInformationPartner
36-
//private TssV2TransactionsPost201ResponseEmbeddedClientReferenceInformationPartner instance;
35+
// TODO uncomment below to declare an instance variable for TssV2TransactionsGet200ResponseClientReferenceInformationPartner
36+
//private TssV2TransactionsGet200ResponseClientReferenceInformationPartner instance;
3737

3838
/// <summary>
3939
/// Setup before each test
4040
/// </summary>
4141
[SetUp]
4242
public void Init()
4343
{
44-
// TODO uncomment below to create an instance of TssV2TransactionsPost201ResponseEmbeddedClientReferenceInformationPartner
45-
//instance = new TssV2TransactionsPost201ResponseEmbeddedClientReferenceInformationPartner();
44+
// TODO uncomment below to create an instance of TssV2TransactionsGet200ResponseClientReferenceInformationPartner
45+
//instance = new TssV2TransactionsGet200ResponseClientReferenceInformationPartner();
4646
}
4747

4848
/// <summary>
@@ -55,13 +55,13 @@ public void Cleanup()
5555
}
5656

5757
/// <summary>
58-
/// Test an instance of TssV2TransactionsPost201ResponseEmbeddedClientReferenceInformationPartner
58+
/// Test an instance of TssV2TransactionsGet200ResponseClientReferenceInformationPartner
5959
/// </summary>
6060
[Test]
61-
public void TssV2TransactionsPost201ResponseEmbeddedClientReferenceInformationPartnerInstanceTest()
61+
public void TssV2TransactionsGet200ResponseClientReferenceInformationPartnerInstanceTest()
6262
{
63-
// TODO uncomment below to test "IsInstanceOfType" TssV2TransactionsPost201ResponseEmbeddedClientReferenceInformationPartner
64-
//Assert.IsInstanceOfType<TssV2TransactionsPost201ResponseEmbeddedClientReferenceInformationPartner> (instance, "variable 'instance' is a TssV2TransactionsPost201ResponseEmbeddedClientReferenceInformationPartner");
63+
// TODO uncomment below to test "IsInstanceOfType" TssV2TransactionsGet200ResponseClientReferenceInformationPartner
64+
//Assert.IsInstanceOfType<TssV2TransactionsGet200ResponseClientReferenceInformationPartner> (instance, "variable 'instance' is a TssV2TransactionsGet200ResponseClientReferenceInformationPartner");
6565
}
6666

6767
/// <summary>

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ public void ApplicationUserTest()
9797
// TODO unit test for the property 'ApplicationUser'
9898
}
9999
/// <summary>
100+
/// Test the property 'Partner'
101+
/// </summary>
102+
[Test]
103+
public void PartnerTest()
104+
{
105+
// TODO unit test for the property 'Partner'
106+
}
107+
/// <summary>
100108
/// Test the property 'Comments'
101109
/// </summary>
102110
[Test]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* CyberSource Merged Spec
3+
*
4+
* All CyberSource API specs merged together. These are available at https://developer.cybersource.com/api/reference/api-reference.html
5+
*
6+
* OpenAPI spec version: 0.0.1
7+
*
8+
* Generated by: https://github.com/swagger-api/swagger-codegen.git
9+
*/
10+
11+
12+
using NUnit.Framework;
13+
14+
using System;
15+
using System.Linq;
16+
using System.IO;
17+
using System.Collections.Generic;
18+
using CyberSource.Api;
19+
using CyberSource.Model;
20+
using CyberSource.Client;
21+
using System.Reflection;
22+
23+
namespace CyberSource.Test
24+
{
25+
/// <summary>
26+
/// Class for testing TssV2TransactionsGet200ResponsePaymentInformationCustomer
27+
/// </summary>
28+
/// <remarks>
29+
/// This file is automatically generated by Swagger Codegen.
30+
/// Please update the test case below to test the model.
31+
/// </remarks>
32+
[TestFixture]
33+
public class TssV2TransactionsGet200ResponsePaymentInformationCustomerTests
34+
{
35+
// TODO uncomment below to declare an instance variable for TssV2TransactionsGet200ResponsePaymentInformationCustomer
36+
//private TssV2TransactionsGet200ResponsePaymentInformationCustomer instance;
37+
38+
/// <summary>
39+
/// Setup before each test
40+
/// </summary>
41+
[SetUp]
42+
public void Init()
43+
{
44+
// TODO uncomment below to create an instance of TssV2TransactionsGet200ResponsePaymentInformationCustomer
45+
//instance = new TssV2TransactionsGet200ResponsePaymentInformationCustomer();
46+
}
47+
48+
/// <summary>
49+
/// Clean up after each test
50+
/// </summary>
51+
[TearDown]
52+
public void Cleanup()
53+
{
54+
55+
}
56+
57+
/// <summary>
58+
/// Test an instance of TssV2TransactionsGet200ResponsePaymentInformationCustomer
59+
/// </summary>
60+
[Test]
61+
public void TssV2TransactionsGet200ResponsePaymentInformationCustomerInstanceTest()
62+
{
63+
// TODO uncomment below to test "IsInstanceOfType" TssV2TransactionsGet200ResponsePaymentInformationCustomer
64+
//Assert.IsInstanceOfType<TssV2TransactionsGet200ResponsePaymentInformationCustomer> (instance, "variable 'instance' is a TssV2TransactionsGet200ResponsePaymentInformationCustomer");
65+
}
66+
67+
/// <summary>
68+
/// Test the property 'CustomerId'
69+
/// </summary>
70+
[Test]
71+
public void CustomerIdTest()
72+
{
73+
// TODO unit test for the property 'CustomerId'
74+
}
75+
/// <summary>
76+
/// Test the property 'Id'
77+
/// </summary>
78+
[Test]
79+
public void IdTest()
80+
{
81+
// TODO unit test for the property 'Id'
82+
}
83+
84+
}
85+
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* CyberSource Merged Spec
3+
*
4+
* All CyberSource API specs merged together. These are available at https://developer.cybersource.com/api/reference/api-reference.html
5+
*
6+
* OpenAPI spec version: 0.0.1
7+
*
8+
* Generated by: https://github.com/swagger-api/swagger-codegen.git
9+
*/
10+
11+
12+
using NUnit.Framework;
13+
14+
using System;
15+
using System.Linq;
16+
using System.IO;
17+
using System.Collections.Generic;
18+
using CyberSource.Api;
19+
using CyberSource.Model;
20+
using CyberSource.Client;
21+
using System.Reflection;
22+
23+
namespace CyberSource.Test
24+
{
25+
/// <summary>
26+
/// Class for testing TssV2TransactionsGet200ResponsePaymentInformationInstrumentIdentifier
27+
/// </summary>
28+
/// <remarks>
29+
/// This file is automatically generated by Swagger Codegen.
30+
/// Please update the test case below to test the model.
31+
/// </remarks>
32+
[TestFixture]
33+
public class TssV2TransactionsGet200ResponsePaymentInformationInstrumentIdentifierTests
34+
{
35+
// TODO uncomment below to declare an instance variable for TssV2TransactionsGet200ResponsePaymentInformationInstrumentIdentifier
36+
//private TssV2TransactionsGet200ResponsePaymentInformationInstrumentIdentifier instance;
37+
38+
/// <summary>
39+
/// Setup before each test
40+
/// </summary>
41+
[SetUp]
42+
public void Init()
43+
{
44+
// TODO uncomment below to create an instance of TssV2TransactionsGet200ResponsePaymentInformationInstrumentIdentifier
45+
//instance = new TssV2TransactionsGet200ResponsePaymentInformationInstrumentIdentifier();
46+
}
47+
48+
/// <summary>
49+
/// Clean up after each test
50+
/// </summary>
51+
[TearDown]
52+
public void Cleanup()
53+
{
54+
55+
}
56+
57+
/// <summary>
58+
/// Test an instance of TssV2TransactionsGet200ResponsePaymentInformationInstrumentIdentifier
59+
/// </summary>
60+
[Test]
61+
public void TssV2TransactionsGet200ResponsePaymentInformationInstrumentIdentifierInstanceTest()
62+
{
63+
// TODO uncomment below to test "IsInstanceOfType" TssV2TransactionsGet200ResponsePaymentInformationInstrumentIdentifier
64+
//Assert.IsInstanceOfType<TssV2TransactionsGet200ResponsePaymentInformationInstrumentIdentifier> (instance, "variable 'instance' is a TssV2TransactionsGet200ResponsePaymentInformationInstrumentIdentifier");
65+
}
66+
67+
/// <summary>
68+
/// Test the property 'Id'
69+
/// </summary>
70+
[Test]
71+
public void IdTest()
72+
{
73+
// TODO unit test for the property 'Id'
74+
}
75+
76+
}
77+
78+
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,30 @@ public void AccountFeaturesTest()
112112
{
113113
// TODO unit test for the property 'AccountFeatures'
114114
}
115+
/// <summary>
116+
/// Test the property 'PaymentInstrument'
117+
/// </summary>
118+
[Test]
119+
public void PaymentInstrumentTest()
120+
{
121+
// TODO unit test for the property 'PaymentInstrument'
122+
}
123+
/// <summary>
124+
/// Test the property 'InstrumentIdentifier'
125+
/// </summary>
126+
[Test]
127+
public void InstrumentIdentifierTest()
128+
{
129+
// TODO unit test for the property 'InstrumentIdentifier'
130+
}
131+
/// <summary>
132+
/// Test the property 'ShippingAddress'
133+
/// </summary>
134+
[Test]
135+
public void ShippingAddressTest()
136+
{
137+
// TODO unit test for the property 'ShippingAddress'
138+
}
115139

116140
}
117141

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ public void ResponseCodeSourceTest()
176176
{
177177
// TODO unit test for the property 'ResponseCodeSource'
178178
}
179+
/// <summary>
180+
/// Test the property 'PaymentAccountReferenceNumber'
181+
/// </summary>
182+
[Test]
183+
public void PaymentAccountReferenceNumberTest()
184+
{
185+
// TODO unit test for the property 'PaymentAccountReferenceNumber'
186+
}
179187

180188
}
181189

0 commit comments

Comments
 (0)