Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 90 additions & 23 deletions src/code.cloudfoundry.org/gorouter/proxy/session_affinity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ var _ = Describe("Session Affinity with JSESSIONID", func() {
conf.SecureCookies = false

jSessionIdCookie = &http.Cookie{
Name: StickyCookieKey,
Value: "xxx",
MaxAge: 1,
Name: StickyCookieKey,
Value: "xxx",
}
})

Expand Down Expand Up @@ -167,29 +166,38 @@ var _ = Describe("Session Affinity with JSESSIONID", func() {

Context("when the response contains a JSESSIONID cookie", func() {

It("responds with a VCAP_ID cookie scoped to the session", func() {
ln := test_util.RegisterConnHandler(r, "app", responseWithJSessionID, test_util.RegisterConfig{InstanceId: "my-id"})
defer ln.Close()
Context("and JSESSIONID cookie is a session cookie", func() {
var expiry time.Time

x := dialProxy(proxyServer)
req := test_util.NewRequest("GET", "app", "/", nil)
x.WriteRequest(req)
BeforeEach(func() {
jSessionIdCookie.Expires = expiry
jSessionIdCookie.MaxAge = 0
})

Eventually(done).Should(Receive())
It("responds with a VCAP_ID cookie scoped to the session", func() {
ln := test_util.RegisterConnHandler(r, "app", responseWithJSessionID, test_util.RegisterConfig{InstanceId: "my-id"})
defer ln.Close()

resp, _ := x.ReadResponse()
jsessionId := getCookie(StickyCookieKey, resp.Cookies())
Expect(jsessionId).ToNot(BeNil())
x := dialProxy(proxyServer)
req := test_util.NewRequest("GET", "app", "/", nil)
x.WriteRequest(req)

cookie := getCookie(handlers.VcapCookieId, resp.Cookies())
Expect(cookie).ToNot(BeNil())
Expect(cookie.Value).To(Equal("my-id"))
Expect(cookie.Secure).To(BeFalse())
Expect(cookie.MaxAge).To(BeZero())
Expect(cookie.Expires).To(BeZero())
Eventually(done).Should(Receive())

resp, _ := x.ReadResponse()
jsessionId := getCookie(StickyCookieKey, resp.Cookies())
Expect(jsessionId).ToNot(BeNil())

cookie := getCookie(handlers.VcapCookieId, resp.Cookies())
Expect(cookie).ToNot(BeNil())
Expect(cookie.Value).To(Equal("my-id"))
Expect(cookie.Secure).To(BeFalse())
Expect(cookie.MaxAge).To(BeZero())
Expect(cookie.Expires).To(BeZero())
})
})

Context("and the JSESSIONID cookie has an expiry date", func() {
Context("and JSESSIONID cookie has an expiry date", func() {
var expiry time.Time

BeforeEach(func() {
Expand Down Expand Up @@ -217,13 +225,71 @@ var _ = Describe("Session Affinity with JSESSIONID", func() {
})
})

Context("and JSESSIONID cookie has MaxAge < 0", func() {

BeforeEach(func() {
jSessionIdCookie.MaxAge = -1
})

It("responds with a VCAP_ID cookie with MaxAge set to invalidate", func() {
ln := test_util.RegisterConnHandler(r, "app", responseWithJSessionID, test_util.RegisterConfig{InstanceId: "my-id"})
defer ln.Close()

x := dialProxy(proxyServer)
req := test_util.NewRequest("GET", "app", "/", nil)
x.WriteRequest(req)

Eventually(done).Should(Receive())

resp, _ := x.ReadResponse()
jsessionId := getCookie(StickyCookieKey, resp.Cookies())
Expect(jsessionId).ToNot(BeNil())

cookie := getCookie(handlers.VcapCookieId, resp.Cookies())
Expect(cookie).ToNot(BeNil())
Expect(cookie.Value).To(Equal("my-id"))
Expect(cookie.Secure).To(BeFalse())
Expect(cookie.MaxAge).To(Equal(-1))
Expect(cookie.Expires).To(BeZero())
})
})

Context("and JSESSIONID cookie has MaxAge > 0", func() {

BeforeEach(func() {
jSessionIdCookie.MaxAge = 1
})

It("responds with a VCAP_ID cookie with the same MaxAge", func() {
ln := test_util.RegisterConnHandler(r, "app", responseWithJSessionID, test_util.RegisterConfig{InstanceId: "my-id"})
defer ln.Close()

x := dialProxy(proxyServer)
req := test_util.NewRequest("GET", "app", "/", nil)
x.WriteRequest(req)

Eventually(done).Should(Receive())

resp, _ := x.ReadResponse()
jsessionId := getCookie(StickyCookieKey, resp.Cookies())
Expect(jsessionId).ToNot(BeNil())

cookie := getCookie(handlers.VcapCookieId, resp.Cookies())
Expect(cookie).ToNot(BeNil())
Expect(cookie.Value).To(Equal("my-id"))
Expect(cookie.Secure).To(BeFalse())
Expect(cookie.MaxAge).To(Equal(1))
Expect(cookie.Expires).To(BeZero())
})
})

Context("and JSESSIONID cookie is set to Secure", func() {

BeforeEach(func() {
jSessionIdCookie.Secure = true
})

It("responds with a VCAP_ID cookie that is also Secure ", func() {
It("responds with a VCAP_ID cookie that is also Secure", func() {
ln := test_util.RegisterConnHandler(r, "app", responseWithJSessionID, test_util.RegisterConfig{InstanceId: "my-id"})
defer ln.Close()

Expand All @@ -244,13 +310,13 @@ var _ = Describe("Session Affinity with JSESSIONID", func() {
})
})

Context("with secure cookies enabled and non-secure cookie", func() {
Context("and secure cookies are enabled with non-secure JSESSIONID cookie", func() {
BeforeEach(func() {
conf.SecureCookies = true
jSessionIdCookie.Secure = false
})

It("marks the cookie as secure only", func() {
It("responds with a VCAP_ID cookie that is marked as secure", func() {
ln := test_util.RegisterConnHandler(r, "app", responseWithJSessionID, test_util.RegisterConfig{InstanceId: "my-id"})
defer ln.Close()

Expand Down Expand Up @@ -391,6 +457,7 @@ var _ = Describe("Session Affinity with JSESSIONID", func() {
Context("when the JSESSIONID is expired", func() {
BeforeEach(func() {
jSessionIdCookie.MaxAge = -1

})

It("expires the VCAP_ID", func() {
Expand Down