mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-03-19 20:57:47 +02:00
Check for empty cookies for CookieAuthTransport
Don't add empty cookie values to the session object for CookieAuthTransport
This commit is contained in:
parent
2e3f247e48
commit
e3036dab2f
5
jira.go
5
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)
|
||||
|
36
jira_test.go
36
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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user