Skip to content

Commit

Permalink
Add failing test case for double cookie setting
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Oct 14, 2020
1 parent 4d86df7 commit ec1bc1f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ import (
"testing"
)

func TestNoDoubleCookie(t *testing.T) {
var n *CSRFHandler
n = New(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
n.RegenerateToken(w, r)
}))

r := httptest.NewRequest("GET", "http://dummy.us", nil)
w := httptest.NewRecorder()

n.ServeHTTP(w, r)

if len(w.Result().Cookies()) > 1 {
t.Errorf("Expected one CSRF cookie, got %d", len(w.Result().Cookies()))
}
}

func TestDefaultFailureHandler(t *testing.T) {
writer := httptest.NewRecorder()
req := dummyGet()
Expand Down

0 comments on commit ec1bc1f

Please sign in to comment.