Author: jfrederic.clere(a)jboss.com
Date: 2009-04-20 05:49:53 -0400 (Mon, 20 Apr 2009)
New Revision: 1019
Modified:
trunk/test/java/org/jboss/web/cookies/CookiesTestCase.java
trunk/test/webapps/cookies/test.jsp
Log:
Add a test for bugzilla ASF 45272.
Modified: trunk/test/java/org/jboss/web/cookies/CookiesTestCase.java
===================================================================
--- trunk/test/java/org/jboss/web/cookies/CookiesTestCase.java 2009-04-19 17:37:46 UTC
(rev 1018)
+++ trunk/test/java/org/jboss/web/cookies/CookiesTestCase.java 2009-04-20 09:49:53 UTC
(rev 1019)
@@ -136,7 +136,18 @@
public void testTestW39() { writeTest(39); }
public void testTestW40() { writeTest(40); }
+ // Bugzilla 45272
+ public void testTestW41() { writeTest(41, "a", "Path=/"); }
+ public void testTestW42() { writeTest(42, "a", "Version=1;
Path=/"); }
+
+
+ // Store the received cookies.
+ private String cookies [] = null;
+
public void writeTest(int test) {
+ writeTest(test, null, null);
+ }
+ public void writeTest(int test, String name, String token) {
try {
String result = Mytest(test, null, false);
if (result != null)
@@ -144,7 +155,22 @@
} catch (Exception ex) {
ex.printStackTrace();
fail("Test failed because of " + ex);
+ return;
}
+ /* Tests the cookies */
+ if (name == null)
+ return; // nothing to do...
+ if (cookies != null) {
+ String sname = name + "=";
+ for (int i=0; i<cookies.length; i++) {
+ if (cookies[i].startsWith(sname)) {
+ if (cookies[i].indexOf(token)==-1) {
+ fail("Can't find token in " + cookies[i]);
+ return;
+ }
+ }
+ }
+ }
}
public void readTest(int test, String cookie) {
@@ -186,6 +212,7 @@
String header = reader.readLine();
int contentLength = 0;
String error = "Unknown";
+ cookies = null;
while (!"".equals(header)) {
int colon = header.indexOf(':');
String headerName = header.substring(0, colon).trim();
@@ -196,6 +223,19 @@
if ("ERROR".equalsIgnoreCase(headerName)) {
error = headerValue;
}
+ if ("set-cookie".equalsIgnoreCase(headerName)) {
+ if (cookies == null) {
+ cookies = new String [1];
+ cookies[0] = headerValue;
+ } else {
+ String [] oldcookies = cookies;
+ cookies = new String [oldcookies.length + 1];
+ for (int i=0; i<oldcookies.length; i++) {
+ cookies[i] = oldcookies[i];
+ }
+ cookies[oldcookies.length] = headerValue;
+ }
+ }
header = reader.readLine();
}
if (contentLength > 0) {
Modified: trunk/test/webapps/cookies/test.jsp
===================================================================
--- trunk/test/webapps/cookies/test.jsp 2009-04-19 17:37:46 UTC (rev 1018)
+++ trunk/test/webapps/cookies/test.jsp 2009-04-20 09:49:53 UTC (rev 1019)
@@ -92,6 +92,10 @@
case 38: test(response, out, "a", "=:", "foo",
"b=:ar"); break;
case 39: test(response, out, "a", ":", "foo",
"b:ar"); break;
case 40: test(response, out, "a", "=", "foo",
"b=ar"); break;
+
+ case 41: test(response, out, "/", 0); break;
+ case 42: test(response, out, "/", 1); break;
+
default: sendError(response, "Unknown test");break;
}
} else {
@@ -193,4 +197,11 @@
cookie = new Cookie(name2, val2);
response.addCookie(cookie);
out.println("OK");
+ }
+void test(HttpServletResponse response, JspWriter out, String path, int version) throws
Exception {
+ Cookie cookie = new Cookie("a", "b");
+ cookie.setVersion(version);
+ cookie.setPath(path);
+ response.addCookie(cookie);
+ out.println("OK");
}%>