feat: 通用授权后台、离线证、Waffo 支付页与仪表盘加强
支持多产品计划展示、LICOFF 离线签发、支付独立配置与调试,以及分析看板;同步更新 README 与集成文档。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
0966375076
commit
8cc2c83f9d
41 files changed
+3177
-332
No files matched your search
@@ -0,0 +1,75 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestOfflineLicenseSignAndVerify(t *testing.T) {
|
||||
kp, err := DeriveOfflineKeyPair("319de107090c6fd0aae9b7db343376dd5a22ccfb24b631ee67144141b1d32000")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
now := time.Now().Unix()
|
||||
claims := OfflineLicenseClaims{
|
||||
ProductCode: "opsxshell",
|
||||
DeviceID: "dev-1",
|
||||
Email: "a@b.com",
|
||||
PlanType: "yearly",
|
||||
IssuedAt: now,
|
||||
ExpiresAt: now + 86400*30,
|
||||
MaxDevices: 1,
|
||||
}
|
||||
serial, err := SignOfflineLicense(kp, claims)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !IsOfflineLicenseKey(serial) {
|
||||
t.Fatalf("prefix: %s", serial)
|
||||
}
|
||||
got, err := VerifyOfflineLicense(kp.Public, serial)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got.DeviceID != "dev-1" || got.PlanType != "yearly" {
|
||||
t.Fatalf("claims mismatch: %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOfflineLicenseRejectsPerpetual(t *testing.T) {
|
||||
kp, err := DeriveOfflineKeyPair("319de107090c6fd0aae9b7db343376dd5a22ccfb24b631ee67144141b1d32000")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
now := time.Now().Unix()
|
||||
_, err = SignOfflineLicense(kp, OfflineLicenseClaims{
|
||||
ProductCode: "opsxshell",
|
||||
DeviceID: "dev-1",
|
||||
PlanType: "perpetual",
|
||||
IssuedAt: now,
|
||||
ExpiresAt: now + 86400,
|
||||
MaxDevices: 1,
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatal("expected perpetual reject")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOfflineLicenseRejectsOver365(t *testing.T) {
|
||||
kp, err := DeriveOfflineKeyPair("319de107090c6fd0aae9b7db343376dd5a22ccfb24b631ee67144141b1d32000")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
now := time.Now().Unix()
|
||||
_, err = SignOfflineLicense(kp, OfflineLicenseClaims{
|
||||
ProductCode: "opsxshell",
|
||||
DeviceID: "dev-1",
|
||||
PlanType: "yearly",
|
||||
IssuedAt: now,
|
||||
ExpiresAt: now + 86400*400,
|
||||
MaxDevices: 1,
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatal("expected over-365 reject")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user