03568c88e3
- 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>
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package infra
|
|
|
|
import (
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestSessionCookieClear(t *testing.T) {
|
|
t.Run("cookie clear setea MaxAge negativo", func(t *testing.T) {
|
|
w := httptest.NewRecorder()
|
|
SessionCookieClear(w, "my_session")
|
|
|
|
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.MaxAge >= 0 {
|
|
t.Errorf("MaxAge: got %d, want negative", c.MaxAge)
|
|
}
|
|
})
|
|
|
|
t.Run("cookie clear valor es vacio", func(t *testing.T) {
|
|
w := httptest.NewRecorder()
|
|
SessionCookieClear(w, "sess")
|
|
cookies := w.Result().Cookies()
|
|
if len(cookies) == 0 {
|
|
t.Fatal("no cookie set")
|
|
}
|
|
if cookies[0].Value != "" {
|
|
t.Errorf("Value: got %q, want empty", cookies[0].Value)
|
|
}
|
|
})
|
|
|
|
t.Run("header Set-Cookie contiene HttpOnly y SameSite=Lax", func(t *testing.T) {
|
|
w := httptest.NewRecorder()
|
|
SessionCookieClear(w, "sess")
|
|
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)
|
|
}
|
|
})
|
|
}
|