- 新增 sdk.MachineFingerprint:Linux machine-id+DMI、macOS IOPlatformUUID,容器内 fail-closed - 文件模式在 bind.fp 存在时自动校验,无需显式 WithFingerprint;采集失败拒绝绑定 license - 新增 WithFingerprintFunc 支持容器读取挂载宿主 machine-id;在线激活同步使用自动指纹 - license 包新增 NormalizeFingerprint(sha256:64hex 校验与小写归一化) - 新增指纹绑定/采集失败/无绑定跳过等测试
33 lines
710 B
Go
33 lines
710 B
Go
package license
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestNormalizeFingerprint(t *testing.T) {
|
|
valid := "sha256:" + strings.Repeat("a", 64)
|
|
cases := []struct {
|
|
input string
|
|
want string
|
|
wantErr bool
|
|
}{
|
|
{"", "", false},
|
|
{valid, valid, false},
|
|
{" " + strings.ToUpper(valid) + " ", valid, false},
|
|
{"not-a-fingerprint", "", true},
|
|
{"sha256:xyz", "", true},
|
|
{"sha256:" + strings.Repeat("g", 64), "", true},
|
|
}
|
|
for _, tc := range cases {
|
|
got, err := NormalizeFingerprint(tc.input)
|
|
if (err != nil) != tc.wantErr {
|
|
t.Errorf("%q: err=%v wantErr=%v", tc.input, err, tc.wantErr)
|
|
continue
|
|
}
|
|
if got != tc.want {
|
|
t.Errorf("%q: got %q want %q", tc.input, got, tc.want)
|
|
}
|
|
}
|
|
}
|