package keygen import "testing" func TestLegacyDualValidation(t *testing.T) { // Reference values produced independently from the disassembly. if got, want := legacyKey(1), "71npXhLZP5t3VJrvBfdFlRDNx9zHTb"; got != want { t.Fatalf("legacyKey(1) = %q, want %q", got, want) } if legacyKey(1) != legacyKey(63) { t.Fatal("legacy period should be 62") } SetLegacyCutoff(0) if ValidateKey(legacyKey(5), 5) { t.Fatal("cutoff 0 must reject every legacy token") } SetLegacyCutoff(100) if !ValidateKey(legacyKey(5), 5) { t.Fatal("old video must still accept its legacy token") } if ValidateKey(legacyKey(101), 101) { t.Fatal("video created after the switch must NOT accept a legacy token") } if !ValidateKey(GenerateKey(101), 101) { t.Fatal("new HMAC token must work above the cutoff") } if !ValidateKey(GenerateKey(5), 5) { t.Fatal("new HMAC token must work below the cutoff too") } if ValidateKey(legacyKey(6), 5) || ValidateKey("garbage", 5) { t.Fatal("wrong token accepted") } SetLegacyCutoff(0) }