1- '''
2- '''
1+ """
2+ """
33# Licensed to the Apache Software Foundation (ASF) under one
44# or more contributor license agreements. See the NOTICE file
55# distributed with this work for additional information
1616# See the License for the specific language governing permissions and
1717# limitations under the License.
1818
19- import sys
19+ from typing import Union
2020
2121Test .Summary = 'Verify ATS can function as a forward proxy'
2222Test .ContinueOnFail = True
2323
2424
2525class ForwardProxyTest :
26- def __init__ (self ):
26+ _scheme_proto_mismatch_policy : Union [int , None ]
27+ _ts_counter : int = 0
28+ _server_counter : int = 0
29+
30+ def __init__ (self , verify_scheme_matches_protocol : Union [int , None ]):
31+ """Construct a ForwardProxyTest object.
32+
33+ :param verify_scheme_matches_protocol: The value with which to
34+ configure Traffic Server's
35+ proxy.config.ssl.client.scheme_proto_mismatch_policy. A value of None
36+ means that no value will be explicitly set in the records.config.
37+ :type verify_scheme_matches_protocol: int or None
38+ """
39+ self ._scheme_proto_mismatch_policy = verify_scheme_matches_protocol
2740 self .setupOriginServer ()
2841 self .setupTS ()
2942
3043 def setupOriginServer (self ):
31- self .server = Test .MakeVerifierServerProcess ("server" , "forward_proxy.replay.yaml" )
32- self .server .Streams .All = Testers .ContainsExpression (
33- 'Received an HTTP/1 request with key 1' ,
34- 'Verify that the server received the request.' )
44+ """Configure the Proxy Verifier server."""
45+ proc_name = f"server{ ForwardProxyTest ._server_counter } "
46+ self .server = Test .MakeVerifierServerProcess (proc_name , "forward_proxy.replay.yaml" )
47+ ForwardProxyTest ._server_counter += 1
48+ if self ._scheme_proto_mismatch_policy in (2 , None ):
49+ self .server .Streams .All = Testers .ExcludesExpression (
50+ 'Received an HTTP/1 request with key 1' ,
51+ 'Verify that the server did not receive the request.' )
52+ else :
53+ self .server .Streams .All = Testers .ContainsExpression (
54+ 'Received an HTTP/1 request with key 1' ,
55+ 'Verify that the server received the request.' )
3556
3657 def setupTS (self ):
37- self .ts = Test .MakeATSProcess ("ts" , enable_tls = True , enable_cache = False )
58+ """Configure the Traffic Server process."""
59+ proc_name = f"ts{ ForwardProxyTest ._ts_counter } "
60+ self .ts = Test .MakeATSProcess (proc_name , enable_tls = True , enable_cache = False )
61+ ForwardProxyTest ._ts_counter += 1
3862 self .ts .addDefaultSSLFiles ()
3963 self .ts .Disk .ssl_multicert_config .AddLine ("dest_ip=* ssl_cert_name=server.pem ssl_key_name=server.key" )
4064 self .ts .Disk .remap_config .AddLine (
@@ -50,10 +74,13 @@ def setupTS(self):
5074 'proxy.config.diags.debug.tags' : "http" ,
5175 })
5276
77+ if self ._scheme_proto_mismatch_policy is not None :
78+ self .ts .Disk .records_config .update ({
79+ 'proxy.config.ssl.client.scheme_proto_mismatch_policy' : self ._scheme_proto_mismatch_policy ,
80+ })
81+
5382 def addProxyHttpsToHttpCase (self ):
54- """
55- Test ATS as an HTTPS forward proxy behind an HTTP server.
56- """
83+ """Test ATS as an HTTPS forward proxy behind an HTTP server."""
5784 tr = Test .AddTestRun ()
5885 tr .Processes .Default .StartBefore (self .server )
5986 tr .Processes .Default .StartBefore (self .ts )
@@ -65,12 +92,21 @@ def addProxyHttpsToHttpCase(self):
6592 tr .StillRunningAfter = self .server
6693 tr .StillRunningAfter = self .ts
6794
68- tr .Processes .Default .Streams .All = Testers .ContainsExpression (
69- '< HTTP/1.1 200 OK' ,
70- 'Verify that curl received a 200 OK response.' )
95+ if self ._scheme_proto_mismatch_policy in (2 , None ):
96+ tr .Processes .Default .Streams .All = Testers .ContainsExpression (
97+ '< HTTP/1.1 400 Invalid HTTP Request' ,
98+ 'Verify that the request was rejected.' )
99+ else :
100+ tr .Processes .Default .Streams .All = Testers .ContainsExpression (
101+ '< HTTP/1.1 200 OK' ,
102+ 'Verify that curl received a 200 OK response.' )
71103
72104 def run (self ):
105+ """Configure the TestRun instances for this set of tests."""
73106 self .addProxyHttpsToHttpCase ()
74107
75108
76- ForwardProxyTest ().run ()
109+ ForwardProxyTest (verify_scheme_matches_protocol = None ).run ()
110+ ForwardProxyTest (verify_scheme_matches_protocol = 0 ).run ()
111+ ForwardProxyTest (verify_scheme_matches_protocol = 1 ).run ()
112+ ForwardProxyTest (verify_scheme_matches_protocol = 2 ).run ()
0 commit comments