svn commit: r831530 - in /tomcat/trunk/test/org/apache/catalina/startup: TestTomcat.java TestTomcatBase.java

2009-10-31 Thread markt
Author: markt
Date: Sat Oct 31 11:01:48 2009
New Revision: 831530

URL: http://svn.apache.org/viewvc?rev=831530&view=rev
Log:
Refactoring to allow easier re-use.

Modified:
tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java
tomcat/trunk/test/org/apache/catalina/startup/TestTomcatBase.java

Modified: tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java?rev=831530&r1=831529&r2=831530&view=diff
==
--- tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java (original)
+++ tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java Sat Oct 31 
11:01:48 2009
@@ -16,14 +16,9 @@
  */
 package org.apache.catalina.startup;
 
-import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
-import java.net.HttpURLConnection;
 import java.net.URL;
-import java.util.List;
-import java.util.Map;
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
@@ -216,35 +211,4 @@
 assertEquals(HttpServletResponse.SC_OK, rc);
 }
 
-/**
- *  Wrapper for getting the response.
- */
-public static ByteChunk getUrl(String path) throws IOException {
-ByteChunk out = new ByteChunk();
-getUrl(path, out, null);
-return out;
-}
-
-public static int getUrl(String path, 
- ByteChunk out, 
- Map> resHead) throws 
IOException {
-URL url = new URL(path);
-HttpURLConnection connection = 
-(HttpURLConnection) url.openConnection();
-connection.setReadTimeout(10);
-connection.connect();
-int rc = connection.getResponseCode();
-if (resHead != null) {
-Map> head = connection.getHeaderFields();
-resHead.putAll(head);
-}
-InputStream is = connection.getInputStream();
-BufferedInputStream bis = new BufferedInputStream(is);
-byte[] buf = new byte[2048];
-int rd = 0;
-while((rd = bis.read(buf)) > 0) {
-out.append(buf, 0, rd);
-}
-return rc;
-}
 }

Modified: tomcat/trunk/test/org/apache/catalina/startup/TestTomcatBase.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/TestTomcatBase.java?rev=831530&r1=831529&r2=831530&view=diff
==
--- tomcat/trunk/test/org/apache/catalina/startup/TestTomcatBase.java (original)
+++ tomcat/trunk/test/org/apache/catalina/startup/TestTomcatBase.java Sat Oct 
31 11:01:48 2009
@@ -16,15 +16,23 @@
  */
 package org.apache.catalina.startup;
 
+import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.PrintWriter;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.tomcat.util.buf.ByteChunk;
+
 import junit.framework.TestCase;
 
 /**
@@ -83,4 +91,37 @@
 out.print("Hello World");
 }
 }
+
+
+/**
+ *  Wrapper for getting the response.
+ */
+public static ByteChunk getUrl(String path) throws IOException {
+ByteChunk out = new ByteChunk();
+getUrl(path, out, null);
+return out;
+}
+
+public static int getUrl(String path, 
+ ByteChunk out, 
+ Map> resHead) throws 
IOException {
+URL url = new URL(path);
+HttpURLConnection connection = 
+(HttpURLConnection) url.openConnection();
+connection.setReadTimeout(10);
+connection.connect();
+int rc = connection.getResponseCode();
+if (resHead != null) {
+Map> head = connection.getHeaderFields();
+resHead.putAll(head);
+}
+InputStream is = connection.getInputStream();
+BufferedInputStream bis = new BufferedInputStream(is);
+byte[] buf = new byte[2048];
+int rd = 0;
+while((rd = bis.read(buf)) > 0) {
+out.append(buf, 0, rd);
+}
+return rc;
+}
 }



-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



svn commit: r831533 - in /tomcat/trunk/test/org/apache: catalina/connector/ catalina/core/ catalina/startup/ tomcat/util/http/

2009-10-31 Thread markt
Author: markt
Date: Sat Oct 31 11:46:50 2009
New Revision: 831533

URL: http://svn.apache.org/viewvc?rev=831533&view=rev
Log:
New cookie unit tests and associated refactoring to get ant test target working.

Added:
tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java
  - copied, changed from r831530, 
tomcat/trunk/test/org/apache/catalina/startup/TestTomcatBase.java
tomcat/trunk/test/org/apache/tomcat/util/http/CookiesBaseTest.java

tomcat/trunk/test/org/apache/tomcat/util/http/TestCookiesDefaultSysProps.java

tomcat/trunk/test/org/apache/tomcat/util/http/TestCookiesNoFwdStrictSysProps.java

tomcat/trunk/test/org/apache/tomcat/util/http/TestCookiesNoStrictNamingSysProps.java
tomcat/trunk/test/org/apache/tomcat/util/http/TestCookiesStrictSysProps.java
Removed:
tomcat/trunk/test/org/apache/catalina/startup/TestTomcatBase.java
Modified:
tomcat/trunk/test/org/apache/catalina/connector/TestKeepAliveCount.java
tomcat/trunk/test/org/apache/catalina/connector/TestRequest.java
tomcat/trunk/test/org/apache/catalina/core/TestStandardContext.java
tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java

Modified: 
tomcat/trunk/test/org/apache/catalina/connector/TestKeepAliveCount.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/connector/TestKeepAliveCount.java?rev=831533&r1=831532&r2=831533&view=diff
==
--- tomcat/trunk/test/org/apache/catalina/connector/TestKeepAliveCount.java 
(original)
+++ tomcat/trunk/test/org/apache/catalina/connector/TestKeepAliveCount.java Sat 
Oct 31 11:46:50 2009
@@ -25,10 +25,10 @@
 
 import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.startup.SimpleHttpClient;
-import org.apache.catalina.startup.TestTomcatBase;
+import org.apache.catalina.startup.TomcatBaseTest;
 import org.apache.catalina.startup.Tomcat;
 
-public class TestKeepAliveCount extends TestTomcatBase{
+public class TestKeepAliveCount extends TomcatBaseTest{
 
 public void testHttp10() throws Exception {
 TestKeepAliveClient client = new TestKeepAliveClient();

Modified: tomcat/trunk/test/org/apache/catalina/connector/TestRequest.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/connector/TestRequest.java?rev=831533&r1=831532&r2=831533&view=diff
==
--- tomcat/trunk/test/org/apache/catalina/connector/TestRequest.java (original)
+++ tomcat/trunk/test/org/apache/catalina/connector/TestRequest.java Sat Oct 31 
11:46:50 2009
@@ -28,13 +28,13 @@
 
 import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.startup.SimpleHttpClient;
-import org.apache.catalina.startup.TestTomcatBase;
+import org.apache.catalina.startup.TomcatBaseTest;
 import org.apache.catalina.startup.Tomcat;
 
 /**
  * Test case for {...@link Request}. 
  */
-public class TestRequest extends TestTomcatBase {
+public class TestRequest extends TomcatBaseTest {
 
 /**
  * Test case for https://issues.apache.org/bugzilla/show_bug.cgi?id=37794

Modified: tomcat/trunk/test/org/apache/catalina/core/TestStandardContext.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/core/TestStandardContext.java?rev=831533&r1=831532&r2=831533&view=diff
==
--- tomcat/trunk/test/org/apache/catalina/core/TestStandardContext.java 
(original)
+++ tomcat/trunk/test/org/apache/catalina/core/TestStandardContext.java Sat Oct 
31 11:46:50 2009
@@ -30,10 +30,10 @@
 import org.apache.catalina.deploy.FilterDef;
 import org.apache.catalina.deploy.FilterMap;
 import org.apache.catalina.startup.SimpleHttpClient;
-import org.apache.catalina.startup.TestTomcatBase;
+import org.apache.catalina.startup.TomcatBaseTest;
 import org.apache.catalina.startup.Tomcat;
 
-public class TestStandardContext extends TestTomcatBase {
+public class TestStandardContext extends TomcatBaseTest {
 
 private static final String REQUEST =
 "GET / HTTP/1.1\r\n" +

Modified: tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java?rev=831533&r1=831532&r2=831533&view=diff
==
--- tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java (original)
+++ tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java Sat Oct 31 
11:46:50 2009
@@ -31,7 +31,7 @@
 import org.apache.catalina.deploy.ContextEnvironment;
 import org.apache.tomcat.util.buf.ByteChunk;
 
-public class TestTomcat extends TestTomcatBase {
+public class TestTomcat extends TomcatBaseTest {
 
 /**
  * Simple servlet to test in-line registration 

Copied: tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java (from 
r831530, 

svn commit: r831536 - in /tomcat/trunk: java/org/apache/tomcat/util/http/ test/org/apache/tomcat/util/http/ webapps/docs/config/

2009-10-31 Thread markt
Author: markt
Date: Sat Oct 31 12:59:51 2009
New Revision: 831536

URL: http://svn.apache.org/viewvc?rev=831536&view=rev
Log:
Add an explicit configuration option for cookie version switching and update 
test cases and docs to include it.

Added:
tomcat/trunk/test/org/apache/tomcat/util/http/TestCookiesSwitchSysProps.java
Modified:
tomcat/trunk/java/org/apache/tomcat/util/http/ServerCookie.java
tomcat/trunk/test/org/apache/tomcat/util/http/CookiesBaseTest.java

tomcat/trunk/test/org/apache/tomcat/util/http/TestCookiesDefaultSysProps.java
tomcat/trunk/test/org/apache/tomcat/util/http/TestCookiesStrictSysProps.java
tomcat/trunk/webapps/docs/config/systemprops.xml

Modified: tomcat/trunk/java/org/apache/tomcat/util/http/ServerCookie.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/ServerCookie.java?rev=831536&r1=831535&r2=831536&view=diff
==
--- tomcat/trunk/java/org/apache/tomcat/util/http/ServerCookie.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/http/ServerCookie.java Sat Oct 31 
12:59:51 2009
@@ -75,6 +75,14 @@
 public static final boolean STRICT_SERVLET_COMPLIANCE;
 
 /**
+ * If set to false, we don't auto switch invalid v0 cookies to v1 and add
+ * quotes to make them valid.
+ * Default is usually true. If STRICT_SERVLET_COMPLIANCE==true then default
+ * is false. Explicitly setting always takes priority.
+ */
+public static final boolean ALLOW_VERSION_SWITCH;
+
+/**
  * If set to false, we don't use the IE6/7 Max-Age/Expires work around.
  * Default is usually true. If STRICT_SERVLET_COMPLIANCE==true then default
  * is false. Explicitly setting always takes priority.
@@ -97,6 +105,15 @@
 "false")).booleanValue();
 
 
+String allowVersionSwitch = System.getProperty(
+
"org.apache.tomcat.util.http.ServerCookie.ALLOW_VERSION_SWITCH");
+if (allowVersionSwitch == null) {
+ALLOW_VERSION_SWITCH = !STRICT_SERVLET_COMPLIANCE;
+} else {
+ALLOW_VERSION_SWITCH =
+Boolean.valueOf(allowVersionSwitch).booleanValue();
+}
+
 String alwaysAddExpires = System.getProperty(
 "org.apache.tomcat.util.http.ServerCookie.ALWAYS_ADD_EXPIRES");
 if (alwaysAddExpires == null) {
@@ -400,7 +417,7 @@
 buf.append('"');
 buf.append(escapeDoubleQuotes(value,1,value.length()-1));
 buf.append('"');
-} else if (allowVersionSwitch && (!STRICT_SERVLET_COMPLIANCE) && 
version==0 && !isToken2(value, literals)) {
+} else if (allowVersionSwitch && ALLOW_VERSION_SWITCH && version==0 && 
!isToken2(value, literals)) {
 buf.append('"');
 buf.append(escapeDoubleQuotes(value,0,value.length()));
 buf.append('"');

Modified: tomcat/trunk/test/org/apache/tomcat/util/http/CookiesBaseTest.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/http/CookiesBaseTest.java?rev=831536&r1=831535&r2=831536&view=diff
==
--- tomcat/trunk/test/org/apache/tomcat/util/http/CookiesBaseTest.java 
(original)
+++ tomcat/trunk/test/org/apache/tomcat/util/http/CookiesBaseTest.java Sat Oct 
31 12:59:51 2009
@@ -39,20 +39,22 @@
 /**
  * Servlet for cookie naming test.
  */
-public static class CookieName extends HttpServlet {
+public static class CookieServlet extends HttpServlet {
 
 private static final long serialVersionUID = 1L;
 
 private final String cookieName;
-
-public CookieName(String cookieName) {
+private final String cookieValue;
+
+public CookieServlet(String cookieName, String cookieValue) {
 this.cookieName = cookieName;
+this.cookieValue = cookieValue;
 }
 
 public void doGet(HttpServletRequest req, HttpServletResponse res) 
 throws IOException {
 try {
-Cookie cookie = new Cookie(cookieName,"Value");
+Cookie cookie = new Cookie(cookieName, cookieValue);
 res.addCookie(cookie);
 res.getWriter().write("Cookie name ok");
 } catch (IllegalArgumentException iae) {
@@ -68,14 +70,18 @@
 StandardContext ctx = 
 tomcat.addContext("/", System.getProperty("java.io.tmpdir"));
 
-Tomcat.addServlet(ctx, "invalid", new CookieName("na;me"));
+Tomcat.addServlet(ctx, "invalid", new CookieServlet("na;me", "value"));
 ctx.addServletMapping("/invalid", "invalid");
-Tomcat.addServlet(ctx, "invalidFwd", new CookieName("na/me"));
+Tomcat.addServlet(ctx, "invalidFwd",
+new CookieServlet("na/me", "value"));
 ctx.addServletMapping("/invalidFwd", "invalid

svn commit: r831544 - in /tomcat/trunk: java/org/apache/tomcat/util/http/Cookies.java test/org/apache/tomcat/util/http/TestCookiesAllowEquals.java test/org/apache/tomcat/util/http/TestCookiesDisallowE

2009-10-31 Thread markt
Author: markt
Date: Sat Oct 31 14:09:02 2009
New Revision: 831544

URL: http://svn.apache.org/viewvc?rev=831544&view=rev
Log:
Add a new new cookie option to allow the use of equals signs in cookies. 
Includes test cases and docs.

Added:
tomcat/trunk/test/org/apache/tomcat/util/http/TestCookiesAllowEquals.java
tomcat/trunk/test/org/apache/tomcat/util/http/TestCookiesDisallowEquals.java
Modified:
tomcat/trunk/java/org/apache/tomcat/util/http/Cookies.java
tomcat/trunk/webapps/docs/config/systemprops.xml

Modified: tomcat/trunk/java/org/apache/tomcat/util/http/Cookies.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/Cookies.java?rev=831544&r1=831543&r2=831544&view=diff
==
--- tomcat/trunk/java/org/apache/tomcat/util/http/Cookies.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/http/Cookies.java Sat Oct 31 
14:09:02 2009
@@ -53,6 +53,12 @@
 public static final boolean STRICT_SERVLET_COMPLIANCE;
 
 /**
+ * If true, cookie values are allowed to contain an equals character 
without
+ * being quoted.
+ */
+public static final boolean ALLOW_EQUALS_IN_VALUE;
+
+/**
  * If set to true, the / character will be treated as a
  * separator. Default is usually false. If STRICT_SERVLET_COMPLIANCE==true
  * then default is true. Explicitly setting always takes priority.
@@ -70,6 +76,10 @@
 "org.apache.catalina.STRICT_SERVLET_COMPLIANCE",
 "false")).booleanValue();
 
+ALLOW_EQUALS_IN_VALUE = Boolean.valueOf(System.getProperty(
+
"org.apache.tomcat.util.http.ServerCookie.ALLOW_EQUALS_IN_VALUE",
+"false")).booleanValue();
+
 String  fwdSlashIsSeparator = System.getProperty(
 
"org.apache.tomcat.util.http.ServerCookie.FWD_SLASH_IS_SEPARATOR");
 if (fwdSlashIsSeparator == null) {
@@ -588,7 +598,11 @@
  */
 public static final int getTokenEndPosition(byte bytes[], int off, int 
end){
 int pos = off;
-while (pos < end && !isSeparator(bytes[pos])) {pos++; }
+while (pos < end &&
+(!isSeparator(bytes[pos]) ||
+bytes[pos]=='=' && ALLOW_EQUALS_IN_VALUE)) {
+pos++;
+}
 
 if (pos > end)
 return end;

Added: tomcat/trunk/test/org/apache/tomcat/util/http/TestCookiesAllowEquals.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/http/TestCookiesAllowEquals.java?rev=831544&view=auto
==
--- tomcat/trunk/test/org/apache/tomcat/util/http/TestCookiesAllowEquals.java 
(added)
+++ tomcat/trunk/test/org/apache/tomcat/util/http/TestCookiesAllowEquals.java 
Sat Oct 31 14:09:02 2009
@@ -0,0 +1,99 @@
+/*
+ *  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.
+ */
+package org.apache.tomcat.util.http;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.startup.SimpleHttpClient;
+import org.apache.catalina.startup.TomcatBaseTest;
+import org.apache.catalina.startup.Tomcat;
+
+public class TestCookiesAllowEquals extends TomcatBaseTest{
+
+private static final String COOKIE_WITH_EQUALS = "name=value=withequals";
+
+public void testWithEquals() throws Exception {
+System.setProperty(
+
"org.apache.tomcat.util.http.ServerCookie.ALLOW_EQUALS_IN_VALUE",
+"true");
+
+TestCookieEqualsClient client = new TestCookieEqualsClient();
+client.doRequest();
+}
+
+private class TestCookieEqualsClient extends SimpleHttpClient {
+
+
+private void doRequest() throws Exception {
+Tomcat tomcat = getTomcatInstance();
+StandardContext root = tomcat.addContext("", TEMP_DIR);
+Tomcat.addServlet(root, "Simple", new Simple

Re: svn commit: r831536 - in /tomcat/trunk: java/org/apache/tomcat/util/http/ test/org/apache/tomcat/util/http/ webapps/docs/config/

2009-10-31 Thread Remy Maucherat
On Sat, 2009-10-31 at 12:59 +, ma...@apache.org wrote:
> Author: markt
> Date: Sat Oct 31 12:59:51 2009
> New Revision: 831536
> 
> URL: http://svn.apache.org/viewvc?rev=831536&view=rev
> Log:
> Add an explicit configuration option for cookie version switching and update 
> test cases and docs to include it.

The version switch flag is not correct.

Following a clarification, the Servlet EG has validated the concept of
cookie version switching, to support comments (if a comment is set on
the cookie, then the cookie automatically becomes v1, if it was v0; so
evidently it is now acceptable to switch versions to handle values that
are invalid in v0).

Rémy



-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



Re: svn commit: r831536 - in /tomcat/trunk: java/org/apache/tomcat/util/http/ test/org/apache/tomcat/util/http/ webapps/docs/config/

2009-10-31 Thread Mark Thomas
Remy Maucherat wrote:
> On Sat, 2009-10-31 at 12:59 +, ma...@apache.org wrote:
>> Author: markt
>> Date: Sat Oct 31 12:59:51 2009
>> New Revision: 831536
>>
>> URL: http://svn.apache.org/viewvc?rev=831536&view=rev
>> Log:
>> Add an explicit configuration option for cookie version switching and update 
>> test cases and docs to include it.
> 
> The version switch flag is not correct.
> 
> Following a clarification, the Servlet EG has validated the concept of
> cookie version switching, to support comments (if a comment is set on
> the cookie, then the cookie automatically becomes v1, if it was v0; so
> evidently it is now acceptable to switch versions to handle values that
> are invalid in v0).
> 
> Rémy

Thanks for that info - I wasn't aware of that. I'll update the cookie handling
code accordingly.

Cheers,

Mark


-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org