Use recorder Cookies() helper

- replaces hand-parsing of cookie strings
This commit is contained in:
aram price 2020-12-09 16:29:25 -08:00
parent 2ddba8d825
commit 6ec3589112

View File

@ -104,17 +104,14 @@ func TestManager(t *testing.T) {
redirectStateParam := parsedLocation.Query().Get("state") redirectStateParam := parsedLocation.Query().Get("state")
r.NotEmpty(redirectStateParam) r.NotEmpty(redirectStateParam)
cookieValueAndDirectivesSplit := strings.SplitN(recorder.Header().Get("Set-Cookie"), ";", 2) cookies := recorder.Result().Cookies() //nolint:bodyclose
r.Len(cookieValueAndDirectivesSplit, 2) r.Len(cookies, 1)
cookieKeyValueSplit := strings.Split(cookieValueAndDirectivesSplit[0], "=") csrfCookie := cookies[0]
r.Len(cookieKeyValueSplit, 2) r.Equal("__Host-pinniped-csrf", csrfCookie.Name)
csrfCookieName := cookieKeyValueSplit[0] r.NotEmpty(csrfCookie.Value)
r.Equal("__Host-pinniped-csrf", csrfCookieName)
csrfCookieValue := cookieKeyValueSplit[1]
r.NotEmpty(csrfCookieValue)
// Return the important parts of the response so we can use them in our next request to the callback endpoint // Return the important parts of the response so we can use them in our next request to the callback endpoint
return csrfCookieValue, redirectStateParam return csrfCookie.Value, redirectStateParam
} }
requireCallbackRequestToBeHandled := func(requestIssuer, requestURLSuffix, csrfCookieValue string) string { requireCallbackRequestToBeHandled := func(requestIssuer, requestURLSuffix, csrfCookieValue string) string {