fix(ci): align auth and payment verification tests
This commit is contained in:
@@ -4,7 +4,11 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"encoding/json"
|
||||
"encoding/pem"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -52,6 +56,28 @@ func newWebhookProviderTestLoadBalancer(client *dbent.Client) payment.LoadBalanc
|
||||
return payment.NewDefaultLoadBalancer(client, []byte(webhookProviderTestEncryptionKey))
|
||||
}
|
||||
|
||||
func encryptValidWebhookWxpayConfig(t *testing.T, suffix string) string {
|
||||
t.Helper()
|
||||
|
||||
key, err := rsa.GenerateKey(rand.Reader, 2048)
|
||||
require.NoError(t, err)
|
||||
|
||||
privDER, err := x509.MarshalPKCS8PrivateKey(key)
|
||||
require.NoError(t, err)
|
||||
pubDER, err := x509.MarshalPKIXPublicKey(&key.PublicKey)
|
||||
require.NoError(t, err)
|
||||
|
||||
return encryptWebhookProviderConfig(t, map[string]string{
|
||||
"appId": "wx-app-" + suffix,
|
||||
"mchId": "mch-" + suffix,
|
||||
"privateKey": string(pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Bytes: privDER})),
|
||||
"apiV3Key": webhookProviderTestEncryptionKey,
|
||||
"publicKey": string(pem.EncodeToMemory(&pem.Block{Type: "PUBLIC KEY", Bytes: pubDER})),
|
||||
"publicKeyId": "public-key-id-" + suffix,
|
||||
"certSerial": "cert-serial-" + suffix,
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetOrderProviderInstanceResolvesUniqueLegacyProviderKey(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
client := newPaymentConfigServiceTestClient(t)
|
||||
@@ -275,24 +301,8 @@ func TestGetOrderProviderInstanceRejectsMissingSnapshotInstanceWithoutLegacyFall
|
||||
func TestGetWebhookProviderRejectsAmbiguousRegistryFallback(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
client := newPaymentConfigServiceTestClient(t)
|
||||
wxpayConfigA := encryptWebhookProviderConfig(t, map[string]string{
|
||||
"appId": "wx-app-a",
|
||||
"mchId": "mch-a",
|
||||
"privateKey": "private-key-a",
|
||||
"apiV3Key": webhookProviderTestEncryptionKey,
|
||||
"publicKey": "public-key-a",
|
||||
"publicKeyId": "public-key-id-a",
|
||||
"certSerial": "cert-serial-a",
|
||||
})
|
||||
wxpayConfigB := encryptWebhookProviderConfig(t, map[string]string{
|
||||
"appId": "wx-app-b",
|
||||
"mchId": "mch-b",
|
||||
"privateKey": "private-key-b",
|
||||
"apiV3Key": webhookProviderTestEncryptionKey,
|
||||
"publicKey": "public-key-b",
|
||||
"publicKeyId": "public-key-id-b",
|
||||
"certSerial": "cert-serial-b",
|
||||
})
|
||||
wxpayConfigA := encryptValidWebhookWxpayConfig(t, "a")
|
||||
wxpayConfigB := encryptValidWebhookWxpayConfig(t, "b")
|
||||
_, err := client.PaymentProviderInstance.Create().
|
||||
SetProviderKey(payment.TypeWxpay).
|
||||
SetName("wxpay-a").
|
||||
@@ -442,24 +452,8 @@ func TestGetWebhookProviderUsesProviderSnapshotBeforeWxpayFallback(t *testing.T)
|
||||
Save(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
wxpayConfigA := encryptWebhookProviderConfig(t, map[string]string{
|
||||
"appId": "wx-app-snapshot-a",
|
||||
"mchId": "mch-snapshot-a",
|
||||
"privateKey": "private-key-snapshot-a",
|
||||
"apiV3Key": webhookProviderTestEncryptionKey,
|
||||
"publicKey": "public-key-snapshot-a",
|
||||
"publicKeyId": "public-key-id-snapshot-a",
|
||||
"certSerial": "cert-serial-snapshot-a",
|
||||
})
|
||||
wxpayConfigB := encryptWebhookProviderConfig(t, map[string]string{
|
||||
"appId": "wx-app-snapshot-b",
|
||||
"mchId": "mch-snapshot-b",
|
||||
"privateKey": "private-key-snapshot-b",
|
||||
"apiV3Key": webhookProviderTestEncryptionKey,
|
||||
"publicKey": "public-key-snapshot-b",
|
||||
"publicKeyId": "public-key-id-snapshot-b",
|
||||
"certSerial": "cert-serial-snapshot-b",
|
||||
})
|
||||
wxpayConfigA := encryptValidWebhookWxpayConfig(t, "snapshot-a")
|
||||
wxpayConfigB := encryptValidWebhookWxpayConfig(t, "snapshot-b")
|
||||
instA, err := client.PaymentProviderInstance.Create().
|
||||
SetProviderKey(payment.TypeWxpay).
|
||||
SetName("wxpay-snapshot-a").
|
||||
|
||||
Reference in New Issue
Block a user