Skip to content

Commit 2231557

Browse files
committed
Refactor AJP tests to use a common base class
Fixes broken AJP tests
1 parent 6c03276 commit 2231557

3 files changed

Lines changed: 59 additions & 28 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.coyote.ajp;
18+
19+
import org.junit.Before;
20+
21+
import org.apache.catalina.startup.TomcatBaseTest;
22+
23+
/**
24+
* Base class for tests that need an AJP connector rather than the default HTTP connector.
25+
*/
26+
public abstract class AjpBaseTest extends TomcatBaseTest {
27+
28+
@Before
29+
@Override
30+
public void setUp() throws Exception {
31+
super.setUp();
32+
33+
getTomcatInstance().getConnector().setProperty("secretRequired", "false");
34+
}
35+
36+
37+
@Override
38+
protected String getProtocol() {
39+
/*
40+
* The tests are all setup for HTTP so need to convert the protocol values to AJP.
41+
*/
42+
// Has a protocol been specified
43+
String protocol = System.getProperty("tomcat.test.protocol");
44+
45+
// Use NIO by default
46+
if (protocol == null) {
47+
protocol = "org.apache.coyote.ajp.AjpNioProtocol";
48+
} else if (protocol.contains("Nio2")) {
49+
protocol = "org.apache.coyote.ajp.AjpNio2Protocol";
50+
} else {
51+
protocol = "org.apache.coyote.ajp.AjpNioProtocol";
52+
}
53+
54+
return protocol;
55+
}
56+
}

‎test/org/apache/coyote/ajp/TestAbstractAjpProcessor.java‎

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,45 +38,21 @@
3838

3939
import org.apache.catalina.Context;
4040
import org.apache.catalina.Globals;
41-
import org.apache.catalina.connector.Connector;
4241
import org.apache.catalina.startup.Tomcat;
43-
import org.apache.catalina.startup.TomcatBaseTest;
4442
import org.apache.tomcat.util.http.Method;
4543
import org.apache.tomcat.util.res.StringManager;
4644

47-
public class TestAbstractAjpProcessor extends TomcatBaseTest {
45+
public class TestAbstractAjpProcessor extends AjpBaseTest {
4846

4947
@Before
5048
@Override
5149
public void setUp() throws Exception {
5250
super.setUp();
5351

54-
Connector c = getTomcatInstance().getConnector();
55-
c.setProperty("secretRequired", "false");
56-
c.setProperty("allowedRequestAttributesPattern", "MYATTRIBUTE.*");
52+
getTomcatInstance().getConnector().setProperty("allowedRequestAttributesPattern", "MYATTRIBUTE.*");
5753
}
5854

5955

60-
@Override
61-
protected String getProtocol() {
62-
/*
63-
* The tests are all setup for HTTP so need to convert the protocol values to AJP.
64-
*/
65-
// Has a protocol been specified
66-
String protocol = System.getProperty("tomcat.test.protocol");
67-
68-
// Use NIO by default
69-
if (protocol == null) {
70-
protocol = "org.apache.coyote.ajp.AjpNioProtocol";
71-
} else if (protocol.contains("Nio2")) {
72-
protocol = "org.apache.coyote.ajp.AjpNio2Protocol";
73-
} else {
74-
protocol = "org.apache.coyote.ajp.AjpNioProtocol";
75-
}
76-
77-
return protocol;
78-
}
79-
8056
private void doSnoopTest(RequestDescriptor desc) throws Exception {
8157

8258
final int ajpPacketSize = 16000;

‎test/org/apache/coyote/ajp/TestAjpSecurity.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,13 @@
3434
import org.apache.catalina.Wrapper;
3535
import org.apache.catalina.connector.Connector;
3636
import org.apache.catalina.startup.Tomcat;
37-
import org.apache.catalina.startup.TomcatBaseTest;
3837
import org.apache.tomcat.util.buf.HexUtils;
3938

4039
/*
4140
* Tests that can't easily be added to the {@code org.apache.tomcat.security} package because they need access to
4241
* package private classes.
4342
*/
44-
public class TestAjpSecurity extends TomcatBaseTest {
43+
public class TestAjpSecurity extends AjpBaseTest {
4544

4645

4746
@Test

0 commit comments

Comments
 (0)