You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2019/11/30 11:54:06 UTC

[tomcat] 01/02: Refactor to reduce code volume and to allow for other method tests

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

markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 4a8ad6d0769a4f6335886b4175d317fc513b723a
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Nov 29 22:55:15 2019 +0000

    Refactor to reduce code volume and to allow for other method tests
---
 .../apache/tomcat/util/http/TestRequestUtil.java   | 162 ---------------------
 .../tomcat/util/http/TestRequestUtilNormalize.java |  77 ++++++++++
 2 files changed, 77 insertions(+), 162 deletions(-)

diff --git a/test/org/apache/tomcat/util/http/TestRequestUtil.java b/test/org/apache/tomcat/util/http/TestRequestUtil.java
deleted file mode 100644
index 02deb5e..0000000
--- a/test/org/apache/tomcat/util/http/TestRequestUtil.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * 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 org.junit.Assert;
-import org.junit.Test;
-
-public class TestRequestUtil {
-
-    @Test
-    public void testNormalize01() {
-        doTestNormalize("//something", "/something");
-    }
-
-    @Test
-    public void testNormalize02() {
-        doTestNormalize("some//thing", "/some/thing");
-    }
-
-    @Test
-    public void testNormalize03() {
-        doTestNormalize("something//", "/something/");
-    }
-
-    @Test
-    public void testNormalize04() {
-        doTestNormalize("//", "/");
-    }
-
-        @Test
-    public void testNormalize05() {
-        doTestNormalize("//", "/");
-    }
-
-    @Test
-    public void testNormalize06() {
-        doTestNormalize("///", "/");
-    }
-
-    @Test
-    public void testNormalize07() {
-        doTestNormalize("////", "/");
-    }
-
-    @Test
-    public void testNormalize08() {
-        doTestNormalize("/.", "/");
-    }
-
-    @Test
-    public void testNormalize09() {
-        doTestNormalize("/./", "/");
-    }
-
-    @Test
-    public void testNormalize10() {
-        doTestNormalize(".", "/");
-    }
-
-    @Test
-    public void testNormalize11() {
-        doTestNormalize("/..", null);
-    }
-
-    @Test
-    public void testNormalize12() {
-        doTestNormalize("/../", null);
-    }
-
-    @Test
-    public void testNormalize13() {
-        doTestNormalize("..", null);
-    }
-
-    @Test
-    public void testNormalize14() {
-        doTestNormalize("//..", null);
-    }
-
-    @Test
-    public void testNormalize15() {
-        doTestNormalize("//../", null);
-    }
-
-    @Test
-    public void testNormalize16() {
-        doTestNormalize("/./..", null);
-    }
-
-    @Test
-    public void testNormalize17() {
-        doTestNormalize("/./../", null);
-    }
-
-    @Test
-    public void testNormalize18() {
-        doTestNormalize("/a/../..", null);
-    }
-
-    @Test
-    public void testNormalize19() {
-        doTestNormalize("/a/../../", null);
-    }
-
-    @Test
-    public void testNormalize20() {
-        doTestNormalize("/a/..", "/");
-    }
-
-    @Test
-    public void testNormalize21() {
-        doTestNormalize("/a/.", "/a");
-    }
-
-    @Test
-    public void testNormalize22() {
-        doTestNormalize("/a/../", "/");
-    }
-
-    @Test
-    public void testNormalize23() {
-        doTestNormalize("/a/./", "/a/");
-    }
-
-    @Test
-    public void testNormalize24() {
-        doTestNormalize("/a/b/..", "/a");
-    }
-
-    @Test
-    public void testNormalize25() {
-        doTestNormalize("/a/b/.", "/a/b");
-    }
-
-    @Test
-    public void testNormalize26() {
-        doTestNormalize("/a/b/../", "/a/");
-    }
-
-    @Test
-    public void testNormalize27() {
-        doTestNormalize("/a/b/./", "/a/b/");
-    }
-
-    private void doTestNormalize(String input, String expected) {
-        Assert.assertEquals(expected,RequestUtil.normalize(input));
-    }
-}
diff --git a/test/org/apache/tomcat/util/http/TestRequestUtilNormalize.java b/test/org/apache/tomcat/util/http/TestRequestUtilNormalize.java
new file mode 100644
index 0000000..b642868
--- /dev/null
+++ b/test/org/apache/tomcat/util/http/TestRequestUtilNormalize.java
@@ -0,0 +1,77 @@
+/*
+ * 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.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+
+@RunWith(Parameterized.class)
+public class TestRequestUtilNormalize {
+
+    @Parameterized.Parameters(name = "{index}: input[{0}]")
+    public static Collection<Object[]> parameters() {
+        List<Object[]> parameterSets = new ArrayList<>();
+
+        parameterSets.add(new String[] { "//something", "/something" });
+        parameterSets.add(new String[] { "some//thing", "/some/thing" });
+        parameterSets.add(new String[] { "something//", "/something/" });
+        parameterSets.add(new String[] { "//", "/" });
+        parameterSets.add(new String[] { "///", "/" });
+        parameterSets.add(new String[] { "////", "/" });
+        parameterSets.add(new String[] { "/.", "/" });
+        parameterSets.add(new String[] { "/./", "/" });
+        parameterSets.add(new String[] { ".", "/" });
+        parameterSets.add(new String[] { "/..", null });
+        parameterSets.add(new String[] { "/../", null });
+        parameterSets.add(new String[] { "..", null });
+        parameterSets.add(new String[] { "//..", null });
+        parameterSets.add(new String[] { "//../", null });
+        parameterSets.add(new String[] { "/./..", null });
+        parameterSets.add(new String[] { "/./../", null });
+        parameterSets.add(new String[] { "/a/../..", null });
+        parameterSets.add(new String[] { "/a/../../", null });
+        parameterSets.add(new String[] { "/a/..", "/" });
+        parameterSets.add(new String[] { "/a/.", "/a" });
+        parameterSets.add(new String[] { "/a/../", "/" });
+        parameterSets.add(new String[] { "/a/./", "/a/" });
+        parameterSets.add(new String[] { "/a/b/..", "/a" });
+        parameterSets.add(new String[] { "/a/b/.", "/a/b" });
+        parameterSets.add(new String[] { "/a/b/../", "/a/" });
+        parameterSets.add(new String[] { "/a/b/./", "/a/b/" });
+
+        return parameterSets;
+    }
+
+
+    @Parameter(0)
+    public String input;
+    @Parameter(1)
+    public String expected;
+
+
+    @Test
+    public void testNormalize() {
+        Assert.assertEquals(expected,RequestUtil.normalize(input));
+    }
+}


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