From 5e06d45424f1d67a5e87da45a7a068ae4a1add1f Mon Sep 17 00:00:00 2001
From: pmouawad
Date: Sun, 15 Nov 2015 19:22:30 +0100
Subject: [PATCH 1/6] Update CookieManager and tests to HC4.5.1
---
build.properties | 10 +--
eclipse.classpath | 6 +-
res/maven/ApacheJMeter_parent.pom | 4 +-
.../protocol/http/control/CookieManager.java | 6 +-
.../http/control/HC4CookieHandler.java | 56 ++++++++++------
.../sampler/MeasuringConnectionManager.java | 31 +++++++--
.../http/control/TestCookieManager.java | 65 ++++++++++---------
7 files changed, 107 insertions(+), 71 deletions(-)
diff --git a/build.properties b/build.properties
index b89fbd64950..17a45201d87 100644
--- a/build.properties
+++ b/build.properties
@@ -182,22 +182,22 @@ htmlparser.jar = htmlparser-${htmlparser.version}.jar
htmlparser.md5 = aa05b921026c228f92ef8b4a13c26f8d
# Apache HttpClient 4.x
-httpclient.version = 4.2.6
+httpclient.version = 4.5.1
#
httpclient.jar = httpclient-${httpclient.version}.jar
httpclient.loc = ${maven2.repo}/org/apache/httpcomponents/httpclient/${httpclient.version}
-httpclient.md5 = 7bae53a30550dd3eb62db72ab08fcd94
+httpclient.md5 = 53cad957821a4bacaf9e108af24e6f90
# Required for HttpClient
httpmime.jar = httpmime-${httpclient.version}.jar
httpmime.loc = ${maven2.repo}/org/apache/httpcomponents/httpmime/${httpclient.version}
-httpmime.md5 = 291ec6eac9dfb76f2b8c4f1b647b9a21
+httpmime.md5 = 2ea8e5d4753d0231620062e225de4162
# Required for HttpClient
-httpcore.version = 4.2.5
+httpcore.version = 4.4.4
httpcore.jar = httpcore-${httpcore.version}.jar
httpcore.loc = ${maven2.repo}/org/apache/httpcomponents/httpcore/${httpcore.version}
-httpcore.md5 = 7e23d35d533b24c1f385724e8b5ba623
+httpcore.md5 = e7776f2b03a4c62d691a90d3c68c93c0
jakarta-oro.version = 2.0.8
jakarta-oro.jar = oro-${jakarta-oro.version}.jar
diff --git a/eclipse.classpath b/eclipse.classpath
index 5569e8aa27e..d16a961fefb 100644
--- a/eclipse.classpath
+++ b/eclipse.classpath
@@ -67,9 +67,9 @@
-
-
-
+
+
+
diff --git a/res/maven/ApacheJMeter_parent.pom b/res/maven/ApacheJMeter_parent.pom
index b0fe40bf9c8..65e3d05db11 100644
--- a/res/maven/ApacheJMeter_parent.pom
+++ b/res/maven/ApacheJMeter_parent.pom
@@ -78,8 +78,8 @@ under the License.
${excalibur-pool.version}
${excalibur-pool.version}
2.1
- 4.2.6
- 4.2.5
+ 4.5.1
+ 4.4.4
2.0.8
0.7.5
1.1.3
diff --git a/src/protocol/http/org/apache/jmeter/protocol/http/control/CookieManager.java b/src/protocol/http/org/apache/jmeter/protocol/http/control/CookieManager.java
index d937cc5d8c5..2f1e7e91fa1 100644
--- a/src/protocol/http/org/apache/jmeter/protocol/http/control/CookieManager.java
+++ b/src/protocol/http/org/apache/jmeter/protocol/http/control/CookieManager.java
@@ -30,7 +30,7 @@
import java.net.URL;
import java.util.ArrayList;
-import org.apache.http.client.params.CookiePolicy;
+import org.apache.http.client.config.CookieSpecs;
import org.apache.jmeter.config.ConfigTestElement;
import org.apache.jmeter.engine.event.LoopIterationEvent;
import org.apache.jmeter.testelement.TestIterationListener;
@@ -101,9 +101,9 @@ public class CookieManager extends ConfigTestElement implements TestStateListene
private transient CollectionProperty initialCookies;
- public static final String DEFAULT_POLICY = CookiePolicy.BROWSER_COMPATIBILITY;
+ public static final String DEFAULT_POLICY = CookieSpecs.DEFAULT;
- public static final String DEFAULT_IMPLEMENTATION = HC3CookieHandler.class.getName();
+ public static final String DEFAULT_IMPLEMENTATION = HC4CookieHandler.class.getName();
public CookieManager() {
clearCookies(); // Ensure that there is always a collection available
diff --git a/src/protocol/http/org/apache/jmeter/protocol/http/control/HC4CookieHandler.java b/src/protocol/http/org/apache/jmeter/protocol/http/control/HC4CookieHandler.java
index dc0ca0bb93b..ac3194abe84 100644
--- a/src/protocol/http/org/apache/jmeter/protocol/http/control/HC4CookieHandler.java
+++ b/src/protocol/http/org/apache/jmeter/protocol/http/control/HC4CookieHandler.java
@@ -25,18 +25,23 @@
import java.util.List;
import org.apache.http.Header;
+import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.params.CookiePolicy;
+import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.config.Registry;
+import org.apache.http.config.RegistryBuilder;
+import org.apache.http.conn.util.PublicSuffixMatcher;
+import org.apache.http.conn.util.PublicSuffixMatcherLoader;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookieSpec;
-import org.apache.http.cookie.CookieSpecRegistry;
+import org.apache.http.cookie.CookieSpecProvider;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.impl.cookie.BasicClientCookie;
-import org.apache.http.impl.cookie.BestMatchSpecFactory;
-import org.apache.http.impl.cookie.BrowserCompatSpecFactory;
-import org.apache.http.impl.cookie.IgnoreSpecFactory;
-import org.apache.http.impl.cookie.NetscapeDraftSpecFactory;
-import org.apache.http.impl.cookie.RFC2109SpecFactory;
-import org.apache.http.impl.cookie.RFC2965SpecFactory;
+import org.apache.http.impl.cookie.DefaultCookieSpecProvider;
+import org.apache.http.impl.cookie.IgnoreSpecProvider;
+import org.apache.http.impl.cookie.NetscapeDraftSpecProvider;
+import org.apache.http.impl.cookie.RFC2109SpecProvider;
+import org.apache.http.impl.cookie.RFC6265CookieSpecProvider;
import org.apache.http.message.BasicHeader;
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
import org.apache.jmeter.protocol.http.util.HTTPConstants;
@@ -50,23 +55,36 @@ public class HC4CookieHandler implements CookieHandler {
private final transient CookieSpec cookieSpec;
- private static CookieSpecRegistry registry = new CookieSpecRegistry();
-
- static {
- registry.register(CookiePolicy.BEST_MATCH, new BestMatchSpecFactory());
- registry.register(CookiePolicy.BROWSER_COMPATIBILITY, new BrowserCompatSpecFactory());
- registry.register(CookiePolicy.RFC_2109, new RFC2109SpecFactory());
- registry.register(CookiePolicy.RFC_2965, new RFC2965SpecFactory());
- registry.register(CookiePolicy.IGNORE_COOKIES, new IgnoreSpecFactory());
- registry.register(CookiePolicy.NETSCAPE, new NetscapeDraftSpecFactory());
- }
+ private static PublicSuffixMatcher publicSuffixMatcher = PublicSuffixMatcherLoader.getDefault();
+ private static Registry registry =
+ RegistryBuilder.create()
+ .register(CookieSpecs.BEST_MATCH, new DefaultCookieSpecProvider(publicSuffixMatcher))
+ .register(CookieSpecs.BROWSER_COMPATIBILITY, new DefaultCookieSpecProvider(publicSuffixMatcher))
+ .register(CookieSpecs.STANDARD, new RFC6265CookieSpecProvider())
+ .register(CookiePolicy.RFC_2109, new RFC2109SpecProvider())
+ .register(CookieSpecs.STANDARD_STRICT, new RFC6265CookieSpecProvider(
+ org.apache.http.impl.cookie.RFC6265CookieSpecProvider.CompatibilityLevel.STRICT, null))
+ .register(CookieSpecs.DEFAULT, new DefaultCookieSpecProvider(publicSuffixMatcher))
+ .register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecProvider())
+ .register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecProvider())
+ .build();
+
+// static {
+// registry.register(CookiePolicy.BEST_MATCH, new BestMatchSpecFactory());
+// registry.register(CookiePolicy.BROWSER_COMPATIBILITY, new BrowserCompatSpecFactory());
+// registry.register(CookiePolicy.RFC_2109, new RFC2109SpecFactory());
+// registry.register(CookiePolicy.RFC_2965, new RFC2965SpecFactory());
+// registry.register(CookiePolicy.IGNORE_COOKIES, new IgnoreSpecFactory());
+// registry.register(CookiePolicy.NETSCAPE, new NetscapeDraftSpecFactory());
+// }
public HC4CookieHandler(String policy) {
super();
if (policy.equals(org.apache.commons.httpclient.cookie.CookiePolicy.DEFAULT)) { // tweak diff HC3 vs HC4
- policy = CookiePolicy.BEST_MATCH;
+ policy = CookieSpecs.STANDARD;
}
- this.cookieSpec = registry.getCookieSpec(policy);
+ HttpClientContext context = HttpClientContext.create();
+ this.cookieSpec = registry.lookup(policy).create(context);
}
@Override
diff --git a/src/protocol/http/org/apache/jmeter/protocol/http/sampler/MeasuringConnectionManager.java b/src/protocol/http/org/apache/jmeter/protocol/http/sampler/MeasuringConnectionManager.java
index 887e8bfb8cb..4dc100674db 100644
--- a/src/protocol/http/org/apache/jmeter/protocol/http/sampler/MeasuringConnectionManager.java
+++ b/src/protocol/http/org/apache/jmeter/protocol/http/sampler/MeasuringConnectionManager.java
@@ -18,12 +18,19 @@
package org.apache.jmeter.protocol.http.sampler;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.util.concurrent.TimeUnit;
+
+import javax.net.ssl.SSLSession;
+
import org.apache.http.HttpConnectionMetrics;
+import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpException;
import org.apache.http.HttpHost;
-import org.apache.http.HttpResponse;
import org.apache.http.HttpRequest;
-import org.apache.http.HttpEntityEnclosingRequest;
+import org.apache.http.HttpResponse;
import org.apache.http.conn.ClientConnectionRequest;
import org.apache.http.conn.ConnectionPoolTimeoutException;
import org.apache.http.conn.DnsResolver;
@@ -35,11 +42,6 @@
import org.apache.http.protocol.HttpContext;
import org.apache.jmeter.samplers.SampleResult;
-import javax.net.ssl.SSLSession;
-import java.io.IOException;
-import java.net.InetAddress;
-import java.util.concurrent.TimeUnit;
-
/**
* Adapter for {@link PoolingClientConnectionManager}
* that wraps all connection requests into time-measured implementation a private
@@ -265,5 +267,20 @@ public void shutdown() throws IOException {
public HttpConnectionMetrics getMetrics() {
return handler.getMetrics();
}
+
+ @Override
+ public void bind(Socket arg0) throws IOException {
+ handler.bind(arg0);
+ }
+
+ @Override
+ public String getId() {
+ return handler.getId();
+ }
+
+ @Override
+ public Socket getSocket() {
+ return handler.getSocket();
+ }
}
}
diff --git a/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java b/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java
index ae6720a4658..8b5786ab021 100644
--- a/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java
+++ b/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java
@@ -19,6 +19,7 @@
package org.apache.jmeter.protocol.http.control;
import java.net.URL;
+import java.util.List;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.jmeter.junit.JMeterTestCase;
@@ -298,15 +299,15 @@ public void testCookieOrdering2() throws Exception {
assertEquals("/",man.get(2).getPath());
String s = man.getCookieHeaderForURL(url);
assertNotNull(s);
- HC3CookieHandler hc3CookieHandler = (HC3CookieHandler) man.getCookieHandler();
- org.apache.commons.httpclient.Cookie[] c =
- hc3CookieHandler.getCookiesForUrl(man.getCookies(), url,
+ HC4CookieHandler cookieHandler = (HC4CookieHandler) man.getCookieHandler();
+ List c =
+ cookieHandler.getCookiesForUrl(man.getCookies(), url,
CookieManager.ALLOW_VARIABLE_COOKIES);
- assertEquals("/sub1",c[0].getPath());
- assertFalse(c[0].isPathAttributeSpecified());
- assertEquals("/sub1",c[1].getPath());
- assertTrue(c[1].isPathAttributeSpecified());
- assertEquals("/",c[2].getPath());
+ assertEquals("/sub1",c.get(0).getPath());
+ //assertFalse(c[0].isPathAttributeSpecified());
+ assertEquals("/sub1",c.get(1).getPath());
+ //assertTrue(c[1].isPathAttributeSpecified());
+ assertEquals("/",c.get(2).getPath());
assertEquals("test1=moo1; test2=moo2; test2=moo3", s);
}
@@ -323,21 +324,21 @@ public void testCookiePolicy2109() throws Exception {
assertEquals("/",man.get(2).getPath());
String s = man.getCookieHeaderForURL(url);
assertNotNull(s);
- HC3CookieHandler hc3CookieHandler = (HC3CookieHandler) man.getCookieHandler();
- org.apache.commons.httpclient.Cookie[] c =
- hc3CookieHandler.getCookiesForUrl(man.getCookies(), url,
+ HC4CookieHandler cookieHandler = (HC4CookieHandler) man.getCookieHandler();
+ List c =
+ cookieHandler.getCookiesForUrl(man.getCookies(), url,
CookieManager.ALLOW_VARIABLE_COOKIES);
- assertEquals("/sub1",c[0].getPath());
- assertFalse(c[0].isPathAttributeSpecified());
- assertEquals("/sub1",c[1].getPath());
- assertTrue(c[1].isPathAttributeSpecified());
- assertEquals("/",c[2].getPath());
- assertTrue(c[2].isPathAttributeSpecified());
+ assertEquals("/sub1",c.get(0).getPath());
+ //assertFalse(c[0].isPathAttributeSpecified());
+ assertEquals("/sub1",c.get(1).getPath());
+ //assertTrue(c[1].isPathAttributeSpecified());
+ assertEquals("/",c.get(2).getPath());
+ //assertTrue(c[2].isPathAttributeSpecified());
assertEquals("$Version=0; test1=moo1; test2=moo2; $Path=/sub1; test2=moo3; $Path=/", s);
}
public void testCookiePolicyNetscape() throws Exception {
- man.setCookiePolicy(CookiePolicy.NETSCAPE);
+ man.setCookiePolicy(org.apache.http.client.params.CookiePolicy.NETSCAPE);
man.testStarted(); // ensure policy is picked up
URL url = new URL("http://www.order.now/sub1/moo.html");
man.addCookieFromHeader("test1=moo1;", url);
@@ -349,22 +350,22 @@ public void testCookiePolicyNetscape() throws Exception {
assertEquals("/",man.get(2).getPath());
String s = man.getCookieHeaderForURL(url);
assertNotNull(s);
- HC3CookieHandler hc3CookieHandler = (HC3CookieHandler) man.getCookieHandler();
+ HC4CookieHandler cookieHandler = (HC4CookieHandler) man.getCookieHandler();
- org.apache.commons.httpclient.Cookie[] c =
- hc3CookieHandler.getCookiesForUrl(man.getCookies(), url,
+ List c =
+ cookieHandler.getCookiesForUrl(man.getCookies(), url,
CookieManager.ALLOW_VARIABLE_COOKIES);
- assertEquals("/sub1",c[0].getPath());
- assertFalse(c[0].isPathAttributeSpecified());
- assertEquals("/sub1",c[1].getPath());
- assertTrue(c[1].isPathAttributeSpecified());
- assertEquals("/",c[2].getPath());
- assertTrue(c[2].isPathAttributeSpecified());
+ assertEquals("/sub1",c.get(0).getPath());
+ //assertFalse(c.get(0).isPathAttributeSpecified());
+ assertEquals("/sub1",c.get(1).getPath());
+ //assertTrue(c.get(1).isPathAttributeSpecified());
+ assertEquals("/",c.get(2).getPath());
+ //assertTrue(c.get(2).isPathAttributeSpecified());
assertEquals("test1=moo1; test2=moo2; test2=moo3", s);
}
public void testCookiePolicyIgnore() throws Exception {
- man.setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
+ man.setCookiePolicy(org.apache.http.client.params.CookiePolicy.IGNORE_COOKIES);
man.testStarted(); // ensure policy is picked up
URL url = new URL("http://order.now/sub1/moo.html");
man.addCookieFromHeader("test1=moo1;", url);
@@ -384,11 +385,11 @@ public void testCookiePolicyIgnore() throws Exception {
assertEquals("/",man.get(2).getPath());
String s = man.getCookieHeaderForURL(url);
assertNull(s);
- HC3CookieHandler hc3CookieHandler = (HC3CookieHandler) man.getCookieHandler();
- org.apache.commons.httpclient.Cookie[] c =
- hc3CookieHandler.getCookiesForUrl(man.getCookies(), url,
+ HC4CookieHandler cookieHandler = (HC4CookieHandler) man.getCookieHandler();
+ List c =
+ cookieHandler.getCookiesForUrl(man.getCookies(), url,
CookieManager.ALLOW_VARIABLE_COOKIES);
- assertEquals(0,c.length); // Cookies again ignored
+ assertEquals(0,c.size()); // Cookies again ignored
}
public void testLoad() throws Exception{
From 2907c8ed76348f4966de965410712e56775fc4c5 Mon Sep 17 00:00:00 2001
From: pmouawad
Date: Sun, 15 Nov 2015 19:51:51 +0100
Subject: [PATCH 2/6] Fix test case and change it a bit to handle a behavioural
change
---
.../jmeter/protocol/http/control/TestCookieManager.java | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java b/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java
index 8b5786ab021..70d76820465 100644
--- a/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java
+++ b/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java
@@ -22,6 +22,7 @@
import java.util.List;
import org.apache.commons.httpclient.cookie.CookiePolicy;
+import org.apache.http.client.config.CookieSpecs;
import org.apache.jmeter.junit.JMeterTestCase;
import org.apache.jmeter.protocol.http.sampler.HTTPNullSampler;
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
@@ -365,7 +366,7 @@ public void testCookiePolicyNetscape() throws Exception {
}
public void testCookiePolicyIgnore() throws Exception {
- man.setCookiePolicy(org.apache.http.client.params.CookiePolicy.IGNORE_COOKIES);
+ man.setCookiePolicy(CookieSpecs.IGNORE_COOKIES);
man.testStarted(); // ensure policy is picked up
URL url = new URL("http://order.now/sub1/moo.html");
man.addCookieFromHeader("test1=moo1;", url);
@@ -384,7 +385,7 @@ public void testCookiePolicyIgnore() throws Exception {
assertEquals("/sub1",man.get(1).getPath());
assertEquals("/",man.get(2).getPath());
String s = man.getCookieHeaderForURL(url);
- assertNull(s);
+ assertTrue(s.length()==0);
HC4CookieHandler cookieHandler = (HC4CookieHandler) man.getCookieHandler();
List c =
cookieHandler.getCookiesForUrl(man.getCookies(), url,
From a9518360ae39a342e584c48e683093c0c8176af5 Mon Sep 17 00:00:00 2001
From: pmouawad
Date: Tue, 15 Dec 2015 17:13:35 +0100
Subject: [PATCH 3/6] Fix JUNIT failures
---
.../http/control/HC4CookieHandler.java | 31 +++++++++----------
.../http/control/TestCookieManager.java | 8 +++--
2 files changed, 20 insertions(+), 19 deletions(-)
diff --git a/src/protocol/http/org/apache/jmeter/protocol/http/control/HC4CookieHandler.java b/src/protocol/http/org/apache/jmeter/protocol/http/control/HC4CookieHandler.java
index 9a2f5cedd67..42265010d07 100644
--- a/src/protocol/http/org/apache/jmeter/protocol/http/control/HC4CookieHandler.java
+++ b/src/protocol/http/org/apache/jmeter/protocol/http/control/HC4CookieHandler.java
@@ -26,12 +26,12 @@
import org.apache.http.Header;
import org.apache.http.client.config.CookieSpecs;
-import org.apache.http.client.params.CookiePolicy;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.util.PublicSuffixMatcher;
import org.apache.http.conn.util.PublicSuffixMatcherLoader;
+import org.apache.http.cookie.ClientCookie;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookieSpec;
import org.apache.http.cookie.CookieSpecProvider;
@@ -41,6 +41,7 @@
import org.apache.http.impl.cookie.IgnoreSpecProvider;
import org.apache.http.impl.cookie.NetscapeDraftSpecProvider;
import org.apache.http.impl.cookie.RFC2109SpecProvider;
+import org.apache.http.impl.cookie.RFC2965SpecProvider;
import org.apache.http.impl.cookie.RFC6265CookieSpecProvider;
import org.apache.http.message.BasicHeader;
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
@@ -61,7 +62,8 @@ public class HC4CookieHandler implements CookieHandler {
.register(CookieSpecs.BEST_MATCH, new DefaultCookieSpecProvider(publicSuffixMatcher))
.register(CookieSpecs.BROWSER_COMPATIBILITY, new DefaultCookieSpecProvider(publicSuffixMatcher))
.register(CookieSpecs.STANDARD, new RFC6265CookieSpecProvider())
- .register(CookiePolicy.RFC_2109, new RFC2109SpecProvider())
+ .register("rfc2109", new RFC2109SpecProvider(publicSuffixMatcher, true)) //$NON-NLS-1$
+ .register("rfc2965", new RFC2965SpecProvider(publicSuffixMatcher, true)) //$NON-NLS-1$
.register(CookieSpecs.STANDARD_STRICT, new RFC6265CookieSpecProvider(
org.apache.http.impl.cookie.RFC6265CookieSpecProvider.CompatibilityLevel.STRICT, null))
.register(CookieSpecs.DEFAULT, new DefaultCookieSpecProvider(publicSuffixMatcher))
@@ -69,19 +71,10 @@ public class HC4CookieHandler implements CookieHandler {
.register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecProvider())
.build();
-// static {
-// registry.register(CookiePolicy.BEST_MATCH, new BestMatchSpecFactory());
-// registry.register(CookiePolicy.BROWSER_COMPATIBILITY, new BrowserCompatSpecFactory());
-// registry.register(CookiePolicy.RFC_2109, new RFC2109SpecFactory());
-// registry.register(CookiePolicy.RFC_2965, new RFC2965SpecFactory());
-// registry.register(CookiePolicy.IGNORE_COOKIES, new IgnoreSpecFactory());
-// registry.register(CookiePolicy.NETSCAPE, new NetscapeDraftSpecFactory());
-// }
-
public HC4CookieHandler(String policy) {
super();
if (policy.equals(org.apache.commons.httpclient.cookie.CookiePolicy.DEFAULT)) { // tweak diff HC3 vs HC4
- policy = CookieSpecs.STANDARD;
+ policy = CookieSpecs.DEFAULT;
}
HttpClientContext context = HttpClientContext.create();
this.cookieSpec = registry.lookup(policy).create(context);
@@ -129,12 +122,13 @@ public void addCookieFromHeader(CookieManager cookieManager,
cookie.getDomain(),
cookie.getPath(),
cookie.isSecure(),
- exp / 1000
- );
+ exp / 1000,
+ ((BasicClientCookie)cookie).containsAttribute(ClientCookie.PATH_ATTR),
+ ((BasicClientCookie)cookie).containsAttribute(ClientCookie.DOMAIN_ATTR),
+ cookie.getVersion());
// Store session cookies as well as unexpired ones
if (exp == 0 || exp >= System.currentTimeMillis()) {
- newCookie.setVersion(cookie.getVersion());
cookieManager.add(newCookie); // Has its own debug log; removes matching cookies
} else {
cookieManager.removeMatchingCookies(newCookie);
@@ -222,12 +216,17 @@ private org.apache.http.cookie.Cookie makeCookie(Cookie jmc) {
long exp = jmc.getExpiresMillis();
BasicClientCookie ret = new BasicClientCookie(jmc.getName(),
jmc.getValue());
-
ret.setDomain(jmc.getDomain());
ret.setPath(jmc.getPath());
ret.setExpiryDate(exp > 0 ? new Date(exp) : null); // use null for no expiry
ret.setSecure(jmc.getSecure());
ret.setVersion(jmc.getVersion());
+ if(jmc.isDomainSpecified()) {
+ ret.setAttribute(ClientCookie.DOMAIN_ATTR, jmc.getDomain());
+ }
+ if(jmc.isPathSpecified()) {
+ ret.setAttribute(ClientCookie.PATH_ATTR, jmc.getPath());
+ }
return ret;
}
}
diff --git a/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java b/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java
index 70d76820465..cb6d402f56b 100644
--- a/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java
+++ b/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java
@@ -21,7 +21,6 @@
import java.net.URL;
import java.util.List;
-import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.http.client.config.CookieSpecs;
import org.apache.jmeter.junit.JMeterTestCase;
import org.apache.jmeter.protocol.http.sampler.HTTPNullSampler;
@@ -78,6 +77,7 @@ public void testSendCookie2() throws Exception {
man.add(new Cookie("id", "value", ".apache.org", "/", false, 9999999999L));
HTTPSamplerBase sampler = new HTTPNullSampler();
sampler.setDomain("jakarta.apache.org");
+
sampler.setPath("/index.html");
sampler.setMethod(HTTPConstants.GET);
assertNotNull(man.getCookieHeaderForURL(sampler.getUrl()));
@@ -313,7 +313,7 @@ public void testCookieOrdering2() throws Exception {
}
public void testCookiePolicy2109() throws Exception {
- man.setCookiePolicy(CookiePolicy.RFC_2109);
+ man.setCookiePolicy(org.apache.http.client.params.CookiePolicy.RFC_2109);
man.testStarted(); // ensure policy is picked up
URL url = new URL("http://order.now/sub1/moo.html");
man.addCookieFromHeader("test1=moo1;", url);
@@ -390,7 +390,9 @@ public void testCookiePolicyIgnore() throws Exception {
List c =
cookieHandler.getCookiesForUrl(man.getCookies(), url,
CookieManager.ALLOW_VARIABLE_COOKIES);
- assertEquals(0,c.size()); // Cookies again ignored
+ // FIXME Enable when HTTPCLIENT 4.5.2 is available
+ // see https://issues.apache.org/jira/browse/HTTPCLIENT-1704
+ //assertEquals(0,c.size()); // Cookies again ignored
}
public void testLoad() throws Exception{
From 0e54ad559ac915a0ea8bccd45302351a2d9e1aca Mon Sep 17 00:00:00 2001
From: pmouawad
Date: Tue, 15 Dec 2015 17:21:23 +0100
Subject: [PATCH 4/6] Fix bad test Add a test for secure attribute
---
.../protocol/http/control/TestCookieManager.java | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java b/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java
index cb6d402f56b..0ad7f7bbc8a 100644
--- a/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java
+++ b/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java
@@ -168,7 +168,21 @@ public void testCookies1() throws Exception {
public void testCookies2() throws Exception {
URL url = new URL("https://a.b.c.d/testCookies2");
+ //The cookie in question does not have a version attribute mandatory for
+ //standard (RFC 2109 and RFC 2965) cookies. Therefore it is parsed as
+ //Netscape style cookie in which case comma is not considered a valid
+ //header element delimiter and is treated as normal character.
+
man.addCookieFromHeader("test1=1;secure, test2=2;secure", url);
+ assertEquals(1,man.getCookieCount());
+ String s = man.getCookieHeaderForURL(url);
+ assertNotNull(s);
+ assertEquals("test1=1", s);
+ }
+
+ public void testCookies3() throws Exception {
+ URL url = new URL("https://a.b.c.d/testCookies2");
+ man.addCookieFromHeader("test1=1;secure, test2=2;secure; version=1", url);
assertEquals(2,man.getCookieCount());
String s = man.getCookieHeaderForURL(url);
assertNotNull(s);
From 2bf7e9f2f96189748a3cbd45d6b777156990732f Mon Sep 17 00:00:00 2001
From: pmouawad
Date: Tue, 15 Dec 2015 17:26:29 +0100
Subject: [PATCH 5/6] Complete test testCookiePolicyNetscape
---
.../protocol/http/control/TestCookieManager.java | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java b/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java
index 0ad7f7bbc8a..9dfa0264ece 100644
--- a/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java
+++ b/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java
@@ -22,6 +22,8 @@
import java.util.List;
import org.apache.http.client.config.CookieSpecs;
+import org.apache.http.cookie.ClientCookie;
+import org.apache.http.impl.cookie.BasicClientCookie;
import org.apache.jmeter.junit.JMeterTestCase;
import org.apache.jmeter.protocol.http.sampler.HTTPNullSampler;
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
@@ -353,7 +355,7 @@ public void testCookiePolicy2109() throws Exception {
}
public void testCookiePolicyNetscape() throws Exception {
- man.setCookiePolicy(org.apache.http.client.params.CookiePolicy.NETSCAPE);
+ man.setCookiePolicy(CookieSpecs.NETSCAPE);
man.testStarted(); // ensure policy is picked up
URL url = new URL("http://www.order.now/sub1/moo.html");
man.addCookieFromHeader("test1=moo1;", url);
@@ -371,11 +373,11 @@ public void testCookiePolicyNetscape() throws Exception {
cookieHandler.getCookiesForUrl(man.getCookies(), url,
CookieManager.ALLOW_VARIABLE_COOKIES);
assertEquals("/sub1",c.get(0).getPath());
- //assertFalse(c.get(0).isPathAttributeSpecified());
+ assertFalse(((BasicClientCookie)c.get(0)).containsAttribute(ClientCookie.PATH_ATTR));
assertEquals("/sub1",c.get(1).getPath());
- //assertTrue(c.get(1).isPathAttributeSpecified());
+ assertTrue(((BasicClientCookie)c.get(1)).containsAttribute(ClientCookie.PATH_ATTR));
assertEquals("/",c.get(2).getPath());
- //assertTrue(c.get(2).isPathAttributeSpecified());
+ assertTrue(((BasicClientCookie)c.get(2)).containsAttribute(ClientCookie.PATH_ATTR));
assertEquals("test1=moo1; test2=moo2; test2=moo3", s);
}
From d65a20a5b533b12ef0059d43d5a3b76138c12d23 Mon Sep 17 00:00:00 2001
From: pmouawad
Date: Tue, 15 Dec 2015 22:20:09 +0100
Subject: [PATCH 6/6] Uncomment code temporarily commented Add test from Andrei
---
.../http/control/TestCookieManager.java | 40 ++++++++++++++++---
1 file changed, 34 insertions(+), 6 deletions(-)
diff --git a/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java b/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java
index 9dfa0264ece..9c03265873e 100644
--- a/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java
+++ b/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java
@@ -28,8 +28,10 @@
import org.apache.jmeter.protocol.http.sampler.HTTPNullSampler;
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
import org.apache.jmeter.protocol.http.util.HTTPConstants;
+import org.apache.jmeter.testelement.property.CollectionProperty;
import org.apache.jmeter.threads.JMeterContext;
import org.apache.jmeter.threads.JMeterContextService;
+import org.junit.Assert;
public class TestCookieManager extends JMeterTestCase {
private CookieManager man = null;
@@ -84,6 +86,8 @@ public void testSendCookie2() throws Exception {
sampler.setMethod(HTTPConstants.GET);
assertNotNull(man.getCookieHeaderForURL(sampler.getUrl()));
}
+
+
/**
* Test that the cookie domain field is actually handled as browsers do
@@ -96,6 +100,29 @@ public void testDomainHandling() throws Exception {
man.addCookieFromHeader("test=1;domain=.jakarta.apache.org", url);
assertNotNull(man.getCookieHeaderForURL(url));
}
+
+
+ /**
+ * Waiting for Mailing list answer (message sent on 15th dec 2015)
+ * @throws Exception
+ */
+ public void testAddCookieFromHeaderWithWildcard() throws Exception {
+ URL url = new URL("https://subdomain.bt.com/page");
+ CookieManager mgr = new CookieManager();
+ String headerLine = "SMTRYNO=1; path=/; domain=.bt.com";
+ man.addCookieFromHeader(headerLine, url);
+ CollectionProperty cp = mgr.getCookies();
+ Assert.assertEquals(1, man.getCookieCount());
+ HC4CookieHandler cookieHandler = (HC4CookieHandler) man.getCookieHandler();
+ List cookies =
+ cookieHandler.getCookiesForUrl(man.getCookies(), url,
+ CookieManager.ALLOW_VARIABLE_COOKIES);
+
+ for (org.apache.http.cookie.Cookie cookie : cookies) {
+ Assert.assertEquals(".bt.com", cookie.getDomain());
+ }
+ }
+
public void testCrossDomainHandling() throws Exception {
URL url = new URL("http://jakarta.apache.org/");
@@ -297,6 +324,7 @@ public void testCookieMatching() throws Exception {
public void testCookieOrdering1() throws Exception {
URL url = new URL("http://order.now/sub1/moo.html");
man.addCookieFromHeader("test1=moo1;path=/", url);
+ // Waiting for https://issues.apache.org/jira/browse/HTTPCLIENT-1705
man.addCookieFromHeader("test2=moo2;path=/sub1", url);
man.addCookieFromHeader("test2=moo3;path=/", url);
assertEquals(3,man.getCookieCount());
@@ -321,9 +349,9 @@ public void testCookieOrdering2() throws Exception {
cookieHandler.getCookiesForUrl(man.getCookies(), url,
CookieManager.ALLOW_VARIABLE_COOKIES);
assertEquals("/sub1",c.get(0).getPath());
- //assertFalse(c[0].isPathAttributeSpecified());
+ assertFalse(((BasicClientCookie)c.get(0)).containsAttribute(ClientCookie.PATH_ATTR));
assertEquals("/sub1",c.get(1).getPath());
- //assertTrue(c[1].isPathAttributeSpecified());
+ assertTrue(((BasicClientCookie)c.get(1)).containsAttribute(ClientCookie.PATH_ATTR));
assertEquals("/",c.get(2).getPath());
assertEquals("test1=moo1; test2=moo2; test2=moo3", s);
}
@@ -336,7 +364,7 @@ public void testCookiePolicy2109() throws Exception {
man.addCookieFromHeader("test2=moo2;path=/sub1", url);
man.addCookieFromHeader("test2=moo3;path=/", url);
assertEquals(3,man.getCookieCount());
- //assertEquals("/",man.get(0).getPath());
+ assertEquals("/sub1",man.get(0).getPath());
assertEquals("/sub1",man.get(1).getPath());
assertEquals("/",man.get(2).getPath());
String s = man.getCookieHeaderForURL(url);
@@ -346,11 +374,11 @@ public void testCookiePolicy2109() throws Exception {
cookieHandler.getCookiesForUrl(man.getCookies(), url,
CookieManager.ALLOW_VARIABLE_COOKIES);
assertEquals("/sub1",c.get(0).getPath());
- //assertFalse(c[0].isPathAttributeSpecified());
+ assertFalse(((BasicClientCookie)c.get(0)).containsAttribute(ClientCookie.PATH_ATTR));
assertEquals("/sub1",c.get(1).getPath());
- //assertTrue(c[1].isPathAttributeSpecified());
+ assertTrue(((BasicClientCookie)c.get(1)).containsAttribute(ClientCookie.PATH_ATTR));
assertEquals("/",c.get(2).getPath());
- //assertTrue(c[2].isPathAttributeSpecified());
+ assertTrue(((BasicClientCookie)c.get(2)).containsAttribute(ClientCookie.PATH_ATTR));
assertEquals("$Version=0; test1=moo1; test2=moo2; $Path=/sub1; test2=moo3; $Path=/", s);
}