changeset 435:657042d50537

HttpSessionCookieFilter improvements
author Devel 2
date Thu, 27 Jul 2017 15:49:56 +0200
parents dbbac526c4a0
children 80f236c7b75e
files stress-tester/src/main/java/com/passus/st/client/http/filter/HttpSessionCookieFilter.java stress-tester/src/test/java/com/passus/st/client/http/filter/HttpSessionCookieFilterTest.java
diffstat 2 files changed, 38 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpSessionCookieFilter.java	Thu Jul 27 14:59:15 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpSessionCookieFilter.java	Thu Jul 27 15:49:56 2017 +0200
@@ -84,6 +84,10 @@
     }
 
     private HttpCookie findSessionCookie(HttpMessage msg) {
+        if (msg == null) {
+            return null;
+        }
+
         HttpCookie sessionCookie = null;
         for (CharSequence cookieName : cookieNames) {
             sessionCookie = helper.getCookie(msg, cookieName);
@@ -116,6 +120,8 @@
             } else if (removeInvalidSessionId) {
                 helper.removeCookie(pcapRequest, requestCookie.getName());
                 LOGGER.debug("No mapping for {} [{}]", inValue, pcapRequest.getUrl());
+            } else {
+                setTag(pcapRequest, TAG_SESSION_ID, requestCookie.getValue().toString());
             }
         }
 
@@ -147,6 +153,11 @@
                 session.set(TAG_ORIG_SESSION_ID, inValue);
                 LOGGER.debug("Mapping created: {} -> {} [{}]", inValue, liveValue, modifiedRequest.getUrl());
             }
+        } else {
+            String sessionId = (String) modifiedRequest.getTag(TAG_SESSION_ID);
+            if (sessionId != null) {
+                realResponse.setTag(TAG_SESSION_ID, sessionId);
+            }
         }
 
         return DUNNO;
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpSessionCookieFilterTest.java	Thu Jul 27 14:59:15 2017 +0200
+++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpSessionCookieFilterTest.java	Thu Jul 27 15:49:56 2017 +0200
@@ -2,7 +2,9 @@
 
 import com.passus.net.http.HttpMessageHelper;
 import com.passus.net.http.HttpRequest;
+import com.passus.net.http.HttpRequestBuilder;
 import com.passus.net.http.HttpResponse;
+import com.passus.net.http.HttpResponseBuilder;
 import static com.passus.st.client.http.HttpConsts.TAG_SESSION_ID;
 import com.passus.st.client.http.HttpFlowContext;
 import com.passus.st.client.http.HttpScopes;
@@ -137,4 +139,29 @@
         assertEquals(mh.getCookie(req3, cookieName).getValue().toString(), "real_post");
     }
 
+    @Test
+    public void testNoCookieInResponse() {
+        HttpRequest req = HttpRequestBuilder.get("http://test/test").build();
+        HttpResponse resp = HttpResponseBuilder.ok()
+                .cookie("JSESSIONID", "1")
+                .build();
+
+        HttpRequest req1 = HttpRequestBuilder.get("http://test/test")
+                .cookie("JSESSIONID", "1")
+                .build();
+        HttpResponse resp1 = HttpResponseBuilder.ok().build();
+        
+       
+        HttpSessionCookieFilter processor = new HttpSessionCookieFilter("JSESSIONID");
+        processor.setRemoveInvalidSessionId(false);
+        
+        when(mockContext.origReponse()).thenReturn(null);
+        processor.filterOutbound(req, null, mockContext);
+        processor.filterInbound(req, resp, mockContext);
+
+        processor.filterOutbound(req1, null, mockContext);
+        processor.filterInbound(req1, resp1, mockContext);
+
+        //assertEquals(resp1.getTag(TAG_SESSION_ID), "1");
+    }
 }