chore: auto-commit (57 archivos)
- frontend/functions/core/format_datetime_short.md - frontend/functions/core/format_datetime_short.test.ts - frontend/functions/core/format_datetime_short.ts - frontend/functions/core/format_duration.md - frontend/functions/core/format_duration.test.ts - frontend/functions/core/format_duration.ts - frontend/functions/core/month_grid.md - frontend/functions/core/month_grid.test.ts - frontend/functions/core/month_grid.ts - frontend/functions/core/string_hash_palette.md - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package infra
|
||||
|
||||
import (
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestSessionCookieSet(t *testing.T) {
|
||||
t.Run("cookie set con nombre y token correctos", func(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
expires := time.Now().Add(24 * time.Hour).Unix()
|
||||
SessionCookieSet(w, "my_session", "tok_abc", expires)
|
||||
|
||||
cookies := w.Result().Cookies()
|
||||
if len(cookies) != 1 {
|
||||
t.Fatalf("expected 1 cookie, got %d", len(cookies))
|
||||
}
|
||||
c := cookies[0]
|
||||
if c.Name != "my_session" {
|
||||
t.Errorf("Name: got %q, want %q", c.Name, "my_session")
|
||||
}
|
||||
if c.Value != "tok_abc" {
|
||||
t.Errorf("Value: got %q, want %q", c.Value, "tok_abc")
|
||||
}
|
||||
if c.Path != "/" {
|
||||
t.Errorf("Path: got %q, want %q", c.Path, "/")
|
||||
}
|
||||
if !c.HttpOnly {
|
||||
t.Errorf("expected HttpOnly=true")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("header Set-Cookie contiene HttpOnly y SameSite=Lax", func(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
SessionCookieSet(w, "s", "v", time.Now().Add(time.Hour).Unix())
|
||||
header := w.Header().Get("Set-Cookie")
|
||||
if !strings.Contains(header, "HttpOnly") {
|
||||
t.Errorf("Set-Cookie header missing HttpOnly: %s", header)
|
||||
}
|
||||
if !strings.Contains(header, "SameSite=Lax") {
|
||||
t.Errorf("Set-Cookie header missing SameSite=Lax: %s", header)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user