mirror of
https://github.com/TecharoHQ/anubis.git
synced 2025-08-03 09:48:08 -04:00

Previously this made ClearCookie always clear cookies by name even when CookieDomain was set. This change fixes this and adds tests to make sure that this doesn't happen again. Signed-off-by: Xe Iaso <me@xeiaso.net>
59 lines
1.1 KiB
Go
59 lines
1.1 KiB
Go
package lib
|
|
|
|
import (
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/TecharoHQ/anubis"
|
|
)
|
|
|
|
func TestClearCookie(t *testing.T) {
|
|
srv := spawnAnubis(t, Options{})
|
|
rw := httptest.NewRecorder()
|
|
|
|
srv.ClearCookie(rw)
|
|
|
|
resp := rw.Result()
|
|
|
|
cookies := resp.Cookies()
|
|
|
|
if len(cookies) != 1 {
|
|
t.Errorf("wanted 1 cookie, got %d cookies", len(cookies))
|
|
}
|
|
|
|
ckie := cookies[0]
|
|
|
|
if ckie.Name != anubis.CookieName {
|
|
t.Errorf("wanted cookie named %q, got cookie named %q", anubis.CookieName, ckie.Name)
|
|
}
|
|
|
|
if ckie.MaxAge != -1 {
|
|
t.Errorf("wanted cookie max age of -1, got: %d", ckie.MaxAge)
|
|
}
|
|
}
|
|
|
|
func TestClearCookieWithDomain(t *testing.T) {
|
|
srv := spawnAnubis(t, Options{CookieDomain: "techaro.lol"})
|
|
rw := httptest.NewRecorder()
|
|
|
|
srv.ClearCookie(rw)
|
|
|
|
resp := rw.Result()
|
|
|
|
cookies := resp.Cookies()
|
|
|
|
if len(cookies) != 1 {
|
|
t.Errorf("wanted 1 cookie, got %d cookies", len(cookies))
|
|
}
|
|
|
|
ckie := cookies[0]
|
|
|
|
if ckie.Name != srv.cookieName {
|
|
t.Errorf("wanted cookie named %q, got cookie named %q", srv.cookieName, ckie.Name)
|
|
}
|
|
|
|
if ckie.MaxAge != -1 {
|
|
t.Errorf("wanted cookie max age of -1, got: %d", ckie.MaxAge)
|
|
}
|
|
}
|