- 丢弃支付模块自带的 PAYMENT_SECRET_KEY/JWT_SECRET 派生双密钥体系, EncryptSecret/DecryptSecret 直接走 internal/secretbox(OPSLIC_MASTER_KEY) - 全站只有一把主密钥:Waffo 私钥、节点 shared_key、支付 APIv3 密钥/应用私钥同格式同前缀 - 测试改由 TestMain 装载 secretbox 主密钥,密文前缀统一引用 secretbox.Prefix - .env.example 移除 PAYMENT_SECRET_KEY,改为说明复用 OPSLIC_MASTER_KEY
This commit is contained in:
1 parent
3a98ccc631
commit
b0b611eee2
3 files changed
+26
-138
No files matched your search
@@ -1,15 +1,19 @@
|
||||
package payment
|
||||
|
||||
import (
|
||||
"backend/internal/secretbox"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestMain 固定测试用加密主密钥(masterKey 只会解析一次) // Logan.Li
|
||||
// TestMain 固定测试用加密主密钥并装载信封加密(全站共用 OPSLIC_MASTER_KEY) // Logan.Li
|
||||
func TestMain(m *testing.M) {
|
||||
os.Setenv(EnvPaymentMasterKey, "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")
|
||||
os.Setenv("PAYMENT_CERT_DIR", os.TempDir()+"/opsx-licence-test-certs")
|
||||
if err := secretbox.LoadMasterKey(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
@@ -20,7 +24,7 @@ func TestEncryptDecryptRoundTrip(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("加密失败: %v", err)
|
||||
}
|
||||
if !strings.HasPrefix(enc, cipherPrefix) {
|
||||
if !strings.HasPrefix(enc, secretbox.Prefix) {
|
||||
t.Fatalf("密文缺少前缀: %s", enc)
|
||||
}
|
||||
if strings.Contains(enc, plain) {
|
||||
|
||||
Reference in new issue
Block a user