1'''
2Test whitespace between field name and colon in the header
3'''
4#  Licensed to the Apache Software Foundation (ASF) under one
5#  or more contributor license agreements.  See the NOTICE file
6#  distributed with this work for additional information
7#  regarding copyright ownership.  The ASF licenses this file
8#  to you under the Apache License, Version 2.0 (the
9#  "License"); you may not use this file except in compliance
10#  with the License.  You may obtain a copy of the License at
11#
12#      http://www.apache.org/licenses/LICENSE-2.0
13#
14#  Unless required by applicable law or agreed to in writing, software
15#  distributed under the License is distributed on an "AS IS" BASIS,
16#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17#  See the License for the specific language governing permissions and
18#  limitations under the License.
19
20Test.Summary = '''
21Test whitespace between field name and colon in the header
22'''
23
24Test.ContinueOnFail = True
25
26# Define default ATS
27ts = Test.MakeATSProcess("ts")
28server = Test.MakeOriginServer("server")
29
30# **testname is required**
31testName = ""
32request_header = {"headers": "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
33response_header = {"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
34server.addResponse("sessionlog.json", request_header, response_header)
35
36ts.Disk.remap_config.AddLine(
37    'map http://www.example.com http://127.0.0.1:{0}'.format(server.Variables.Port)
38)
39
40# Test 0 - 200 Response
41tr = Test.AddTestRun()
42tr.Processes.Default.StartBefore(server, ready=When.PortOpen(server.Variables.Port))
43tr.Processes.Default.StartBefore(Test.Processes.ts)
44tr.Processes.Default.Command = 'curl -s -D - -v --ipv4 --http1.1 -H " foo: bar" -H "Host: www.example.com" http://localhost:{0}/'.format(
45    ts.Variables.port)
46tr.Processes.Default.ReturnCode = 0
47tr.Processes.Default.Streams.stdout = "syntax.200.gold"
48tr.StillRunningAfter = ts
49
50# Test 1 - 400 Response - Single space after field name
51tr = Test.AddTestRun()
52tr.Processes.Default.Command = 'curl -s -D - -v --ipv4 --http1.1 -H "foo : bar" -H "Host: www.example.com" http://localhost:{0}/'.format(
53    ts.Variables.port)
54tr.Processes.Default.ReturnCode = 0
55tr.Processes.Default.Streams.stdout = "syntax.400.gold"
56tr.StillRunningAfter = ts
57
58# Test 2 - 400 Response - Double space after field name
59tr = Test.AddTestRun()
60tr.Processes.Default.Command = 'curl -s -D - -v --ipv4 --http1.1 -H "foo  : bar" -H "Host: www.example.com" http://localhost:{0}/'.format(
61    ts.Variables.port)
62tr.Processes.Default.ReturnCode = 0
63tr.Processes.Default.Streams.stdout = "syntax.400.gold"
64tr.StillRunningAfter = ts
65
66# Test 3 - 400 Response - Three different Content-Length headers
67tr = Test.AddTestRun()
68tr.Processes.Default.Command = 'curl -s -D - -v --ipv4 --http1.1 -d "hello world" -H "Content-Length: 11" -H "Content-Length: 10" -H "Content-Length: 9" -H "Host: www.example.com" http://localhost:{0}/'.format(
69    ts.Variables.port)
70tr.Processes.Default.ReturnCode = 0
71tr.Processes.Default.Streams.stdout = "syntax.400.gold"
72tr.StillRunningAfter = ts
73
74# Test 4 - 200 Response - Three same Content-Length headers
75tr = Test.AddTestRun()
76tr.Processes.Default.Command = 'curl -s -D - -v --ipv4 --http1.1 -d "hello world" -H "Content-Length: 11" -H "Content-Length: 11" -H "Content-Length: 11" -H "Host: www.example.com" http://localhost:{0}/'.format(
77    ts.Variables.port)
78tr.Processes.Default.ReturnCode = 0
79tr.Processes.Default.Streams.stdout = "syntax.200.gold"
80tr.StillRunningAfter = ts
81
82# Test 5 - 200 Response - Three different Content-Length headers with a Transfer encoding header
83tr = Test.AddTestRun()
84tr.Processes.Default.Command = 'curl -s -D - -v --ipv4 --http1.1 -d "hello world" -H "Transfer-Encoding: chunked" -H "Content-Length: 11" -H "Content-Length: 10" -H "Content-Length: 9" -H "Host: www.example.com" http://localhost:{0}/'.format(
85    ts.Variables.port)
86tr.Processes.Default.ReturnCode = 0
87tr.Processes.Default.Streams.stdout = "syntax.200.gold"
88tr.StillRunningAfter = ts
89