Author: jboynes
Date: Wed Jan  8 05:54:43 2014
New Revision: 1556449

URL: http://svn.apache.org/r1556449
Log:
test cases for Set-Cookie generation
Added:
    tomcat/trunk/test/org/apache/tomcat/util/http/TestSetCookieSupport.java   
(with props)
    
tomcat/trunk/test/org/apache/tomcat/util/http/TestSetCookieSupportSeparatorsAllowed.java
   (with props)

Added: tomcat/trunk/test/org/apache/tomcat/util/http/TestSetCookieSupport.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/http/TestSetCookieSupport.java?rev=1556449&view=auto
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/util/http/TestSetCookieSupport.java 
(added)
+++ tomcat/trunk/test/org/apache/tomcat/util/http/TestSetCookieSupport.java Wed 
Jan  8 05:54:43 2014
@@ -0,0 +1,112 @@
+/*
+ * 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 javax.servlet.http.Cookie;
+
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class TestSetCookieSupport {
+
+    @Test
+    public void v0simpleCookie() {
+        Cookie cookie = new Cookie("foo", "bar");
+        Assert.assertEquals("foo=bar", 
SetCookieSupport.generateHeader(cookie));
+    }
+
+    @Test
+    public void v0NullValue() {
+        Cookie cookie = new Cookie("foo", null);
+//        Assert.assertEquals("foo=", SetCookieSupport.generateHeader(cookie));
+        Assert.assertEquals("foo=\"\"", 
SetCookieSupport.generateHeader(cookie));
+    }
+
+    @Test
+    public void v0QuotedValue() {
+        Cookie cookie = new Cookie("foo", "\"bar\"");
+        Assert.assertEquals("foo=\"bar\"", 
SetCookieSupport.generateHeader(cookie));
+    }
+
+    @Test
+    public void v0ValueContainsSemicolon() {
+        Cookie cookie = new Cookie("foo", "a;b");
+        // should probably throw IAE?
+        Assert.assertEquals("foo=\"a;b\"; Version=1", 
SetCookieSupport.generateHeader(cookie));
+    }
+
+    @Test
+    public void v0ValueContainsComma() {
+        Cookie cookie = new Cookie("foo", "a,b");
+        // should probably throw IAE?
+        Assert.assertEquals("foo=\"a,b\"; Version=1", 
SetCookieSupport.generateHeader(cookie));
+    }
+
+    @Test
+    public void v0ValueContainsSpace() {
+        Cookie cookie = new Cookie("foo", "a b");
+        // should probably throw IAE?
+        Assert.assertEquals("foo=\"a b\"; Version=1", 
SetCookieSupport.generateHeader(cookie));
+    }
+
+    @Test
+    public void v0ValueContainsEquals() {
+        Cookie cookie = new Cookie("foo", "a=b");
+        Assert.assertEquals("foo=\"a=b\"; Version=1", 
SetCookieSupport.generateHeader(cookie));
+    }
+
+    @Test
+    public void v0ValueContainsQuote() {
+        Cookie cookie = new Cookie("foo", "a\"b");
+//        Assert.assertEquals("foo=a\"b", 
SetCookieSupport.generateHeader(cookie));
+        Assert.assertEquals("foo=\"a\\\"b\"; Version=1", 
SetCookieSupport.generateHeader(cookie));
+    }
+
+    @Ignore("bug 55975")
+    @Test
+    public void v0ValueContainsNonV0Separator() {
+        Cookie cookie = new Cookie("foo", "a()<>@:\\\"/[]?={}b");
+        // Assert.assertEquals("foo=a()<>@:\\\"/[]?{}=b", 
SetCookieSupport.generateHeader(cookie));
+        Assert.assertEquals("foo=\"a()<>@,;:\\\\\\\"/[]?={}b\"; Version=1", 
SetCookieSupport.generateHeader(cookie));
+    }
+
+    @Ignore("bug 55975")
+    @Test
+    public void v0ValueContainsBackslash() {
+        Cookie cookie = new Cookie("foo", "a\\b");
+//        Assert.assertEquals("foo=a\\b", 
SetCookieSupport.generateHeader(cookie));
+        Assert.assertEquals("foo=\"a\\\\b\"; Version=1", 
SetCookieSupport.generateHeader(cookie));
+    }
+
+
+    @Ignore("bug 55975")
+    @Test
+    public void v0ValueContainsBackslashAtEnd() {
+        Cookie cookie = new Cookie("foo", "a\\");
+//        Assert.assertEquals("foo=a\\", 
SetCookieSupport.generateHeader(cookie));
+        Assert.assertEquals("foo=\"a\\\\\"; Version=1", 
SetCookieSupport.generateHeader(cookie));
+    }
+
+    @Ignore("bug 55975")
+    @Test
+    public void v0ValueContainsBackslashAndQuote() {
+        Cookie cookie = new Cookie("foo", "a\"b\\c");
+//        Assert.assertEquals("foo=a\"b\\c", 
SetCookieSupport.generateHeader(cookie));
+        Assert.assertEquals("foo=\"a\\\"b\\\\c\"; Version=1", 
SetCookieSupport.generateHeader(cookie));
+    }
+}

Propchange: 
tomcat/trunk/test/org/apache/tomcat/util/http/TestSetCookieSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
tomcat/trunk/test/org/apache/tomcat/util/http/TestSetCookieSupportSeparatorsAllowed.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/http/TestSetCookieSupportSeparatorsAllowed.java?rev=1556449&view=auto
==============================================================================
--- 
tomcat/trunk/test/org/apache/tomcat/util/http/TestSetCookieSupportSeparatorsAllowed.java
 (added)
+++ 
tomcat/trunk/test/org/apache/tomcat/util/http/TestSetCookieSupportSeparatorsAllowed.java
 Wed Jan  8 05:54:43 2014
@@ -0,0 +1,100 @@
+/*
+ * 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 javax.servlet.http.Cookie;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestSetCookieSupportSeparatorsAllowed {
+
+    static {
+        
System.setProperty("org.apache.tomcat.util.http.ServerCookie.ALLOW_HTTP_SEPARATORS_IN_V0",
 "true");
+        
System.setProperty("org.apache.tomcat.util.http.ServerCookie.FWD_SLASH_IS_SEPARATOR",
 "true");
+    }
+    @Test
+    public void v0simpleCookie() {
+        Cookie cookie = new Cookie("foo", "bar");
+        Assert.assertEquals("foo=bar", 
SetCookieSupport.generateHeader(cookie));
+    }
+
+    @Test
+    public void v0NullValue() {
+        Cookie cookie = new Cookie("foo", null);
+//        Assert.assertEquals("foo=", SetCookieSupport.generateHeader(cookie));
+        Assert.assertEquals("foo=\"\"", 
SetCookieSupport.generateHeader(cookie));
+    }
+
+    @Test
+    public void v0QuotedValue() {
+        Cookie cookie = new Cookie("foo", "\"bar\"");
+        Assert.assertEquals("foo=\"bar\"", 
SetCookieSupport.generateHeader(cookie));
+    }
+
+    @Test
+    public void v0ValueContainsSemicolon() {
+        Cookie cookie = new Cookie("foo", "a;b");
+        // should probably throw IAE?
+        Assert.assertEquals("foo=\"a;b\"; Version=1", 
SetCookieSupport.generateHeader(cookie));
+    }
+
+    @Test
+    public void v0ValueContainsComma() {
+        Cookie cookie = new Cookie("foo", "a,b");
+        // should probably throw IAE?
+        Assert.assertEquals("foo=\"a,b\"; Version=1", 
SetCookieSupport.generateHeader(cookie));
+    }
+
+    @Test
+    public void v0ValueContainsSpace() {
+        Cookie cookie = new Cookie("foo", "a b");
+        // should probably throw IAE?
+        Assert.assertEquals("foo=\"a b\"; Version=1", 
SetCookieSupport.generateHeader(cookie));
+    }
+
+    @Test
+    public void v0ValueContainsQuote() {
+        Cookie cookie = new Cookie("foo", "a\"b");
+        Assert.assertEquals("foo=a\"b", 
SetCookieSupport.generateHeader(cookie));
+    }
+
+    @Test
+    public void v0ValueContainsNonV0Separator() {
+        Cookie cookie = new Cookie("foo", "a()<>@:\\\"/[]?={}b");
+        Assert.assertEquals("foo=a()<>@:\\\"/[]?={}b", 
SetCookieSupport.generateHeader(cookie));
+    }
+
+    @Test
+    public void v0ValueContainsBackslash() {
+        Cookie cookie = new Cookie("foo", "a\\b");
+        Assert.assertEquals("foo=a\\b", 
SetCookieSupport.generateHeader(cookie));
+    }
+
+
+    @Test
+    public void v0ValueContainsBackslashAtEnd() {
+        Cookie cookie = new Cookie("foo", "a\\");
+        Assert.assertEquals("foo=a\\", 
SetCookieSupport.generateHeader(cookie));
+    }
+
+    @Test
+    public void v0ValueContainsBackslashAndQuote() {
+        Cookie cookie = new Cookie("foo", "a\"b\\c");
+        Assert.assertEquals("foo=a\"b\\c", 
SetCookieSupport.generateHeader(cookie));
+    }
+}

Propchange: 
tomcat/trunk/test/org/apache/tomcat/util/http/TestSetCookieSupportSeparatorsAllowed.java
------------------------------------------------------------------------------
    svn:eol-style = native



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

Reply via email to