This is an automated email from the ASF dual-hosted git repository.

paulrutter pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git


The following commit(s) were added to refs/heads/master by this push:
     new a1d6c1fb27 FELIX-6756 Cookie name "Path" is a reserved token - Apply 
fix from patch - Add unit tests
a1d6c1fb27 is described below

commit a1d6c1fb270268237d75fc37e21bf78bbad914fa
Author: Paul Rütter <[email protected]>
AuthorDate: Mon Mar 10 08:52:10 2025 +0100

    FELIX-6756 Cookie name "Path" is a reserved token
    - Apply fix from patch
    - Add unit tests
---
 .../felix/http/jakartawrappers/CookieWrapper.java  | 68 ++++++++++++++-------
 .../felix/http/javaxwrappers/CookieWrapper.java    | 70 +++++++++++++++-------
 .../http/jakartawrappers/CookieWrapperTest.java    | 44 ++++++++++++++
 .../http/javaxwrappers/CookieWrapperTest.java      | 44 ++++++++++++++
 4 files changed, 186 insertions(+), 40 deletions(-)

diff --git 
a/http/wrappers/src/main/java/org/apache/felix/http/jakartawrappers/CookieWrapper.java
 
b/http/wrappers/src/main/java/org/apache/felix/http/jakartawrappers/CookieWrapper.java
index 9c85fdeb51..55f9416c90 100644
--- 
a/http/wrappers/src/main/java/org/apache/felix/http/jakartawrappers/CookieWrapper.java
+++ 
b/http/wrappers/src/main/java/org/apache/felix/http/jakartawrappers/CookieWrapper.java
@@ -50,64 +50,92 @@ public class CookieWrapper extends Cookie {
      * @param c Wrapped cookie
      */
     public CookieWrapper(@NotNull final javax.servlet.http.Cookie c) {
-        super(c.getName(), c.getValue());
+        super("dummy", "dummy");
         this.cookie = c;
-        super.setComment(c.getComment());
-        if ( c.getDomain() != null ) {
-            super.setDomain(c.getDomain());
-        }
-        super.setHttpOnly(c.isHttpOnly());
-        super.setMaxAge(c.getMaxAge());
-        super.setPath(c.getPath());
-        super.setSecure(c.getSecure());
-        super.setVersion(c.getVersion());
+    }
+
+    @Override
+    public String getName() {
+        return this.cookie.getName();
+    }
+
+    @Override
+    public String getValue() {
+        return this.cookie.getValue();
+    }
+
+    @Override
+    public void setValue(String value) {
+        this.cookie.setValue(value);
     }
 
     @Override
     public void setComment(final String purpose) {
         this.cookie.setComment(purpose);
-        super.setComment(purpose);
+    }
+
+    @Override
+    public String getComment() {
+        return this.cookie.getComment();
     }
 
     @Override
     public void setDomain(final String domain) {
         this.cookie.setDomain(domain);
-        super.setDomain(domain);
+    }
+
+    @Override
+    public String getDomain() {
+        return this.cookie.getDomain();
     }
 
     @Override
     public void setMaxAge(final int expiry) {
         this.cookie.setMaxAge(expiry);
-        super.setMaxAge(expiry);
+    }
+
+    @Override
+    public int getMaxAge() {
+        return this.cookie.getMaxAge();
     }
 
     @Override
     public void setPath(final String uri) {
         this.cookie.setPath(uri);
-        super.setPath(uri);
+    }
+
+    @Override
+    public String getPath() {
+        return this.cookie.getPath();
     }
 
     @Override
     public void setSecure(final boolean flag) {
         this.cookie.setSecure(flag);
-        super.setSecure(flag);
     }
 
     @Override
-    public void setValue(final String newValue) {
-        this.cookie.setValue(newValue);
-        super.setValue(newValue);
+    public boolean getSecure() {
+        return this.cookie.getSecure();
     }
 
     @Override
     public void setVersion(final int v) {
         this.cookie.setVersion(v);
-        super.setVersion(v);
+    }
+
+    @Override
+    public int getVersion() {
+        return this.cookie.getVersion();
     }
 
     @Override
     public void setHttpOnly(final boolean isHttpOnly) {
         this.cookie.setHttpOnly(isHttpOnly);
-        super.setHttpOnly(isHttpOnly);
+    }
+
+    @Override
+    public boolean isHttpOnly() {
+        return this.cookie.isHttpOnly();
     }
 }
diff --git 
a/http/wrappers/src/main/java/org/apache/felix/http/javaxwrappers/CookieWrapper.java
 
b/http/wrappers/src/main/java/org/apache/felix/http/javaxwrappers/CookieWrapper.java
index 7c8bcd79c8..856f8b45b6 100644
--- 
a/http/wrappers/src/main/java/org/apache/felix/http/javaxwrappers/CookieWrapper.java
+++ 
b/http/wrappers/src/main/java/org/apache/felix/http/javaxwrappers/CookieWrapper.java
@@ -47,67 +47,97 @@ public class CookieWrapper extends 
javax.servlet.http.Cookie {
 
     /**
      * Create new cookie
+     *
      * @param c Wrapped cookie
      */
     public CookieWrapper(@NotNull final Cookie c) {
-        super(c.getName(), c.getValue());
+        super("dummy", "dummy");
         this.cookie = c;
-        super.setComment(c.getComment());
-        if ( c.getDomain() != null ) {
-            super.setDomain(c.getDomain());
-        }
-        super.setHttpOnly(c.isHttpOnly());
-        super.setMaxAge(c.getMaxAge());
-        super.setPath(c.getPath());
-        super.setSecure(c.getSecure());
-        super.setVersion(c.getVersion());
+    }
+
+    @Override
+    public String getName() {
+        return this.cookie.getName();
+    }
+
+    @Override
+    public String getValue() {
+        return this.cookie.getValue();
+    }
+
+    @Override
+    public void setValue(String value) {
+        this.cookie.setValue(value);
     }
 
     @Override
     public void setComment(final String purpose) {
         this.cookie.setComment(purpose);
-        super.setComment(purpose);
+    }
+
+    @Override
+    public String getComment() {
+        return this.cookie.getComment();
     }
 
     @Override
     public void setDomain(final String domain) {
         this.cookie.setDomain(domain);
-        super.setDomain(domain);
+    }
+
+    @Override
+    public String getDomain() {
+        return this.cookie.getDomain();
     }
 
     @Override
     public void setMaxAge(final int expiry) {
         this.cookie.setMaxAge(expiry);
-        super.setMaxAge(expiry);
+    }
+
+    @Override
+    public int getMaxAge() {
+        return this.cookie.getMaxAge();
     }
 
     @Override
     public void setPath(final String uri) {
         this.cookie.setPath(uri);
-        super.setPath(uri);
+    }
+
+    @Override
+    public String getPath() {
+        return this.cookie.getPath();
     }
 
     @Override
     public void setSecure(final boolean flag) {
         this.cookie.setSecure(flag);
-        super.setSecure(flag);
     }
 
     @Override
-    public void setValue(final String newValue) {
-        this.cookie.setValue(newValue);
-        super.setValue(newValue);
+    public boolean getSecure() {
+        return this.cookie.getSecure();
     }
 
     @Override
     public void setVersion(final int v) {
         this.cookie.setVersion(v);
-        super.setVersion(v);
+    }
+
+    @Override
+    public int getVersion() {
+        return this.cookie.getVersion();
     }
 
     @Override
     public void setHttpOnly(final boolean isHttpOnly) {
         this.cookie.setHttpOnly(isHttpOnly);
-        super.setHttpOnly(isHttpOnly);
     }
+
+    @Override
+    public boolean isHttpOnly() {
+        return this.cookie.isHttpOnly();
+    }
+
 }
diff --git 
a/http/wrappers/src/test/java/org/apache/felix/http/jakartawrappers/CookieWrapperTest.java
 
b/http/wrappers/src/test/java/org/apache/felix/http/jakartawrappers/CookieWrapperTest.java
new file mode 100644
index 0000000000..0bb6334767
--- /dev/null
+++ 
b/http/wrappers/src/test/java/org/apache/felix/http/jakartawrappers/CookieWrapperTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.felix.http.jakartawrappers;
+
+import javax.servlet.http.Cookie;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+
+public class CookieWrapperTest {
+    @Test
+    public void testReservedCookieNames() {
+        testCookie("Path");
+        testCookie("MaxAge");
+        testCookie("Comment");
+    }
+
+    private static void testCookie(String cookieName) {
+        Cookie pathCookie = Mockito.mock(Cookie.class);
+        when(pathCookie.getName()).thenReturn(cookieName);
+
+        // Threw `java.lang.IllegalArgumentException: Cookie name "Path" is a 
reserved token` before
+        CookieWrapper cookieWrapper = new CookieWrapper(pathCookie);
+
+        assertEquals(cookieName, cookieWrapper.getName());
+    }
+}
diff --git 
a/http/wrappers/src/test/java/org/apache/felix/http/javaxwrappers/CookieWrapperTest.java
 
b/http/wrappers/src/test/java/org/apache/felix/http/javaxwrappers/CookieWrapperTest.java
new file mode 100644
index 0000000000..cea5110a62
--- /dev/null
+++ 
b/http/wrappers/src/test/java/org/apache/felix/http/javaxwrappers/CookieWrapperTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.felix.http.javaxwrappers;
+
+import jakarta.servlet.http.Cookie;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+
+public class CookieWrapperTest {
+    @Test
+    public void testReservedCookieNames() {
+        testCookie("Path");
+        testCookie("MaxAge");
+        testCookie("Comment");
+    }
+
+    private static void testCookie(String cookieName) {
+        Cookie pathCookie = Mockito.mock(Cookie.class);
+        when(pathCookie.getName()).thenReturn(cookieName);
+
+        // Threw `java.lang.IllegalArgumentException: Cookie name "Path" is a 
reserved token` before
+        CookieWrapper cookieWrapper = new CookieWrapper(pathCookie);
+
+        assertEquals(cookieName, cookieWrapper.getName());
+    }
+}

Reply via email to