57 lines
852 B
Go
57 lines
852 B
Go
package golicense
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestVerify(t *testing.T) {
|
|
e, err := New(true, 5, 365)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
key, err := e.String()
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
e2, err := Verify(key)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if e2.Data.Feature1 != e.Data.Feature1 {
|
|
t.Error("Feature1 mismatch")
|
|
}
|
|
|
|
if e2.Data.Feature2 != e.Data.Feature2 {
|
|
t.Error("Feature2 mismatchh")
|
|
}
|
|
}
|
|
|
|
func TestVerifyMismatch(t *testing.T) {
|
|
e1, _ := New(true, 5, 365)
|
|
|
|
e2, _ := New(false, 5, 365)
|
|
|
|
key1, _ := e1.String()
|
|
key2, _ := e2.String()
|
|
|
|
if key1 == key2 {
|
|
t.Error("same keys, different license data")
|
|
}
|
|
}
|
|
|
|
func TestVerifyModifiedData(t *testing.T) {
|
|
e, _ := New(false, 5, 365)
|
|
|
|
e.Data.Feature1 = true
|
|
|
|
key, _ := e.String()
|
|
|
|
_, err := Verify(key)
|
|
|
|
if err != ErrorHmacMismatch {
|
|
t.Error("No HmacMismatch error")
|
|
}
|
|
}
|