fix(sdk): 单调时钟回拨检测与可信时间补偿
sdk-ci / test (push) Successful in 2m24s
sdk-release / release (push) Failing after 41s
sdk-release / cleanup (push) Successful in 8s

- 墙钟回拨超过 60s 时补偿 clockSkew 并告警,trustedNow 不随回拨倒退
- 新增回拨补偿测试
This commit is contained in:
iceking2nd committed 2026-11-14 21:28:20 +08:00
1 parent c320f7c91f
commit 5cc2d73cdd
2 files changed
+48

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
package sdk
import "testing"
// TestClockRollback_Compensated 本地时钟回拨不得让可信时间倒退。
func TestClockRollback_Compensated(t *testing.T) {
e := newEnv(t)
clock := &fakeClock{now: e.now}
path := writeFileLicense(t, e, 0)
c, err := New(WithLicenseFile(path), WithProductKey("prod_test"),
WithTrustChain(e.trust()), WithClock(clock))
if err != nil {
t.Fatal(err)
}
defer c.Close()
before := c.trustedNow()
clock.Advance(-3600) // 墙钟回拨 1h
c.tick()
if got := c.trustedNow(); got < before {
t.Fatalf("可信时间倒退: before=%d after=%d", before, got)
}
if c.State() != StateActive {
t.Fatalf("回拨不应改变有效状态: %s", c.State())
}
}