mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-09-19 18:22:24 +08:00
test(tenpayv3): 补充部分含请求敏感数据中请求的自动加密的单元测试
This commit is contained in:
@@ -13,7 +13,6 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Utilities
|
|||||||
InnerReplacePropertyStringValue(ref obj, replacement, null);
|
InnerReplacePropertyStringValue(ref obj, replacement, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void InnerReplacePropertyStringValue<T>(ref T obj, ReplacePropertyStringValueReplacement replacement, PropertyInfo? currentProp)
|
private static void InnerReplacePropertyStringValue<T>(ref T obj, ReplacePropertyStringValueReplacement replacement, PropertyInfo? currentProp)
|
||||||
{
|
{
|
||||||
if (obj == null) throw new ArgumentNullException(nameof(obj));
|
if (obj == null) throw new ArgumentNullException(nameof(obj));
|
||||||
@@ -25,7 +24,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Utilities
|
|||||||
|
|
||||||
if (objType.IsArray || obj is IList || obj is IDictionary)
|
if (objType.IsArray || obj is IList || obj is IDictionary)
|
||||||
{
|
{
|
||||||
EachCollectionProperty(ref obj, objType, replacement, null);
|
InnerReplaceEachCollectionPropertyStringValue(ref obj, objType, replacement, null);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -55,12 +54,14 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Utilities
|
|||||||
object? value = childProp.GetValue(obj, null);
|
object? value = childProp.GetValue(obj, null);
|
||||||
if (value is null)
|
if (value is null)
|
||||||
continue;
|
continue;
|
||||||
EachCollectionProperty(ref value, propType, replacement, childProp);
|
|
||||||
|
InnerReplaceEachCollectionPropertyStringValue(ref value, propType, replacement, childProp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static void EachCollectionProperty<T>(ref T obj, Type objType, ReplacePropertyStringValueReplacement replacement, PropertyInfo? currentProp)
|
|
||||||
|
private static void InnerReplaceEachCollectionPropertyStringValue<T>(ref T obj, Type objType, ReplacePropertyStringValueReplacement replacement, PropertyInfo? currentProp)
|
||||||
{
|
{
|
||||||
if (objType.IsArray)
|
if (objType.IsArray)
|
||||||
{
|
{
|
||||||
|
@@ -42,5 +42,26 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.UnitTests
|
|||||||
Assert.Equal(MockText, data.Account);
|
Assert.Equal(MockText, data.Account);
|
||||||
Assert.Equal(MockText, Utilities.RSAUtility.DecryptWithECB(RSA_PRIVATE_KEY, data.Name));
|
Assert.Equal(MockText, Utilities.RSAUtility.DecryptWithECB(RSA_PRIVATE_KEY, data.Name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact(DisplayName = "加密请求中的敏感数据([POST] /profitsharing/orders)")]
|
||||||
|
public void DecryptResponseSensitiveProperty_CreateProfitSharingOrderRequest()
|
||||||
|
{
|
||||||
|
var mock = new Models.CreateProfitSharingOrderRequest()
|
||||||
|
{
|
||||||
|
ReceiverList = new List<Models.CreateProfitSharingOrderRequest.Types.Receiver>()
|
||||||
|
{
|
||||||
|
new Models.CreateProfitSharingOrderRequest.Types.Receiver()
|
||||||
|
{
|
||||||
|
Account = MockText,
|
||||||
|
Name = MockText
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var data = MockClientInstance.Value.EncryptRequestSensitiveProperty(mock);
|
||||||
|
|
||||||
|
Assert.Equal(RSA_CERTSN, data.WechatpayCertSerialNumber);
|
||||||
|
Assert.Equal(MockText, data.ReceiverList[0].Account);
|
||||||
|
Assert.Equal(MockText, Utilities.RSAUtility.DecryptWithECB(RSA_PRIVATE_KEY, data.ReceiverList[0].Name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user