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"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSessionTokenExtract(t *testing.T) {
|
||||
const cookieName = "test_session"
|
||||
|
||||
t.Run("cookie present retorna token de cookie", func(t *testing.T) {
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r.AddCookie(&http.Cookie{Name: cookieName, Value: "tok_cookie"})
|
||||
got := SessionTokenExtract(r, cookieName)
|
||||
if got != "tok_cookie" {
|
||||
t.Errorf("got %q, want %q", got, "tok_cookie")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("bearer header retorna token de header", func(t *testing.T) {
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r.Header.Set("Authorization", "Bearer tok_bearer")
|
||||
got := SessionTokenExtract(r, cookieName)
|
||||
if got != "tok_bearer" {
|
||||
t.Errorf("got %q, want %q", got, "tok_bearer")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("cookie gana sobre bearer header", func(t *testing.T) {
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r.AddCookie(&http.Cookie{Name: cookieName, Value: "tok_cookie"})
|
||||
r.Header.Set("Authorization", "Bearer tok_bearer")
|
||||
got := SessionTokenExtract(r, cookieName)
|
||||
if got != "tok_cookie" {
|
||||
t.Errorf("got %q, want %q (cookie should win)", got, "tok_cookie")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("sin token retorna cadena vacia", func(t *testing.T) {
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
got := SessionTokenExtract(r, cookieName)
|
||||
if got != "" {
|
||||
t.Errorf("got %q, want empty string", got)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user