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

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


The following commit(s) were added to refs/heads/10.1.x by this push:
     new 30968b0d96 Refactor AJP tests to use a common base class
30968b0d96 is described below

commit 30968b0d9632bb2decc62c7b4d7ff70d6b765b74
Author: Mark Thomas <[email protected]>
AuthorDate: Tue Oct 20 20:52:05 2026 +0100

    Refactor AJP tests to use a common base class
    
    Fixes broken AJP tests
---
 test/org/apache/coyote/ajp/AjpBaseTest.java        | 56 ++++++++++++++++++++++
 .../coyote/ajp/TestAbstractAjpProcessor.java       | 28 +----------
 test/org/apache/coyote/ajp/TestAjpSecurity.java    |  3 +-
 3 files changed, 59 insertions(+), 28 deletions(-)

diff --git a/test/org/apache/coyote/ajp/AjpBaseTest.java 
b/test/org/apache/coyote/ajp/AjpBaseTest.java
new file mode 100644
index 0000000000..f7e24fb3d1
--- /dev/null
+++ b/test/org/apache/coyote/ajp/AjpBaseTest.java
@@ -0,0 +1,56 @@
+/*
+ *  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.coyote.ajp;
+
+import org.junit.Before;
+
+import org.apache.catalina.startup.TomcatBaseTest;
+
+/**
+ * Base class for tests that need an AJP connector rather than the default 
HTTP connector.
+ */
+public abstract class AjpBaseTest extends TomcatBaseTest {
+
+    @Before
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+
+        getTomcatInstance().getConnector().setProperty("secretRequired", 
"false");
+    }
+
+
+    @Override
+    protected String getProtocol() {
+        /*
+         * The tests are all setup for HTTP so need to convert the protocol 
values to AJP.
+         */
+        // Has a protocol been specified
+        String protocol = System.getProperty("tomcat.test.protocol");
+
+        // Use NIO by default
+        if (protocol == null) {
+            protocol = "org.apache.coyote.ajp.AjpNioProtocol";
+        } else if (protocol.contains("Nio2")) {
+            protocol = "org.apache.coyote.ajp.AjpNio2Protocol";
+        } else {
+            protocol = "org.apache.coyote.ajp.AjpNioProtocol";
+        }
+
+        return protocol;
+    }
+}
diff --git a/test/org/apache/coyote/ajp/TestAbstractAjpProcessor.java 
b/test/org/apache/coyote/ajp/TestAbstractAjpProcessor.java
index 83a0600bd8..a89dbb6560 100644
--- a/test/org/apache/coyote/ajp/TestAbstractAjpProcessor.java
+++ b/test/org/apache/coyote/ajp/TestAbstractAjpProcessor.java
@@ -38,45 +38,21 @@ import org.junit.Test;
 
 import org.apache.catalina.Context;
 import org.apache.catalina.Globals;
-import org.apache.catalina.connector.Connector;
 import org.apache.catalina.startup.Tomcat;
-import org.apache.catalina.startup.TomcatBaseTest;
 import org.apache.tomcat.util.http.Method;
 import org.apache.tomcat.util.res.StringManager;
 
-public class TestAbstractAjpProcessor extends TomcatBaseTest {
+public class TestAbstractAjpProcessor extends AjpBaseTest {
 
     @Before
     @Override
     public void setUp() throws Exception {
         super.setUp();
 
-        Connector c = getTomcatInstance().getConnector();
-        c.setProperty("secretRequired", "false");
-        c.setProperty("allowedRequestAttributesPattern", "MYATTRIBUTE.*");
+        
getTomcatInstance().getConnector().setProperty("allowedRequestAttributesPattern",
 "MYATTRIBUTE.*");
     }
 
 
-    @Override
-    protected String getProtocol() {
-        /*
-         * The tests are all setup for HTTP so need to convert the protocol 
values to AJP.
-         */
-        // Has a protocol been specified
-        String protocol = System.getProperty("tomcat.test.protocol");
-
-        // Use NIO by default
-        if (protocol == null) {
-            protocol = "org.apache.coyote.ajp.AjpNioProtocol";
-        } else if (protocol.contains("Nio2")) {
-            protocol = "org.apache.coyote.ajp.AjpNio2Protocol";
-        } else {
-            protocol = "org.apache.coyote.ajp.AjpNioProtocol";
-        }
-
-        return protocol;
-    }
-
     private void doSnoopTest(RequestDescriptor desc) throws Exception {
 
         final int ajpPacketSize = 16000;
diff --git a/test/org/apache/coyote/ajp/TestAjpSecurity.java 
b/test/org/apache/coyote/ajp/TestAjpSecurity.java
index df4cea10bf..50b49f4108 100644
--- a/test/org/apache/coyote/ajp/TestAjpSecurity.java
+++ b/test/org/apache/coyote/ajp/TestAjpSecurity.java
@@ -34,14 +34,13 @@ import org.apache.catalina.Context;
 import org.apache.catalina.Wrapper;
 import org.apache.catalina.connector.Connector;
 import org.apache.catalina.startup.Tomcat;
-import org.apache.catalina.startup.TomcatBaseTest;
 import org.apache.tomcat.util.buf.HexUtils;
 
 /*
  * Tests that can't easily be added to the {@code org.apache.tomcat.security} 
package because they need access to
  * package private classes.
  */
-public class TestAjpSecurity extends TomcatBaseTest {
+public class TestAjpSecurity extends AjpBaseTest {
 
 
     @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to