You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by mo...@apache.org on 2023/01/18 20:05:11 UTC
[knox] branch master updated: KNOX-2863 - Fix an issue where session cookie order in LB feature breaks (#715)
This is an automated email from the ASF dual-hosted git repository.
more pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git
The following commit(s) were added to refs/heads/master by this push:
new 481c8db83 KNOX-2863 - Fix an issue where session cookie order in LB feature breaks (#715)
481c8db83 is described below
commit 481c8db838884ba9842fc1f7d3f0f4cd83a96164
Author: Sandeep Moré <mo...@gmail.com>
AuthorDate: Wed Jan 18 15:05:05 2023 -0500
KNOX-2863 - Fix an issue where session cookie order in LB feature breaks (#715)
---
.../ha/dispatch/ConfigurableHADispatch.java | 4 +-
.../gateway/ha/dispatch/DefaultHaDispatchTest.java | 48 +++++++++++++++++++++-
2 files changed, 48 insertions(+), 4 deletions(-)
diff --git a/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/ConfigurableHADispatch.java b/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/ConfigurableHADispatch.java
index 5497ea2f4..d73139015 100644
--- a/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/ConfigurableHADispatch.java
+++ b/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/ConfigurableHADispatch.java
@@ -289,8 +289,8 @@ public class ConfigurableHADispatch extends ConfigurableDispatch {
if (inboundRequest.getCookies() != null) {
sessionCookie =
Arrays.stream(inboundRequest.getCookies())
- .findFirst()
- .filter(cookie -> stickySessionCookieName.equals(cookie.getName()));
+ .filter(cookie -> stickySessionCookieName.equals(cookie.getName()))
+ .findFirst();
}
// Check for a case where no fallback is configured
diff --git a/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/dispatch/DefaultHaDispatchTest.java b/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/dispatch/DefaultHaDispatchTest.java
index 1206fdeec..1545f0a24 100644
--- a/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/dispatch/DefaultHaDispatchTest.java
+++ b/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/dispatch/DefaultHaDispatchTest.java
@@ -574,7 +574,42 @@ public class DefaultHaDispatchTest {
doTestFailoverStickyOnFallbackOff(true);
}
+ /**
+ * Test whether order of sticky session cookie matters.
+ * Test the case where loadbalancing is on, sticky sessions is on, fallback is disabled, and the initial request
+ * fails AND session cookie is not first.
+ *
+ * Expected behavior: Failover should occur until the initial session has been established, regardless of the
+ * noFallback setting.
+ *
+ * KNOX-2619
+ */
+ @Test
+ public void testFailoverStickyOnFallbackOff_SessionCookieOrder() throws Exception {
+ Cookie [] sessionCookieFirst = new Cookie[3];
+ sessionCookieFirst[0] = new Cookie(HaServiceConfigConstants.DEFAULT_STICKY_SESSION_COOKIE_NAME + "-" + "OOZIE",
+ "59973e253ae20de796c6ef413608ec1c80fca24310a4cbdecc0ff97aeea55745");
+ sessionCookieFirst[1] = new Cookie("Test1", "Test1");
+ sessionCookieFirst[2] = new Cookie("Test2", "Test2");
+
+ Cookie [] sessionCookieLast = new Cookie[3];
+ sessionCookieLast[2] = new Cookie(HaServiceConfigConstants.DEFAULT_STICKY_SESSION_COOKIE_NAME + "-" + "OOZIE",
+ "59973e253ae20de796c6ef413608ec1c80fca24310a4cbdecc0ff97aeea55745");
+ sessionCookieLast[1] = new Cookie("Test1", "Test1");
+ sessionCookieLast[0] = new Cookie("Test2", "Test2");
+
+ /* Test when session cookie is first */
+ doTestFailoverStickyOnFallbackOff(true, sessionCookieFirst);
+ /* Test when session cookie is last */
+ doTestFailoverStickyOnFallbackOff(true, sessionCookieLast);
+ }
+
private void doTestFailoverStickyOnFallbackOff(final Boolean withCookie)
+ throws Exception {
+ doTestFailoverStickyOnFallbackOff(withCookie, null);
+ }
+
+ private void doTestFailoverStickyOnFallbackOff(final Boolean withCookie, final Cookie[] cookies)
throws Exception {
final String enableLoadBalancing = "true"; // load-balancing is required for sticky sessions to be enabled
final String enableStickySession = "true";
@@ -624,10 +659,19 @@ public class DefaultHaDispatchTest {
EasyMock.expect(inboundRequest.getAttribute("dispatch.ha.failover.counter")).andReturn(new AtomicInteger(0)).once();
EasyMock.expect(inboundRequest.getAttribute("dispatch.ha.failover.counter")).andReturn(new AtomicInteger(1)).once();
if (withCookie) {
+ Cookie[] responseCookies;
+ Cookie sessionCookie = new Cookie(HaServiceConfigConstants.DEFAULT_STICKY_SESSION_COOKIE_NAME + "-" + serviceName,
+ "59973e253ae20de796c6ef413608ec1c80fca24310a4cbdecc0ff97aeea55745");
+ if(cookies != null && cookies.length > 0) {
+ /* Add provided cookies */
+ responseCookies = cookies;
+ } else {
+ responseCookies = new Cookie[] {sessionCookie};
+ }
+
inboundRequest.getCookies();
EasyMock.expectLastCall()
- .andReturn(new Cookie[] { new Cookie(HaServiceConfigConstants.DEFAULT_STICKY_SESSION_COOKIE_NAME + "-" + serviceName,
- "59973e253ae20de796c6ef413608ec1c80fca24310a4cbdecc0ff97aeea55745") })
+ .andReturn(responseCookies)
.anyTimes();
} else {
EasyMock.expect(inboundRequest.getCookies()).andReturn(null).anyTimes();