From 655fb6c4cc180dfcbc13c1b85e0fbf47019caec0 Mon Sep 17 00:00:00 2001 From: mo khan Date: Tue, 15 Apr 2025 17:46:34 -0600 Subject: feat: create session cookie tied to access token --- pkg/web/cookie/cookie_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 pkg/web/cookie/cookie_test.go (limited to 'pkg/web/cookie/cookie_test.go') diff --git a/pkg/web/cookie/cookie_test.go b/pkg/web/cookie/cookie_test.go new file mode 100644 index 0000000..17e3d88 --- /dev/null +++ b/pkg/web/cookie/cookie_test.go @@ -0,0 +1,29 @@ +package cookie + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/xlgmokha/x/pkg/env" +) + +func TestCookie(t *testing.T) { + t.Run("New", func(t *testing.T) { + t.Run("returns a cookie pinned to the HOST", func(t *testing.T) { + env.With(env.Vars{"HOST": "sparkle.example.com"}, func() { + cookie := New("name", "value", time.Now().Add(1*time.Minute)) + assert.Equal(t, cookie.Domain, "sparkle.example.com") + }) + }) + }) + + t.Run("Reset", func(t *testing.T) { + t.Run("returns an expired cookie", func(t *testing.T) { + result := Reset("example") + + assert.Equal(t, -1, result.MaxAge) + assert.Equal(t, time.Unix(0, 0), result.Expires) + }) + }) +} -- cgit v1.2.3