feat(tenpayv3): 新增区块链电子发票相关接口

This commit is contained in:
Fu Diwei
2023-04-03 15:19:48 +08:00
parent 6e1aeb0798
commit 2f6216e609
52 changed files with 2636 additions and 6 deletions

View File

@@ -647,6 +647,88 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.UnitTests
AssertMockRequestModel(reqB2, (cipher) => Utilities.SM2Utility.Decrypt(SM2_PEM_PRIVATE_KEY, cipher));
}
[Fact(DisplayName = "测试用例:加密请求中的敏感数据([POST] /new-tax-control-fapiao/fapiao-applications")]
public async Task TestEncryptRequestSensitiveProperty_CreateNewTaxControlFapiaoApplicationRequest()
{
static Models.CreateNewTaxControlFapiaoApplicationRequest GenerateMockRequestModel()
{
return new Models.CreateNewTaxControlFapiaoApplicationRequest()
{
Buyer = new Models.CreateNewTaxControlFapiaoApplicationRequest.Types.Buyer()
{
UserMobileNumber = MOCK_PLAIN_STR,
UserEmail = MOCK_PLAIN_STR
}
};
}
static void AssertMockRequestModel(Models.CreateNewTaxControlFapiaoApplicationRequest request, Func<string, string> decryptor)
{
Assert.NotEqual(MOCK_PLAIN_STR, request.Buyer!.UserMobileNumber!);
Assert.NotEqual(MOCK_PLAIN_STR, request.Buyer!.UserEmail!);
Assert.Equal(MOCK_PLAIN_STR, decryptor.Invoke(request.Buyer!.UserMobileNumber!));
Assert.Equal(MOCK_PLAIN_STR, decryptor.Invoke(request.Buyer!.UserEmail!));
Assert.Equal(MOCK_CERT_SN, request.WechatpayCertificateSerialNumber!, ignoreCase: true);
}
var reqA1 = GenerateMockRequestModel();
CreateMockClientUseRSA(autoEncrypt: false).EncryptRequestSensitiveProperty(reqA1);
AssertMockRequestModel(reqA1, (cipher) => Utilities.RSAUtility.DecryptWithECB(RSA_PEM_PRIVATE_KEY, cipher));
var reqA2 = GenerateMockRequestModel();
CreateMockClientUseSM2(autoEncrypt: false).EncryptRequestSensitiveProperty(reqA2);
AssertMockRequestModel(reqA2, (cipher) => Utilities.SM2Utility.Decrypt(SM2_PEM_PRIVATE_KEY, cipher));
var reqB1 = GenerateMockRequestModel();
await CreateMockClientUseRSA(autoEncrypt: true).ExecuteCreateNewTaxControlFapiaoApplicationAsync(reqB1);
AssertMockRequestModel(reqB1, (cipher) => Utilities.RSAUtility.DecryptWithECB(RSA_PEM_PRIVATE_KEY, cipher));
var reqB2 = GenerateMockRequestModel();
await CreateMockClientUseSM2(autoEncrypt: true).ExecuteCreateNewTaxControlFapiaoApplicationAsync(reqB2);
AssertMockRequestModel(reqB2, (cipher) => Utilities.SM2Utility.Decrypt(SM2_PEM_PRIVATE_KEY, cipher));
}
[Fact(DisplayName = "测试用例:加密请求中的敏感数据([POST] /new-tax-control-fapiao/fapiao-applications/{fapiao_apply_id}/insert-cards")]
public async Task TestEncryptRequestSensitiveProperty_CreateNewTaxControlFapiaoApplicationCardRequest()
{
static Models.CreateNewTaxControlFapiaoApplicationCardRequest GenerateMockRequestModel()
{
return new Models.CreateNewTaxControlFapiaoApplicationCardRequest()
{
Buyer = new Models.CreateNewTaxControlFapiaoApplicationCardRequest.Types.Buyer()
{
UserMobileNumber = MOCK_PLAIN_STR,
UserEmail = MOCK_PLAIN_STR
}
};
}
static void AssertMockRequestModel(Models.CreateNewTaxControlFapiaoApplicationCardRequest request, Func<string, string> decryptor)
{
Assert.NotEqual(MOCK_PLAIN_STR, request.Buyer!.UserMobileNumber!);
Assert.NotEqual(MOCK_PLAIN_STR, request.Buyer!.UserEmail!);
Assert.Equal(MOCK_PLAIN_STR, decryptor.Invoke(request.Buyer!.UserMobileNumber!));
Assert.Equal(MOCK_PLAIN_STR, decryptor.Invoke(request.Buyer!.UserEmail!));
Assert.Equal(MOCK_CERT_SN, request.WechatpayCertificateSerialNumber!, ignoreCase: true);
}
var reqA1 = GenerateMockRequestModel();
CreateMockClientUseRSA(autoEncrypt: false).EncryptRequestSensitiveProperty(reqA1);
AssertMockRequestModel(reqA1, (cipher) => Utilities.RSAUtility.DecryptWithECB(RSA_PEM_PRIVATE_KEY, cipher));
var reqA2 = GenerateMockRequestModel();
CreateMockClientUseSM2(autoEncrypt: false).EncryptRequestSensitiveProperty(reqA2);
AssertMockRequestModel(reqA2, (cipher) => Utilities.SM2Utility.Decrypt(SM2_PEM_PRIVATE_KEY, cipher));
var reqB1 = GenerateMockRequestModel();
await CreateMockClientUseRSA(autoEncrypt: true).ExecuteCreateNewTaxControlFapiaoApplicationCardAsync(reqB1);
AssertMockRequestModel(reqB1, (cipher) => Utilities.RSAUtility.DecryptWithECB(RSA_PEM_PRIVATE_KEY, cipher));
var reqB2 = GenerateMockRequestModel();
await CreateMockClientUseSM2(autoEncrypt: true).ExecuteCreateNewTaxControlFapiaoApplicationCardAsync(reqB2);
AssertMockRequestModel(reqB2, (cipher) => Utilities.SM2Utility.Decrypt(SM2_PEM_PRIVATE_KEY, cipher));
}
[Fact(DisplayName = "测试用例:加密请求中的敏感数据([POST] /payroll-card/authentications/pre-order-with-auth")]
public async Task TestEncryptRequestSensitiveProperty_PreOrderWithAuthPayrollCardAuthenticationRequest()
{