diff --git a/jira.go b/jira.go index 49a1685..d888fe7 100644 --- a/jira.go +++ b/jira.go @@ -375,7 +375,10 @@ func (t *CookieAuthTransport) RoundTrip(req *http.Request) (*http.Response, erro req2 := cloneRequest(req) // per RoundTripper contract for _, cookie := range t.SessionObject { - req2.AddCookie(cookie) + // Don't add an empty value cookie to the request + if cookie.Value != "" { + req2.AddCookie(cookie) + } } return t.transport().RoundTrip(req2) diff --git a/jira_test.go b/jira_test.go index 32c6ea3..c9ef615 100644 --- a/jira_test.go +++ b/jira_test.go @@ -544,6 +544,42 @@ func TestCookieAuthTransport_SessionObject_Exists(t *testing.T) { basicAuthClient.Do(req, nil) } +// Test that an empty cookie in the transport is not returned in the header +func TestCookieAuthTransport_SessionObject_ExistsWithEmptyCookie(t *testing.T) { + setup() + defer teardown() + + emptyCookie := &http.Cookie{Name: "empty_cookie", Value: ""} + testCookie := &http.Cookie{Name: "test", Value: "test"} + + testMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + cookies := r.Cookies() + + if len(cookies) > 1 { + t.Errorf("The empty cookie should not have been added") + } + + if cookies[0].Name != testCookie.Name { + t.Errorf("Cookie names don't match, expected %v, got %v", testCookie.Name, cookies[0].Name) + } + + if cookies[0].Value != testCookie.Value { + t.Errorf("Cookie values don't match, expected %v, got %v", testCookie.Value, cookies[0].Value) + } + }) + + tp := &CookieAuthTransport{ + Username: "username", + Password: "password", + AuthURL: "https://some.jira.com/rest/auth/1/session", + SessionObject: []*http.Cookie{emptyCookie, testCookie}, + } + + basicAuthClient, _ := NewClient(tp.Client(), testServer.URL) + req, _ := basicAuthClient.NewRequest("GET", ".", nil) + basicAuthClient.Do(req, nil) +} + // Test that if no cookie is in the transport, it checks for a cookie func TestCookieAuthTransport_SessionObject_DoesNotExist(t *testing.T) { setup()