1 回答
TA贡献1795条经验 获得超7个赞
在您的DestorySingleSignOn函数中,您将从以下代码块开始:
cookie, err := r.Cookie(ssoCookie)
if err != nil || cookie.Value == "" {
return
}
请注意,您正在检查请求上的cookie ,但仅在response上设置了cookie 。您将需要发出请求以获取初始cookie集,然后使用该cookie发出第二个请求才能使它起作用。
t.Run("SignedOnFirst", func(t *testing.T) {
req := httptest.NewRequest("POST",
"localhost:42100",
nil)
w := httptest.NewRecorder()
SetSingleSignOn(w, "12446rewa12314")
// get the initial cookie
res := w.Result()
cookie := res.Cookies()[0]
// issue a second request with the cookie
req = httptest.NewRequest("POST",
"localhost:42100",
nil)
req.AddCookie(cookie)
w = httptest.NewRecorder()
// assert.NotPanics(t, func() { DestroySingleSignOn(req, w) })
DestroySingleSignOn(req, w)
// get the new cookie
res = w.Result()
fmt.Println(res.Cookies())
assert.Equal(t, 1, len(res.Cookies()))
cookie = *res.Cookies()[0]
// cookie should be named ssoCookie
assert.Equal(t,
ssoCookie,
cookie.Name)
// cookie should have already expired
assert.True(t,
time.Now().After(cookie.Expires))
})
- 1 回答
- 0 关注
- 262 浏览
添加回答
举报