hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: Issues when upgrading from 3 to 4.2.6 or 4.5.1
Date Tue, 15 Dec 2015 08:36:22 GMT
On Mon, 2015-12-14 at 21:41 +0100, Philippe Mouawad wrote:
> Hello Oleg,
> Thanks .
> 

Test case #testParseCookies 

The rest case does not look right to me. I am not sure I understand what
you are trying to test here.

Test case #testParseCookies

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.

Oleg  
 

> Here it is:
> 
> /*
>  * ====================================================================
>  * Licensed to the Apache Software Foundation (ASF) under one
>  * or more contributor license agreements.  See the NOTICE file
>  * distributed with this work for additional information
>  * regarding copyright ownership.  The ASF licenses this file
>  * to you under the Apache License, Version 2.0 (the
>  * "License"); you may not use this file except in compliance
>  * with the License.  You may obtain a copy of the License at
>  *
>  *   http://www.apache.org/licenses/LICENSE-2.0
>  *
>  * Unless required by applicable law or agreed to in writing,
>  * software distributed under the License is distributed on an
>  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>  * KIND, either express or implied.  See the License for the
>  * specific language governing permissions and limitations
>  * under the License.
>  * ====================================================================
>  *
>  * This software consists of voluntary contributions made by many
>  * individuals on behalf of the Apache Software Foundation.  For more
>  * information on the Apache Software Foundation, please see
>  * <http://www.apache.org/>.
>  *
>  */
> package org.apache.http.client.protocol;
> 
> import java.util.List;
> 
> import org.apache.http.Header;
> import org.apache.http.HttpResponse;
> import org.apache.http.HttpResponseInterceptor;
> import org.apache.http.HttpVersion;
> import org.apache.http.client.CookieStore;
> import org.apache.http.cookie.Cookie;
> import org.apache.http.cookie.CookieOrigin;
> import org.apache.http.cookie.CookieSpec;
> import org.apache.http.cookie.SM;
> import org.apache.http.impl.client.BasicCookieStore;
> import org.apache.http.impl.cookie.DefaultCookieSpec;
> import org.apache.http.message.BasicHttpResponse;
> import org.apache.http.util.Asserts;
> import org.junit.Assert;
> import org.junit.Before;
> import org.junit.Test;
> 
> public class TestResponseProcessCookies {
> 
>     private CookieOrigin cookieOrigin;
>     private CookieSpec cookieSpec;
>     private CookieStore cookieStore;
> 
>     @Before
>     public void setUp() throws Exception {
>         this.cookieOrigin = new CookieOrigin("localhost", 80, "/", false);
>         this.cookieSpec = new DefaultCookieSpec();
>         this.cookieStore = new BasicCookieStore();
>     }
> 
>     @Test(expected=IllegalArgumentException.class)
>     public void testResponseParameterCheck() throws Exception {
>         final HttpClientContext context = HttpClientContext.create();
>         final HttpResponseInterceptor interceptor = new
> ResponseProcessCookies();
>         interceptor.process(null, context);
>     }
> 
>     @Test(expected=IllegalArgumentException.class)
>     public void testContextParameterCheck() throws Exception {
>         final HttpResponse response = new
> BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
>         final HttpResponseInterceptor interceptor = new
> ResponseProcessCookies();
>         interceptor.process(response, null);
>     }
> 
>     @Test
>     public void testParseMultipleCookies() throws Exception {
>         final HttpResponse response = new
> BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
>         response.addHeader(SM.SET_COOKIE, "test1=1; comment=\"how,now\",
> test2=2; version=1");
> 
>         final HttpClientContext context = HttpClientContext.create();
>         context.setAttribute(HttpClientContext.COOKIE_ORIGIN,
> this.cookieOrigin);
>         context.setAttribute(HttpClientContext.COOKIE_SPEC,
> this.cookieSpec);
>         context.setAttribute(HttpClientContext.COOKIE_STORE,
> this.cookieStore);
> 
>         final HttpResponseInterceptor interceptor = new
> ResponseProcessCookies();
>         interceptor.process(response, context);
> 
>         final List<Cookie> cookies = this.cookieStore.getCookies();
>         Assert.assertNotNull(cookies);
>         Assert.assertEquals(1, cookies.size());
>         final Cookie cookie = cookies.get(0);
>         Assert.assertEquals(0, cookie.getVersion());
>         Assert.assertEquals("name1", cookie.getName());
>         Assert.assertEquals("value1", cookie.getValue());
>         Assert.assertEquals("localhost", cookie.getDomain());
>         Assert.assertEquals("/", cookie.getPath());
>     }
> 
>     @Test
>     public void testParseCookies() throws Exception {
>         final HttpResponse response = new
> BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
>         response.addHeader(SM.SET_COOKIE, "name1=value1");
> 
>         final HttpClientContext context = HttpClientContext.create();
>         context.setAttribute(HttpClientContext.COOKIE_ORIGIN,
> this.cookieOrigin);
>         context.setAttribute(HttpClientContext.COOKIE_SPEC,
> this.cookieSpec);
>         context.setAttribute(HttpClientContext.COOKIE_STORE,
> this.cookieStore);
> 
>         final HttpResponseInterceptor interceptor = new
> ResponseProcessCookies();
>         interceptor.process(response, context);
> 
>         final List<Cookie> cookies = this.cookieStore.getCookies();
>         List<Header> lstHdr = cookieSpec.formatCookies(cookies);
>         StringBuilder sbHdr = new StringBuilder();
>         for (Header header : lstHdr) {
>             sbHdr.append(header.getValue());
>         }
>         org.junit.Assert.assertEquals("test1=1; test2=2", sbHdr.toString());
>     }
>     @Test
>     public void testParseCookies2() throws Exception {
>         final HttpResponse response = new
> BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
>         response.addHeader(SM.SET_COOKIE, "test1=1;secure, test2=2;secure");
> 
>         final HttpClientContext context = HttpClientContext.create();
>         context.setAttribute(HttpClientContext.COOKIE_ORIGIN,
> this.cookieOrigin);
>         context.setAttribute(HttpClientContext.COOKIE_SPEC,
> this.cookieSpec);
>         context.setAttribute(HttpClientContext.COOKIE_STORE,
> this.cookieStore);
> 
>         final HttpResponseInterceptor interceptor = new
> ResponseProcessCookies();
>         interceptor.process(response, context);
> 
>         final List<Cookie> cookies = this.cookieStore.getCookies();
>         List<Header> lstHdr = cookieSpec.formatCookies(cookies);
>         StringBuilder sbHdr = new StringBuilder();
>         for (Header header : lstHdr) {
>             sbHdr.append(header.getValue());
>         }
>         org.junit.Assert.assertEquals("test1=1; test2=2", sbHdr.toString());
>     }
> 
>     @Test
>     public void testNoCookieOrigin() throws Exception {
>         final HttpResponse response = new
> BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
>         response.addHeader(SM.SET_COOKIE, "name1=value1");
> 
>         final HttpClientContext context = HttpClientContext.create();
>         context.setAttribute(HttpClientContext.COOKIE_ORIGIN, null);
>         context.setAttribute(HttpClientContext.COOKIE_SPEC,
> this.cookieSpec);
>         context.setAttribute(HttpClientContext.COOKIE_STORE,
> this.cookieStore);
> 
>         final HttpResponseInterceptor interceptor = new
> ResponseProcessCookies();
>         interceptor.process(response, context);
> 
>         final List<Cookie> cookies = this.cookieStore.getCookies();
>         Assert.assertNotNull(cookies);
>         Assert.assertEquals(0, cookies.size());
>     }
> 
>     @Test
>     public void testNoCookieSpec() throws Exception {
>         final HttpResponse response = new
> BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
>         response.addHeader(SM.SET_COOKIE, "name1=value1");
> 
>         final HttpClientContext context = HttpClientContext.create();
>         context.setAttribute(HttpClientContext.COOKIE_ORIGIN,
> this.cookieOrigin);
>         context.setAttribute(HttpClientContext.COOKIE_SPEC, null);
>         context.setAttribute(HttpClientContext.COOKIE_STORE,
> this.cookieStore);
> 
>         final HttpResponseInterceptor interceptor = new
> ResponseProcessCookies();
>         interceptor.process(response, context);
> 
>         final List<Cookie> cookies = this.cookieStore.getCookies();
>         Assert.assertNotNull(cookies);
>         Assert.assertEquals(0, cookies.size());
>     }
> 
>     @Test
>     public void testNoCookieStore() throws Exception {
>         final HttpResponse response = new
> BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
>         response.addHeader(SM.SET_COOKIE, "name1=value1");
> 
>         final HttpClientContext context = HttpClientContext.create();
>         context.setAttribute(HttpClientContext.COOKIE_ORIGIN,
> this.cookieOrigin);
>         context.setAttribute(HttpClientContext.COOKIE_SPEC,
> this.cookieSpec);
>         context.setAttribute(HttpClientContext.COOKIE_STORE, null);
> 
>         final HttpResponseInterceptor interceptor = new
> ResponseProcessCookies();
>         interceptor.process(response, context);
> 
>         final List<Cookie> cookies = this.cookieStore.getCookies();
>         Assert.assertNotNull(cookies);
>         Assert.assertEquals(0, cookies.size());
>     }
> 
>     @Test
>     public void testSetCookie2OverrideSetCookie() throws Exception {
>         final HttpResponse response = new
> BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
>         response.addHeader(SM.SET_COOKIE, "name1=value1");
>         response.addHeader(SM.SET_COOKIE2, "name1=value2; Version=1");
> 
>         final HttpClientContext context = HttpClientContext.create();
>         context.setAttribute(HttpClientContext.COOKIE_ORIGIN,
> this.cookieOrigin);
>         context.setAttribute(HttpClientContext.COOKIE_SPEC,
> this.cookieSpec);
>         context.setAttribute(HttpClientContext.COOKIE_STORE,
> this.cookieStore);
> 
>         final HttpResponseInterceptor interceptor = new
> ResponseProcessCookies();
>         interceptor.process(response, context);
> 
>         final List<Cookie> cookies = this.cookieStore.getCookies();
>         Assert.assertNotNull(cookies);
>         Assert.assertEquals(1, cookies.size());
>         final Cookie cookie = cookies.get(0);
>         Assert.assertEquals(1, cookie.getVersion());
>         Assert.assertEquals("name1", cookie.getName());
>         Assert.assertEquals("value2", cookie.getValue());
>         Assert.assertEquals("localhost.local", cookie.getDomain());
>         Assert.assertEquals("/", cookie.getPath());
>     }
> 
>     @Test
>     public void testInvalidHeader() throws Exception {
>         final HttpResponse response = new
> BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
>         response.addHeader(SM.SET_COOKIE2, "name=value; Version=crap");
> 
>         final HttpClientContext context = HttpClientContext.create();
>         context.setAttribute(HttpClientContext.COOKIE_ORIGIN,
> this.cookieOrigin);
>         context.setAttribute(HttpClientContext.COOKIE_SPEC,
> this.cookieSpec);
>         context.setAttribute(HttpClientContext.COOKIE_STORE,
> this.cookieStore);
> 
>         final HttpResponseInterceptor interceptor = new
> ResponseProcessCookies();
>         interceptor.process(response, context);
> 
>         final List<Cookie> cookies = this.cookieStore.getCookies();
>         Assert.assertNotNull(cookies);
>         Assert.assertTrue(cookies.isEmpty());
>     }
> 
>     @Test
>     public void testCookieRejected() throws Exception {
>         final HttpResponse response = new
> BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
>         response.addHeader(SM.SET_COOKIE2, "name=value; Domain=
> www.somedomain.com; Version=1");
> 
>         final HttpClientContext context = HttpClientContext.create();
>         context.setAttribute(HttpClientContext.COOKIE_ORIGIN,
> this.cookieOrigin);
>         context.setAttribute(HttpClientContext.COOKIE_SPEC,
> this.cookieSpec);
>         context.setAttribute(HttpClientContext.COOKIE_STORE,
> this.cookieStore);
> 
>         final HttpResponseInterceptor interceptor = new
> ResponseProcessCookies();
>         interceptor.process(response, context);
> 
>         final List<Cookie> cookies = this.cookieStore.getCookies();
>         Assert.assertNotNull(cookies);
>         Assert.assertTrue(cookies.isEmpty());
>     }
> 
> }
> 
> 
> On Mon, Dec 14, 2015 at 9:34 PM, Oleg Kalnichevski <olegk@apache.org> wrote:
> 
> > On Sun, 2015-12-13 at 22:28 +0100, Philippe Mouawad wrote:
> > > Finally, for those  2 I am not sure  as per RFC6265, to use them , put
> > code
> > > in org.apache.http.client.protocol.TestResponseProcessCookies.
> > > They worked with HC3 but it does not mean they should work with HC4, but
> > I
> > > would like a confirmation:
> > >
> >
> > I cannot get the tests to compile due to missing instance variables
> > cookieOrigin, cookieSpec and cookieStore. I'll take another look if you
> > post the complete class.
> >
> > Oleg
> >
> >
> > >
> > >     @Test
> > >     public void testParseCookies() throws Exception {
> > >         final HttpResponse response = new
> > > BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
> > >         response.addHeader(SM.SET_COOKIE, "name1=value1");
> > >
> > >         final HttpClientContext context = HttpClientContext.create();
> > >         context.setAttribute(HttpClientContext.COOKIE_ORIGIN,
> > > this.cookieOrigin);
> > >         context.setAttribute(HttpClientContext.COOKIE_SPEC,
> > > this.cookieSpec);
> > >         context.setAttribute(HttpClientContext.COOKIE_STORE,
> > > this.cookieStore);
> > >
> > >         final HttpResponseInterceptor interceptor = new
> > > ResponseProcessCookies();
> > >         interceptor.process(response, context);
> > >
> > >         final List<Cookie> cookies = this.cookieStore.getCookies();
> > >         List<Header> lstHdr = cookieSpec.formatCookies(cookies);
> > >         StringBuilder sbHdr = new StringBuilder();
> > >         for (Header header : lstHdr) {
> > >             sbHdr.append(header.getValue());
> > >         }
> > >         org.junit.Assert.assertEquals("test1=1; test2=2",
> > sbHdr.toString());
> > >     }
> > >     @Test
> > >     public void testParseCookies2() throws Exception {
> > >         final HttpResponse response = new
> > > BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
> > >         response.addHeader(SM.SET_COOKIE, "test1=1;secure,
> > test2=2;secure");
> > >
> > >         final HttpClientContext context = HttpClientContext.create();
> > >         context.setAttribute(HttpClientContext.COOKIE_ORIGIN,
> > > this.cookieOrigin);
> > >         context.setAttribute(HttpClientContext.COOKIE_SPEC,
> > > this.cookieSpec);
> > >         context.setAttribute(HttpClientContext.COOKIE_STORE,
> > > this.cookieStore);
> > >
> > >         final HttpResponseInterceptor interceptor = new
> > > ResponseProcessCookies();
> > >         interceptor.process(response, context);
> > >
> > >         final List<Cookie> cookies = this.cookieStore.getCookies();
> > >         List<Header> lstHdr = cookieSpec.formatCookies(cookies);
> > >         StringBuilder sbHdr = new StringBuilder();
> > >         for (Header header : lstHdr) {
> > >             sbHdr.append(header.getValue());
> > >         }
> > >         org.junit.Assert.assertEquals("test1=1; test2=2",
> > sbHdr.toString());
> > >     }
> > >
> > > Thanks
> > >
> > > On Sun, Dec 13, 2015 at 10:09 PM, Philippe Mouawad <
> > > philippe.mouawad@gmail.com> wrote:
> > >
> > > > Hi,
> > > > Created https://issues.apache.org/jira/browse/HTTPCLIENT-1705 with a
> > Test
> > > > case in it to show issue with Domain starting with ".".
> > > >
> > > >
> > > > Regards
> > > >
> > > > On Sun, Dec 13, 2015 at 9:50 PM, Philippe Mouawad <
> > > > philippe.mouawad@gmail.com> wrote:
> > > >
> > > >> Hi Oleg,
> > > >> Created https://issues.apache.org/jira/browse/HTTPCLIENT-1705 to show
> > > >> issue with Cookie Header ordering.
> > > >>
> > > >> Regards
> > > >>
> > > >> On Sun, Dec 13, 2015 at 9:30 PM, Philippe Mouawad <
> > > >> philippe.mouawad@gmail.com> wrote:
> > > >>
> > > >>> Hi,
> > > >>>  I created https://issues.apache.org/jira/browse/HTTPCLIENT-1704
> > with
> > > >>> JUnit test case so that you understand the difference we have.
> > > >>>
> > > >>> Regards
> > > >>>
> > > >>> On Sat, Dec 5, 2015 at 1:26 PM, Oleg Kalnichevski <olegk@apache.org>
> > > >>> wrote:
> > > >>>
> > > >>>> On Fri, 2015-12-04 at 21:43 +0100, Philippe Mouawad wrote:
> > > >>>> > Thanks Oleg.
> > > >>>> > But look at
> > > >>>> >
> > > >>>>
> > https://github.com/ubikloadpack/jmeter/blob/HC4_5/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java#L368
> > > >>>> ,
> > > >>>> > it concerns IGNORE_POLICY
> > > >>>> >
> > > >>>> > I really think there is at least one bug.
> > > >>>> > Regards
> > > >>>> >
> > > >>>>
> > > >>>> Sure thing. All these issues may well be due to bugs in HC.
Could
> > you
> > > >>>> please though reproduce them with unit tests that do not involve
> > JMeter
> > > >>>> specific code?
> > > >>>>
> > > >>>> Oleg
> > > >>>>
> > > >>>>
> > > >>>> > On Wed, Dec 2, 2015 at 4:00 PM, Oleg Kalnichevski <
> > olegk@apache.org>
> > > >>>> wrote:
> > > >>>> >
> > > >>>> > > On Wed, 2015-12-02 at 15:51 +0100, Philippe Mouawad
wrote:
> > > >>>> > > > Hi Oleg,
> > > >>>> > > > Thanks for answer.
> > > >>>> > > >
> > > >>>> > > > Find my answers inline.
> > > >>>> > > > Regards
> > > >>>> > > >
> > > >>>> > > > On Wed, Dec 2, 2015 at 3:36 PM, Oleg Kalnichevski
<
> > > >>>> olegk@apache.org>
> > > >>>> > > wrote:
> > > >>>> > > >
> > > >>>> > > > > On Tue, 2015-12-01 at 22:09 +0100, Philippe
Mouawad wrote:
> > > >>>> > > > > > Hello,
> > > >>>> > > > > > Any answer on this question ?
> > > >>>> > > > > > Thanks
> > > >>>> > > > > > Regards
> > > >>>> > > > > >
> > > >>>> > > > > > On Sun, Nov 15, 2015 at 8:39 PM,
Philippe Mouawad <
> > > >>>> > > > > > philippe.mouawad@gmail.com> wrote:
> > > >>>> > > > > >
> > > >>>> > > > > > > Hello,
> > > >>>> > > > > > > We're in the process of migrating
JMeter to last
> > HttpClient
> > > >>>> 4.5.1.
> > > >>>> > > > > > >
> > > >>>> > > > > > > We are now migrating the CookieManager
to remove all
> > > >>>> deprecated
> > > >>>> > > code.
> > > >>>> > > > > > > To test this class, we had a
JUNIT class :
> > > >>>> > > > > > >
> > > >>>> > > > > > >
> > > >>>> > > > >
> > > >>>> > >
> > > >>>>
> > https://github.com/ubikloadpack/jmeter/blob/HC4_5/test/src/org/apache/jmeter/protocol/http/control/TestCookieManager.java
> > > >>>> > > > > > >
> > > >>>> > > > > > > Before migration, it was still
testing HC3 version.
> > > >>>> > > > > > > So we first switched to HC4.23
and noticed some
> > failures:
> > > >>>> > > > > > >
> > > >>>> > > > >
> > > >>>> > > > > I am confused. Are you using HC 4.2.3
or HC 4.5.1?
> > > >>>> > > >
> > > >>>> > > >
> > > >>>> > > > As I wrote, first we switched our JUnit tests
to use HC4
> > > >>>> Implementation
> > > >>>> > > of
> > > >>>> > > > CookieHandler and used 4.2.3, we got some failures
compared to
> > > >>>> HC3.
> > > >>>> > > >
> > > >>>> > > > Then we switched from HC 4.2.3 to HC 4.5.1
and got other
> > failures
> > > >>>> all
> > > >>>> > > > detailed in initial mail.
> > > >>>> > > >
> > > >>>> > > >
> > > >>>> > > > What policy does
> > > >>>> > > > > CookeManager use internally?
> > > >>>> > > > >
> > > >>>> > > > It depends on tests, you can see in the code
that depending on
> > > >>>> test
> > > >>>> > > method
> > > >>>> > > > we set different Policy to test them.
> > > >>>> > > >
> > > >>>> > >
> > > >>>> > > You ought to be using RFC6265 policy either in strict
or relaxed
> > > >>>> mode
> > > >>>> > > and nothing else. All other policies have been marked
as
> > obsolete
> > > >>>> and
> > > >>>> > > have already been removed in 5.0 (trunk).
> > > >>>> > >
> > > >>>> > > Oleg
> > > >>>> > >
> > > >>>> > >
> > > >>>> > >
> > > >>>>
> > ---------------------------------------------------------------------
> > > >>>> > > To unsubscribe, e-mail:
> > httpclient-users-unsubscribe@hc.apache.org
> > > >>>> > > For additional commands, e-mail:
> > > >>>> httpclient-users-help@hc.apache.org
> > > >>>> > >
> > > >>>> > >
> > > >>>> >
> > > >>>> >
> > > >>>>
> > > >>>>
> > > >>>>
> > > >>>>
> > ---------------------------------------------------------------------
> > > >>>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > > >>>> For additional commands, e-mail:
> > httpclient-users-help@hc.apache.org
> > > >>>>
> > > >>>>
> > > >>>
> > > >>>
> > > >>> --
> > > >>> Cordialement.
> > > >>> Philippe Mouawad.
> > > >>>
> > > >>>
> > > >>>
> > > >>
> > > >>
> > > >> --
> > > >> Cordialement.
> > > >> Philippe Mouawad.
> > > >>
> > > >>
> > > >>
> > > >
> > > >
> > > > --
> > > > Cordialement.
> > > > Philippe Mouawad.
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
> >
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message