Skip to content

Commit a2e77e9

Browse files
authored
Add header rewrite test to make sure we are not injecting end of rule char (#6340)
* Add header rewrite test to make sure we are not injecting end of rule characters in to an actual header This is a regression check for the issue fixed in #5423
1 parent bea9d08 commit a2e77e9

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
``
2+
> GET http://www.example.com``
3+
> Host: www.example.com``
4+
> User-Agent: curl/``
5+
> Accept: */*
6+
``
7+
< HTTP/1.1 200 OK
8+
< Date: ``
9+
< Age: ``
10+
< Transfer-Encoding: chunked
11+
< Proxy-Connection: keep-alive
12+
< Server: ATS/``
13+
< X-First: First
14+
< X-Last: Last
15+
<
16+
``
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
'''
2+
'''
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
19+
Test.Summary = '''
20+
Test for a regression of the issue fixed in
21+
https://github.com/apache/trafficserver/pull/5423
22+
Insertion of header rewrite directives in to the output
23+
'''
24+
25+
Test.ContinueOnFail = True
26+
# Define default ATS
27+
ts = Test.MakeATSProcess("ts")
28+
server = Test.MakeOriginServer("server")
29+
30+
Test.testName = ""
31+
request_header = {"headers": "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
32+
# expected response from the origin server
33+
response_header = {"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
34+
35+
# add response to the server dictionary
36+
server.addResponse("sessionfile.log", request_header, response_header)
37+
ts.Disk.records_config.update({
38+
'proxy.config.diags.debug.enabled': 1,
39+
'proxy.config.diags.debug.tags': 'header.*',
40+
})
41+
42+
# The following rule adds X-First and X-Last headers
43+
ts.Setup.CopyAs('rules/rule_l_value.conf', Test.RunDirectory)
44+
45+
ts.Disk.plugin_config.AddLine(
46+
'header_rewrite.so {0}/rule_l_value.conf'.format(Test.RunDirectory)
47+
)
48+
ts.Disk.remap_config.AddLine(
49+
'map http://www.example.com http://127.0.0.1:{0}'.format(server.Variables.Port)
50+
)
51+
ts.Disk.remap_config.AddLine(
52+
'map http://www.example.com:8080 http://127.0.0.1:{0}'.format(server.Variables.Port)
53+
)
54+
55+
# [L] test
56+
tr = Test.AddTestRun("Header Rewrite End [L]")
57+
tr.Processes.Default.Command = 'curl --proxy 127.0.0.1:{0} "http://www.example.com" -H "Proxy-Connection: keep-alive" --verbose'.format(
58+
ts.Variables.port)
59+
tr.Processes.Default.ReturnCode = 0
60+
tr.Processes.Default.StartBefore(server, ready=When.PortOpen(server.Variables.Port))
61+
tr.Processes.Default.StartBefore(Test.Processes.ts)
62+
tr.Processes.Default.Streams.stderr = "gold/header_rewrite-l_value.gold"
63+
tr.StillRunningAfter = server
64+
ts.Streams.All = "gold/header_rewrite-tag.gold"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with 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+
cond %{SEND_RESPONSE_HDR_HOOK}
19+
set-header X-First "First"
20+
set-header X-Last "Last" [L]
21+

0 commit comments

Comments
 (0)