Skip to content

Commit 40f0274

Browse files
committed
test: Separate tests for UseAlias from maintests.sh
Also test a little bit more than before UseAlias is not enabled by default in the rest of the testsuite now
1 parent b131a0c commit 40f0274

File tree

7 files changed

+280
-44
lines changed

7 files changed

+280
-44
lines changed

test/maintests.sh

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -129,50 +129,6 @@ if [ $? -ne 0 ]; then
129129
exit 1
130130
fi
131131

132-
#
133-
# Test virtual host
134-
echotestlabel "Testing virtual hosts"
135-
docker cp tomcat2:/usr/local/tomcat/conf/server.xml .
136-
sed '/Host name=.*/i <Host name=\"example.com\" appBase="examples" />' server.xml > new.xml
137-
docker cp new.xml tomcat2:/usr/local/tomcat/conf/server.xml
138-
docker cp examples tomcat2:/usr/local/tomcat
139-
docker commit tomcat2 ${IMG}-temporary
140-
tomcat_remove 2
141-
tomcat_wait_for_n_nodes 1
142-
# Start the node.
143-
IMG=${IMG}-temporary tomcat_start 2
144-
tomcat_wait_for_n_nodes 2 || exit 1
145-
# Basically curl --header "Host: example.com" http://localhost:8090/test/test.jsp gives 200
146-
# in fact the headers are:
147-
# X-Forwarded-For: localhost
148-
# X-Forwarded-Host: example.com
149-
# X-Forwarded-Server: fe80::faf4:935b:9dda:2adf
150-
# therefore don't forget ProxyPreserveHost On (otherwise UseAlias On failed...)
151-
#
152-
CODE=$(curl -s -o /dev/null -m 20 -w "%{http_code}" --header "Host: example.com" http://localhost:8090/test/test.jsp)
153-
if [ ${CODE} != "200" ]; then
154-
echo "Failed can't reach webapp at example.com: ${CODE}"
155-
exit 1
156-
fi
157-
# Basically curl --header "Host: localhost" http://localhost:8090/test/test.jsp gives 400
158-
CODE=$(curl -s -o /dev/null -m 20 -w "%{http_code}" --header "Host: localhost" http://localhost:8090/test/test.jsp)
159-
if [ ${CODE} != "404" ]; then
160-
echo "Failed should NOT reach webapp at localhost: ${CODE}"
161-
exit 1
162-
fi
163-
# Same using localhost/testapp2 and curl --header "Host: localhost" http://localhost:8090/testapp2/test.jsp
164-
CODE=$(curl -s -o /dev/null -m 20 -w "%{http_code}" --header "Host: localhost" http://localhost:8090/testapp2/test.jsp)
165-
if [ ${CODE} != "200" ]; then
166-
echo "Failed can't reach webapp at localhost: ${CODE}"
167-
exit 1
168-
fi
169-
# Basically curl --header "Host: example.com" http://localhost:8090/testapp2/test.jsp gives 400
170-
CODE=$(curl -s -o /dev/null -m 20 -w "%{http_code}" --header "Host: example.com" http://localhost:8090/testapp2/test.jsp)
171-
if [ ${CODE} != "404" ]; then
172-
echo "Failed should NOT reach webapp at localhost: ${CODE}"
173-
exit 1
174-
fi
175-
176132
# Shutdown the 2 tomcats
177133
tomcat_remove 1
178134
tomcat_remove 2

test/testsuite.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ run_test maintests.sh "Main tests"
7676
res=$(expr $res + $?)
7777
run_test websocket/basic.sh "Websocket tests"
7878
res=$(expr $res + $?)
79+
run_test usealias/testit.sh "UseAlias"
80+
res=$(expr $res + $?)
7981
run_test MODCLUSTER-640/testit.sh "MODCLUSTER-640"
8082
res=$(expr $res + $?)
8183
run_test MODCLUSTER-734/testit.sh "MODCLUSTER-734"
@@ -91,6 +93,8 @@ res=$(expr $res + $?)
9193

9294
MPC_CONF=httpd/mod_lbmethod_cluster.conf run_test basetests.sh "Basic tests with mod_proxy_balancer"
9395
res=$(expr $res + $?)
96+
MPC_CONF=usealias/mod_lbmethod_cluster.conf run_test usealias/testit.sh "UseAlias with mod_proxy_balancer"
97+
res=$(expr $res + $?)
9498
MPC_CONF=MODCLUSTER-640/mod_lbmethod_cluster.conf run_test MODCLUSTER-640/testit.sh "MODCLUSTER-640 with mod_proxy_balancer"
9599
res=$(expr $res + $?)
96100
MPC_CONF=MODCLUSTER-734/mod_lbmethod_cluster.conf run_test MODCLUSTER-734/testit.sh "MODCLUSTER-734 with mod_proxy_balancer"
File renamed without changes.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
LoadModule proxy_module modules/mod_proxy.so
2+
LoadModule proxy_http_module modules/mod_proxy_http.so
3+
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
4+
LoadModule proxy_hcheck_module modules/mod_proxy_hcheck.so
5+
6+
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
7+
LoadModule manager_module modules/mod_manager.so
8+
LoadModule lbmethod_cluster_module modules/mod_lbmethod_cluster.so
9+
LoadModule watchdog_module modules/mod_watchdog.so
10+
11+
UseAlias On
12+
ProxyPreserveHost On
13+
14+
Listen 8090
15+
ServerName httpd-mod_proxy_cluster
16+
ManagerBalancerName mycluster
17+
WSUpgradeHeader websocket
18+
19+
<VirtualHost *:8090>
20+
EnableMCMPReceive
21+
<Location />
22+
Require host .mod_proxy_cluster_testsuite_net
23+
# _gateway is the hostname used through the docker port forward into the custom network
24+
Require host _gateway
25+
Require local
26+
</Location>
27+
<Location /mod_cluster_manager>
28+
SetHandler mod_cluster-manager
29+
# _gateway is the hostname used through the docker port forward into the custom network
30+
Require host _gateway
31+
Require local
32+
</Location>
33+
</VirtualHost>
34+
35+
<Proxy "balancer://mycluster">
36+
ProxySet growth=20
37+
ProxySet lbmethod=cluster
38+
</Proxy>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
LoadModule watchdog_module modules/mod_watchdog.so
2+
LoadModule proxy_module modules/mod_proxy.so
3+
LoadModule proxy_http_module modules/mod_proxy_http.so
4+
LoadModule proxy_hcheck_module modules/mod_proxy_hcheck.so
5+
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
6+
LoadModule manager_module modules/mod_manager.so
7+
LoadModule proxy_cluster_module modules/mod_proxy_cluster.so
8+
9+
UseAlias On
10+
ProxyPreserveHost On
11+
12+
13+
Listen 8090
14+
ManagerBalancerName mycluster
15+
WSUpgradeHeader websocket
16+
17+
<VirtualHost *:8090>
18+
ServerName httpd-mod_proxy_cluster
19+
EnableMCMPReceive
20+
<Location />
21+
Require host .mod_proxy_cluster_testsuite_net
22+
# _gateway is the hostname used through the docker port forward into the custom network
23+
Require host _gateway
24+
Require local
25+
</Location>
26+
<Location /mod_cluster_manager>
27+
SetHandler mod_cluster-manager
28+
# _gateway is the hostname used through the docker port forward into the custom network
29+
Require host _gateway
30+
Require local
31+
</Location>
32+
</VirtualHost>

test/usealias/server.xml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<!-- Note: A "Server" is not itself a "Container", so you may not
19+
define subcomponents such as "Valves" at this level.
20+
Documentation at /docs/config/server.html
21+
-->
22+
<Server port="tomcat_shutdown_port" shutdown="SHUTDOWN" address="tomcat_address" portOffset="port_offset">
23+
<Listener className="org.jboss.modcluster.container.tomcat.ModClusterListener"
24+
connectorPort="tomcat_port"
25+
proxyList="proxy_address:proxy_port" />
26+
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
27+
28+
<!--APR library loader. Documentation at /docs/apr.html -->
29+
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
30+
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
31+
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
32+
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
33+
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
34+
35+
<!-- Global JNDI resources
36+
Documentation at /docs/jndi-resources-howto.html
37+
-->
38+
<GlobalNamingResources>
39+
<!-- Editable user database that can also be used by
40+
UserDatabaseRealm to authenticate users
41+
-->
42+
<Resource name="UserDatabase" auth="Container"
43+
type="org.apache.catalina.UserDatabase"
44+
description="User database that can be updated and saved"
45+
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
46+
pathname="conf/tomcat-users.xml" />
47+
</GlobalNamingResources>
48+
49+
<!-- A "Service" is a collection of one or more "Connectors" that share
50+
a single "Container" Note: A "Service" is not itself a "Container",
51+
so you may not define subcomponents such as "Valves" at this level.
52+
Documentation at /docs/config/service.html
53+
-->
54+
<Service name="Catalina">
55+
56+
57+
<Connector port="tomcat_port" protocol="HTTP/1.1"
58+
address="tomcat_address"
59+
connectionTimeout="20000"
60+
portOffset="port_offset" />
61+
62+
<!-- Define an AJP 1.3 Connector on port 8900 -->
63+
64+
<Connector protocol="AJP/1.3"
65+
address="tomcat_address"
66+
port="tomcat_ajp_port"
67+
secretRequired="false"
68+
portOffset="port_offset" />
69+
70+
71+
<!-- An Engine represents the entry point (within Catalina) that processes
72+
every request. The Engine implementation for Tomcat stand alone
73+
analyzes the HTTP headers included with the request, and passes them
74+
on to the appropriate Host (virtual host).
75+
Documentation at /docs/config/engine.html -->
76+
77+
<!-- You should set jvmRoute to support load-balancing via AJP ie :
78+
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
79+
-->
80+
<Engine name="Catalina" defaultHost="localhost">
81+
82+
<!--For clustering, please take a look at documentation at:
83+
/docs/cluster-howto.html (simple how to)
84+
/docs/config/cluster.html (reference documentation) -->
85+
<!--
86+
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
87+
-->
88+
89+
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
90+
via a brute-force attack -->
91+
<Realm className="org.apache.catalina.realm.LockOutRealm">
92+
<!-- This Realm uses the UserDatabase configured in the global JNDI
93+
resources under the key "UserDatabase". Any edits
94+
that are performed against this UserDatabase are immediately
95+
available for use by the Realm. -->
96+
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
97+
resourceName="UserDatabase"/>
98+
</Realm>
99+
100+
<Host name="example.com" appBase="examples" />
101+
102+
<Host name="tomcat_address" appBase="webapps"
103+
unpackWARs="true" autoDeploy="true">
104+
105+
<Alias>localhost</Alias>
106+
107+
<!-- Access log processes all example.
108+
Documentation at: /docs/config/valve.html
109+
Note: The pattern used is equivalent to using pattern="common" -->
110+
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
111+
prefix="localhost_access_log" suffix=".txt"
112+
pattern="%h %l %u %t &quot;%r&quot; %s %b" />
113+
114+
</Host>
115+
116+
</Engine>
117+
</Service>
118+
</Server>

test/usealias/testit.sh

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/sh
2+
3+
. includes/common.sh
4+
5+
# remove possibly running containers
6+
httpd_remove
7+
tomcat_all_remove
8+
9+
# Make sure to use custom conf with UseAlias On
10+
MPC_CONF=usealias/mod_proxy_cluster.conf httpd_start
11+
12+
13+
tomcat_start 1
14+
15+
tomcat_wait_for_n_nodes 1
16+
17+
# Test virtual host
18+
echo "Create a temporary image with a custom server.xml"
19+
20+
docker cp usealias/server.xml tomcat1:/usr/local/tomcat/conf/server.xml
21+
# This app will have alias = example.com
22+
docker cp usealias/examples tomcat1:/usr/local/tomcat
23+
# This app will have two aliases: localhost, tomcat1
24+
docker cp usealias/examples/test tomcat1:/usr/local/tomcat/webapps/webapp
25+
docker commit tomcat1 ${IMG}-temporary
26+
# TODO: Without shutdown only the examples.com VHost is available, looks fishy
27+
tomcat_shutdown 1
28+
29+
tomcat_wait_for_n_nodes 0
30+
tomcat_remove 1
31+
32+
# Start the node.
33+
echo "Start custom tomcat image as tomcat1"
34+
IMG=${IMG}-temporary tomcat_start 1
35+
36+
tomcat_wait_for_n_nodes 1
37+
sleep 20
38+
39+
# Let's test now that
40+
# curl --header "Host: example.com" http://localhost:8090/test/test.jsp
41+
# gives 200
42+
# in fact the headers are:
43+
# X-Forwarded-For: localhost
44+
# X-Forwarded-Host: example.com
45+
#
46+
# Don't forget ProxyPreserveHost On (otherwise UseAlias On failed...)
47+
#
48+
# Basically each Host header value is compared with the aliases of the VHost corresponding
49+
# to the request and UseAlias makes sure there's a match (if not, 404 is returned)
50+
51+
CODE=$(curl -s -o /dev/null -m 20 -w "%{http_code}" --header "Host: example.com" http://localhost:8090/test/test.jsp)
52+
if [ ${CODE} != "200" ]; then
53+
echo "Failed can't reach webapp at example.com: ${CODE}"
54+
exit 1
55+
fi
56+
57+
CODE=$(curl -s -o /dev/null -m 20 -w "%{http_code}" --header "Host: localhost" http://localhost:8090/test/test.jsp)
58+
if [ ${CODE} != "404" ]; then
59+
echo "Failed should NOT reach webapp at localhost: ${CODE}"
60+
exit 1
61+
fi
62+
63+
CODE=$(curl -s -o /dev/null -m 20 -w "%{http_code}" --header "Host: tomcat1" http://localhost:8090/test/test.jsp)
64+
if [ ${CODE} != "404" ]; then
65+
echo "Failed should NOT reach webapp at localhost: ${CODE}"
66+
exit 1
67+
fi
68+
69+
CODE=$(curl -s -o /dev/null -m 20 -w "%{http_code}" --header "Host: localhost" http://localhost:8090/webapp/test.jsp)
70+
if [ ${CODE} != "200" ]; then
71+
echo "Failed can't reach webapp at localhost: ${CODE}"
72+
exit 1
73+
fi
74+
75+
CODE=$(curl -s -o /dev/null -m 20 -w "%{http_code}" --header "Host: tomcat1" http://localhost:8090/webapp/test.jsp)
76+
if [ ${CODE} != "200" ]; then
77+
echo "Failed can't reach webapp at localhost: ${CODE}"
78+
exit 1
79+
fi
80+
81+
CODE=$(curl -s -o /dev/null -m 20 -w "%{http_code}" --header "Host: example.com" http://localhost:8090/webapp/test.jsp)
82+
if [ ${CODE} != "404" ]; then
83+
echo "Failed should NOT reach webapp at localhost: ${CODE}"
84+
exit 1
85+
fi
86+
87+
tomcat_all_remove
88+
docker image rm ${IMG}-temporary

0 commit comments

Comments
 (0)