在尝试测试以下代码时:
//SetSingleSignOn Sets the cookie to allow for single sign cross applications.
func SetSingleSignOn(w http.ResponseWriter, token string) {
http.SetCookie(w, &http.Cookie{
Name: ssoCookie,
Value: token,
Path: "/",
HttpOnly: false,
Secure: false,
Domain: "localhost",
Expires: time.Now().AddDate(0, 0, 7),
MaxAge: 0,
})
}
//DestroySingleSignOn Gets rid of single sign on, in case a user logs out of the application.
func DestroySingleSignOn(r *http.Request, w http.ResponseWriter) {
cookie, err := r.Cookie(ssoCookie)
if err != nil || cookie.Value == "" {
return
}
cookie = &http.Cookie{
Name: ssoCookie,
Path: "/",
HttpOnly: false,
Secure: false,
Domain: "localhost",
Expires: time.Now(),
MaxAge: -1}
http.SetCookie(w, cookie)
}
我遇到了明显的错误失败。
我所有的SetSingleSignOn通过测试,但健全性测试DestroySingleSignOn失败。
好像http.SetCookie(w, cookie)根本没有调用过!更离奇的是,当我取消对函数的直接调用时
http.SetCookie(w, &http.Cookie{
Name: ssoCookie,
Path: "/",
HttpOnly: false,
Secure: false,
Domain: "localhost",
Expires: time.Now(),
MaxAge: -1}
它似乎可以正常工作(最后一个cookie处于非活动状态),但是现在其中有两个cookie res.Cookies()!
是什么原因造成的?
一只萌萌小番薯
相关分类