test(tenpayv3): 补充部分含请求敏感数据中请求的自动加密的单元测试

This commit is contained in:
Fu Diwei
2021-12-02 09:59:54 +08:00
parent 727039ce31
commit 041f47407d
2 changed files with 26 additions and 4 deletions

View File

@@ -13,7 +13,6 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Utilities
InnerReplacePropertyStringValue(ref obj, replacement, null);
}
private static void InnerReplacePropertyStringValue<T>(ref T obj, ReplacePropertyStringValueReplacement replacement, PropertyInfo? currentProp)
{
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)
{
EachCollectionProperty(ref obj, objType, replacement, null);
InnerReplaceEachCollectionPropertyStringValue(ref obj, objType, replacement, null);
}
else
{
@@ -55,12 +54,14 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Utilities
object? value = childProp.GetValue(obj, null);
if (value is null)
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)
{

View File

@@ -42,5 +42,26 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.UnitTests
Assert.Equal(MockText, data.Account);
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));
}
}
}