diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/HC4CookieHandler.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/HC4CookieHandler.java index 990b33ecca0..276d9134a31 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/HC4CookieHandler.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/HC4CookieHandler.java @@ -18,6 +18,7 @@ package org.apache.jmeter.protocol.http.control; import java.net.URL; +import java.time.Instant; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -228,7 +229,14 @@ List getCookiesForUrl( CookieOrigin cookieOrigin = new CookieOrigin(host, port, path, secure); List cookiesValid = new ArrayList<>(); + // #6428 Cookies must not be sent after they reached their expiry time. + // The cookie specs used here do not check the expiry date in match(), + // so expired cookies have to be filtered out explicitly. + Date now = Date.from(Instant.now()); for (org.apache.http.cookie.Cookie cookie : cookies) { + if (cookie.isExpired(now)) { + continue; + } if (cookieSpec.match(cookie, cookieOrigin)) { cookiesValid.add(cookie); } diff --git a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestHC4CookieManager.java b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestHC4CookieManager.java index 8b242540a47..14bd09959b2 100644 --- a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestHC4CookieManager.java +++ b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestHC4CookieManager.java @@ -259,6 +259,27 @@ public void testOldCookie() throws Exception { assertNull(s); } + // Test cookie that was valid when received is not sent anymore + // once its expiry time has passed (#6428) + @Test + public void testCookieExpiredAfterReceptionIsNotSent() throws Exception { + URL url = new URL("http://a.b.c/"); + man.addCookieFromHeader("test=1; expires=Wed, 01-Jan-2099 00:00:00 GMT", url); + assertEquals(1, man.getCookieCount()); + assertEquals("test=1", man.getCookieHeaderForURL(url)); + // Simulate the passing of time: the cookie is expired by now + man.get(0).setExpires(System.currentTimeMillis() / 1000L - 3600L); + assertNull(man.getCookieHeaderForURL(url), "expired cookie must not be sent"); + } + + // Test session cookie (no expiry date) is still sent + @Test + public void testSessionCookieWithoutExpiryIsStillSent() throws Exception { + URL url = new URL("http://a.b.c/"); + man.addCookieFromHeader("test=1", url); + assertEquals("test=1", man.getCookieHeaderForURL(url)); + } + // Test New cookie is returned @Test public void testNewCookie() throws Exception { diff --git a/xdocs/changes.xml b/xdocs/changes.xml index 13e0d097e6d..b96031cd69c 100644 --- a/xdocs/changes.xml +++ b/xdocs/changes.xml @@ -58,9 +58,20 @@ Summary

+ + +Incompatible changes + + Changes

General