Implement machine fingerprint hashing (T-501)
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package licensing
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDeriveMachineHashCanonicalizesGUID(t *testing.T) {
|
||||
const want = "0922bbbd8c44576d1afa6fe1309615963493cf2e1c4fddda20d2cb3ecb3c1dff"
|
||||
|
||||
got, err := DeriveMachineHash(" 6F9619FF-8B86-D011-B42D-00C04FC964FF\t", 0x1a2b3c4d)
|
||||
if err != nil {
|
||||
t.Fatalf("DeriveMachineHash() error = %v", err)
|
||||
}
|
||||
if got != want {
|
||||
t.Fatalf("DeriveMachineHash() = %q, want %q", got, want)
|
||||
}
|
||||
if len(got) != 64 || strings.ToLower(got) != got {
|
||||
t.Fatalf("DeriveMachineHash() = %q, want 64 lowercase hexadecimal characters", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeriveMachineHashChangesForVolumeSerial(t *testing.T) {
|
||||
guid := "6f9619ff-8b86-d011-b42d-00c04fc964ff"
|
||||
first, err := DeriveMachineHash(guid, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("DeriveMachineHash(first) error = %v", err)
|
||||
}
|
||||
second, err := DeriveMachineHash(guid, 2)
|
||||
if err != nil {
|
||||
t.Fatalf("DeriveMachineHash(second) error = %v", err)
|
||||
}
|
||||
if first == second {
|
||||
t.Fatal("DeriveMachineHash() did not include the volume serial number")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeriveMachineHashRejectsInvalidGUID(t *testing.T) {
|
||||
tests := []string{
|
||||
"",
|
||||
"6f9619ff8b86-d011-b42d-00c04fc964ff",
|
||||
"6f9619ff-8b86-d011-b42d-00c04fc964fg",
|
||||
"6f9619ff-8b86-d011-b42d-00c04fc964f\x00",
|
||||
"6f9619ff-8b86-d011-b42d-00c04fc964fé",
|
||||
}
|
||||
for _, machineGUID := range tests {
|
||||
_, err := DeriveMachineHash(machineGUID, 1)
|
||||
if !errors.Is(err, ErrInvalidMachineGUID) {
|
||||
t.Fatalf("DeriveMachineHash(%q) error = %v, want ErrInvalidMachineGUID", machineGUID, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user