@@ -140,7 +140,7 @@ var _ = Describe("CSRF Cookie Tests", func() {
140 Host: cookieDomain,
140 Host: cookieDomain,
141 Path: cookiePath,
141 Path: cookiePath,
143− }
143+ Header: make(http.Header)}
146 AfterEach(func() {
146 AfterEach(func() {
@@ -168,6 +168,67 @@ var _ = Describe("CSRF Cookie Tests", func() {
171+ Context("LoadCSRFCookie", func() {
173+ // we need to reset the time to ensure the cookie is valid
174+ privateCSRF.time.Reset()
177+ It("should return error when no cookie is set", func() {
178+ csrf, err := LoadCSRFCookie(req, cookieOpts)
179+ Expect(err).To(HaveOccurred())
180+ Expect(csrf).To(BeNil())
183+ It("should find one valid cookie", func() {
184+ privateCSRF.OAuthState = []byte(csrfState)
185+ privateCSRF.OIDCNonce = []byte(csrfNonce)
186+ encoded, err := privateCSRF.encodeCookie()
187+ Expect(err).ToNot(HaveOccurred())
189+ req.AddCookie(&http.Cookie{
190+ Name: privateCSRF.cookieName(),
194+ csrf, err := LoadCSRFCookie(req, cookieOpts)
195+ Expect(err).ToNot(HaveOccurred())
196+ Expect(csrf).ToNot(BeNil())
199+ It("should return error when one invalid cookie is set", func() {
200+ req.AddCookie(&http.Cookie{
201+ Name: privateCSRF.cookieName(),
205+ csrf, err := LoadCSRFCookie(req, cookieOpts)
206+ Expect(err).To(HaveOccurred())
207+ Expect(csrf).To(BeNil())
210+ It("should be able to handle two cookie with one invalid", func() {
211+ privateCSRF.OAuthState = []byte(csrfState)
212+ privateCSRF.OIDCNonce = []byte(csrfNonce)
213+ encoded, err := privateCSRF.encodeCookie()
214+ Expect(err).ToNot(HaveOccurred())
216+ req.AddCookie(&http.Cookie{
217+ Name: privateCSRF.cookieName(),
221+ req.AddCookie(&http.Cookie{
222+ Name: privateCSRF.cookieName(),
226+ csrf, err := LoadCSRFCookie(req, cookieOpts)
227+ Expect(err).ToNot(HaveOccurred())
228+ Expect(csrf).ToNot(BeNil())
171 Context("ClearCookie", func() {
232 Context("ClearCookie", func() {
172 It("sets a cookie with an empty value in the past", func() {
233 It("sets a cookie with an empty value in the past", func() {
173 rw := httptest.NewRecorder()
234 rw := httptest.NewRecorder()