test(tenpayv3): 提供新的响应验签测试用例

This commit is contained in:
Fu Diwei 2021-07-22 15:07:39 +08:00
parent 36be477673
commit 10c396e48f
2 changed files with 10 additions and 7 deletions

View File

@ -6,15 +6,19 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.UnitTests
{ {
static TestClients() static TestClients()
{ {
GlobalCertificateStorer = new Settings.InMemoryCertificateStorer();
Instance = new WechatTenpayClient(new WechatTenpayClientOptions() Instance = new WechatTenpayClient(new WechatTenpayClientOptions()
{ {
MerchantId = TestConfigs.WechatMerchantId, MerchantId = TestConfigs.WechatMerchantId,
MerchantV3Secret = TestConfigs.WechatMerchantSecret, MerchantV3Secret = TestConfigs.WechatMerchantSecret,
MerchantCertSerialNumber = TestConfigs.WechatMerchantCertSerialNumber, MerchantCertSerialNumber = TestConfigs.WechatMerchantCertSerialNumber,
MerchantCertPrivateKey = TestConfigs.WechatMerchantCertPrivateKey MerchantCertPrivateKey = TestConfigs.WechatMerchantCertPrivateKey,
CertificateStorer = GlobalCertificateStorer
}); });
} }
public static readonly Settings.ICertificateStorer GlobalCertificateStorer;
public static readonly WechatTenpayClient Instance; public static readonly WechatTenpayClient Instance;
} }
} }

View File

@ -22,13 +22,12 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.UnitTests
Assert.NotNull(response.WechatpaySignature); Assert.NotNull(response.WechatpaySignature);
TestClients.Instance.DecryptResponseEncryptedData(ref response); TestClients.Instance.DecryptResponseEncryptedData(ref response);
var certificateModel = response.CertificateList.SingleOrDefault(e => e.SerialNumber == response.WechatpayCertSerialNumber); foreach (var certificateModel in response.CertificateList)
Assert.NotNull(certificateModel); {
TestClients.GlobalCertificateStorer.Set(certificateModel.SerialNumber, certificateModel.EncryptCertificate.CipherText);
}
// 通过证书验证签名 Assert.True(TestClients.Instance.VerifyResponseSignature(response));
Assert.True(TestClients.Instance.VerifyResponseSignatureByCertificate(response, certificate: certificateModel.EncryptCertificate.CipherText));
// 通过公钥验证签名
Assert.True(TestClients.Instance.VerifyResponseSignature(response, publicKey: Utilities.RSAUtility.ExportPublicKey(certificateModel.EncryptCertificate.CipherText)));
} }
} }
} }