refactor(cookie): set expires to epoch zero time on deletion

This commit is contained in:
Trong Huu Nguyen
2022-01-07 15:29:43 +01:00
parent 879319cd2a
commit 7432f86b64
2 changed files with 2 additions and 4 deletions

View File

@@ -43,7 +43,7 @@ func (in Cookie) Decrypt(crypter crypto.Crypter) (string, error) {
}
func Clear(w http.ResponseWriter, name string, opts Options) {
expires := time.Now().Add(-7 * 24 * time.Hour)
expires := time.Unix(0, 0)
maxAge := -1
cookie := &http.Cookie{

View File

@@ -52,11 +52,9 @@ func TestClear(t *testing.T) {
}
}
shouldExpireBefore := time.Now().Add(-7 * 24 * time.Hour)
assert.NotNil(t, result)
assert.True(t, result.Expires.Before(time.Now()))
assert.True(t, result.Expires.Before(shouldExpireBefore))
assert.True(t, result.Expires.Equal(time.Unix(0, 0)))
assert.Equal(t, -1, result.MaxAge)
assert.True(t, result.HttpOnly)
assert.Equal(t, name, result.Name)