Mercurial > stress-tester
changeset 442:20d6a963e889
HttpSessionCookieFilter bugfixes + more tests
author | Devel 2 |
---|---|
date | Fri, 28 Jul 2017 10:41:46 +0200 |
parents | 24d9595a4fe2 |
children | c74451bbdc9c |
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, 117 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpSessionCookieFilter.java Fri Jul 28 09:25:18 2017 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpSessionCookieFilter.java Fri Jul 28 10:41:46 2017 +0200 @@ -55,7 +55,7 @@ */ private final Map<ByteString, ByteString> cookiesMap = new ConcurrentHashMap<>(); private final HttpMessageHelper helper = HttpMessageHelper.NOT_STRICT; - private boolean removeInvalidSessionId = true; + private boolean removeInvalidSessionId = false; public HttpSessionCookieFilter() { this.cookieNames = new HashSet<>(DEFAULT_COOKIE_NAMES); @@ -159,8 +159,10 @@ private void deleteMapping(HttpCookie requestCookie, HttpFlowContext context) { ParametersBag oldSession = context.scopes().getSession(requestCookie.getValue().toString()); ByteString oldInValue = (ByteString) oldSession.get(TAG_ORIG_SESSION_ID); - ByteString oldLiveValue = cookiesMap.remove(oldInValue); - LOGGER.debug("Mapping deleted: {} -> {}", oldInValue, oldLiveValue); + if (oldInValue != null) { + ByteString oldLiveValue = cookiesMap.remove(oldInValue); + LOGGER.debug("Mapping deleted: {} -> {}", oldInValue, oldLiveValue); + } }
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpSessionCookieFilterTest.java Fri Jul 28 09:25:18 2017 +0200 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpSessionCookieFilterTest.java Fri Jul 28 10:41:46 2017 +0200 @@ -120,49 +120,132 @@ } @Test - public void testNoCookieInResponse() { - HttpRequest req = HttpRequestBuilder.get("http://test/test").build(); - HttpResponse resp = HttpResponseBuilder.ok() - .cookie("JSESSIONID", "1") + public void testFilter1() { + /** + * req: orig + * origResp: + * resp: newSessId + * + * req: newSessId + */ + + HttpRequest req = HttpRequestBuilder.get("http://test/test") + .cookie("JSESSIONID", "orig") + .build(); + HttpResponse origResp = HttpResponseBuilder.ok().build(); + + HttpResponse respLive = HttpResponseBuilder.ok() + .cookie("JSESSIONID", "newSessId") .build(); - HttpRequest req1 = HttpRequestBuilder.get("http://test/test") - .cookie("JSESSIONID", "1") + HttpRequest req2 = HttpRequestBuilder.get("http://test/test") + .cookie("JSESSIONID", "orig") .build(); - HttpResponse resp1 = HttpResponseBuilder.ok().build(); + HttpResponse origResp2 = HttpResponseBuilder.ok().build(); + + HttpSessionCookieFilter filter = new HttpSessionCookieFilter(); + + when(mockContext.origReponse()).thenReturn(origResp); + filter.filterInbound(req, respLive, mockContext); + filter.filterOutbound(req2, origResp2, mockContext); + + HttpCookie cookie = mh.getCookie(req2, "JSESSIONID"); + assertEquals(cookie.getValue().toString(), "newSessId"); + } + + @Test + public void testFilter2() { + /** + * req: orig + * origResp: + * resp: + * + * req: orig + */ + + HttpRequest req = HttpRequestBuilder.get("http://test/test") + .cookie("JSESSIONID", "orig") + .build(); + HttpResponse origResp = HttpResponseBuilder.ok().build(); + HttpResponse respLive = HttpResponseBuilder.ok().build(); + + HttpRequest req2 = HttpRequestBuilder.get("http://test/test") + .cookie("JSESSIONID", "orig") + .build(); + HttpResponse origResp2 = HttpResponseBuilder.ok().build(); + + HttpSessionCookieFilter filter = new HttpSessionCookieFilter(); - - HttpSessionCookieFilter processor = new HttpSessionCookieFilter("JSESSIONID"); - processor.setRemoveInvalidSessionId(false); - - when(mockContext.origReponse()).thenReturn(null); - processor.filterOutbound(req, null, mockContext); - processor.filterInbound(req, resp, mockContext); + when(mockContext.origReponse()).thenReturn(origResp); + filter.filterInbound(req, respLive, mockContext); + filter.filterOutbound(req2, origResp2, mockContext); - processor.filterOutbound(req1, null, mockContext); - processor.filterInbound(req1, resp1, mockContext); + HttpCookie cookie = mh.getCookie(req2, "JSESSIONID"); + assertEquals(cookie.getValue().toString(), "orig"); + } - //assertEquals(resp1.getTag(TAG_SESSION_ID), "1"); + @Test + public void testFilter3() { + /** + * req: + * origResp: + * resp: newSessId + * + * req: + */ + + HttpRequest req = HttpRequestBuilder.get("http://test/test").build(); + HttpResponse origResp = HttpResponseBuilder.ok().build(); + HttpResponse respLive = HttpResponseBuilder.ok() + .cookie("JSESSIONID", "newSessId") + .build(); + + HttpRequest req2 = HttpRequestBuilder.get("http://test/test").build(); + HttpResponse origResp2 = HttpResponseBuilder.ok().build(); + + HttpSessionCookieFilter filter = new HttpSessionCookieFilter(); + + when(mockContext.origReponse()).thenReturn(origResp); + filter.filterInbound(req, respLive, mockContext); + filter.filterOutbound(req2, origResp2, mockContext); + + HttpCookie cookie = mh.getCookie(req2, "JSESSIONID"); + assertNull(cookie); } @Test - public void test() { + public void testFilter4() { + /** + * req: orig + * resp: newSessId + * origResp: origNew + * + * req: newSessId (origNew) + */ + HttpRequest req = HttpRequestBuilder.get("http://test/test") - .cookie("JSESSIONID", "oldValue") + .cookie("JSESSIONID", "orig") .build(); - HttpResponse respIn = HttpResponseBuilder.ok().build(); + HttpResponse origResp = HttpResponseBuilder.ok() + .cookie("JSESSIONID", "origNew") + .build(); HttpResponse respLive = HttpResponseBuilder.ok() - .cookie("JSESSIONID", "newValue") + .cookie("JSESSIONID", "newSessId") .build(); - + + HttpRequest req2 = HttpRequestBuilder.get("http://test/test") + .cookie("JSESSIONID", "origNew") + .build(); + HttpResponse origResp2 = HttpResponseBuilder.ok().build(); + HttpSessionCookieFilter filter = new HttpSessionCookieFilter(); - filter.setRemoveInvalidSessionId(false); - - when(mockContext.origReponse()).thenReturn(respIn); + + when(mockContext.origReponse()).thenReturn(origResp); filter.filterInbound(req, respLive, mockContext); - filter.filterOutbound(req, respLive, mockContext); - - HttpCookie cookie = mh.getCookie(req, "JSESSIONID"); - assertEquals(cookie.getValue().toString(), "newValue"); + filter.filterOutbound(req2, origResp2, mockContext); + + HttpCookie cookie = mh.getCookie(req2, "JSESSIONID"); + assertEquals(cookie.getValue().toString(), "newSessId"); } + }