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 關注
- 292 瀏覽
添加回答
舉報