9
func TestSecureCookie(t *testing.T) {
11
deserialized internalData
15
secureCookie := NewSecureCookie("hash key", "block key")
16
secureCookie.ignoreExpiration()
17
for _, value := range testData {
18
if err = secureCookie.encode(value.data); err != nil {
22
serialized := secureCookie.Value()
23
if deserialized, err = secureCookie.decode(serialized); err != nil {
27
if fmt.Sprintf("%+v", deserialized) != fmt.Sprintf("%+v", value.data) {
28
t.Errorf("Expected %+v, got %+v.", value.data, deserialized)
33
func TestInvalidHMAC(t *testing.T) {
38
secureCookie := NewSecureCookie("Lorem ipsum...", "dolor sit amet...")
39
for _, value := range testData {
40
if err = secureCookie.encode(value.data); err != nil {
44
raw := []byte(secureCookie.Value())
47
serialized := string(raw)
48
if _, err = secureCookie.decode(serialized); err != nil {
49
if !errors.Is(err, ErrMacInvalid) {
53
t.Errorf("Expected invalid HMAC for %+v", value.data)