github.com/TeaOSLab/EdgeNode@v1.3.8/internal/waf/allow_cookie_info_test.go (about) 1 // Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn . 2 3 package waf_test 4 5 import ( 6 "github.com/TeaOSLab/EdgeNode/internal/utils/fasttime" 7 "github.com/TeaOSLab/EdgeNode/internal/waf" 8 "github.com/iwind/TeaGo/assert" 9 "github.com/iwind/TeaGo/types" 10 "testing" 11 ) 12 13 func TestAllowCookieInfo_Encode(t *testing.T) { 14 var a = assert.NewAssertion(t) 15 16 var info = &waf.AllowCookieInfo{ 17 SetId: 123, 18 ExpiresAt: fasttime.Now().Unix(), 19 } 20 data, err := info.Encode() 21 if err != nil { 22 t.Fatal(err) 23 } 24 t.Log("encrypted: ["+types.String(len(data))+"]", data) 25 26 var info2 = &waf.AllowCookieInfo{} 27 err = info2.Decode(data) 28 if err != nil { 29 t.Fatal(err) 30 } 31 32 t.Logf("%+v", info2) 33 a.IsTrue(info.SetId == info2.SetId) 34 a.IsTrue(info.ExpiresAt == info2.ExpiresAt) 35 }