From 6ec35891122099634b20fcb8cc931ef60e0b5897 Mon Sep 17 00:00:00 2001 From: aram price Date: Wed, 9 Dec 2020 16:29:25 -0800 Subject: [PATCH] Use recorder `Cookies()` helper - replaces hand-parsing of cookie strings --- internal/oidc/provider/manager/manager_test.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/internal/oidc/provider/manager/manager_test.go b/internal/oidc/provider/manager/manager_test.go index ed048a31..0720b719 100644 --- a/internal/oidc/provider/manager/manager_test.go +++ b/internal/oidc/provider/manager/manager_test.go @@ -104,17 +104,14 @@ func TestManager(t *testing.T) { redirectStateParam := parsedLocation.Query().Get("state") r.NotEmpty(redirectStateParam) - cookieValueAndDirectivesSplit := strings.SplitN(recorder.Header().Get("Set-Cookie"), ";", 2) - r.Len(cookieValueAndDirectivesSplit, 2) - cookieKeyValueSplit := strings.Split(cookieValueAndDirectivesSplit[0], "=") - r.Len(cookieKeyValueSplit, 2) - csrfCookieName := cookieKeyValueSplit[0] - r.Equal("__Host-pinniped-csrf", csrfCookieName) - csrfCookieValue := cookieKeyValueSplit[1] - r.NotEmpty(csrfCookieValue) + cookies := recorder.Result().Cookies() //nolint:bodyclose + r.Len(cookies, 1) + csrfCookie := cookies[0] + r.Equal("__Host-pinniped-csrf", csrfCookie.Name) + r.NotEmpty(csrfCookie.Value) // 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 {