PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/gold_tests/headers/via.test.py

https://github.com/apache/trafficserver
Python | 124 lines | 103 code | 2 blank | 19 comment | 0 complexity | 294eeea56c8e2ab6d7e10e703407f2c7 MD5 | raw file
  1. '''
  2. Test the VIA header. This runs several requests through ATS and extracts the upstream VIA headers.
  3. Those are then checked against a gold file to verify the protocol stack based output is correct.
  4. '''
  5. # Licensed to the Apache Software Foundation (ASF) under one
  6. # or more contributor license agreements. See the NOTICE file
  7. # distributed with this work for additional information
  8. # regarding copyright ownership. The ASF licenses this file
  9. # to you under the Apache License, Version 2.0 (the
  10. # "License"); you may not use this file except in compliance
  11. # with the License. You may obtain a copy of the License at
  12. #
  13. # http://www.apache.org/licenses/LICENSE-2.0
  14. #
  15. # Unless required by applicable law or agreed to in writing, software
  16. # distributed under the License is distributed on an "AS IS" BASIS,
  17. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. # See the License for the specific language governing permissions and
  19. # limitations under the License.
  20. import os
  21. Test.Summary = '''
  22. Check VIA header for protocol stack data.
  23. '''
  24. Test.SkipUnless(
  25. Condition.HasCurlFeature('http2'),
  26. Condition.HasCurlFeature('IPv6')
  27. )
  28. Test.ContinueOnFail = True
  29. # Define default ATS
  30. ts = Test.MakeATSProcess("ts", enable_tls=True)
  31. server = Test.MakeOriginServer("server", options={'--load': os.path.join(Test.TestDirectory, 'via-observer.py')})
  32. testName = "VIA"
  33. # We only need one transaction as only the VIA header will be checked.
  34. request_header = {"headers": "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
  35. response_header = {"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
  36. server.addResponse("sessionlog.json", request_header, response_header)
  37. # These should be promoted rather than other tests like this reaching around.
  38. ts.addDefaultSSLFiles()
  39. ts.Disk.records_config.update({
  40. 'proxy.config.http.insert_request_via_str': 4,
  41. 'proxy.config.http.insert_response_via_str': 4,
  42. 'proxy.config.ssl.server.cert.path': '{0}'.format(ts.Variables.SSLDir),
  43. 'proxy.config.ssl.server.private_key.path': '{0}'.format(ts.Variables.SSLDir),
  44. })
  45. ts.Disk.remap_config.AddLine(
  46. 'map http://www.example.com http://127.0.0.1:{0}'.format(server.Variables.Port)
  47. )
  48. ts.Disk.remap_config.AddLine(
  49. 'map https://www.example.com http://127.0.0.1:{0}'.format(server.Variables.Port, ts.Variables.ssl_port)
  50. )
  51. ts.Disk.ssl_multicert_config.AddLine(
  52. 'dest_ip=* ssl_cert_name=server.pem ssl_key_name=server.key'
  53. )
  54. # Set up to check the output after the tests have run.
  55. via_log_id = Test.Disk.File("via.log")
  56. via_log_id.Content = "via.gold"
  57. # Basic HTTP 1.1
  58. tr = Test.AddTestRun()
  59. # Wait for the micro server
  60. tr.Processes.Default.StartBefore(server, ready=When.PortOpen(server.Variables.Port))
  61. # Delay on readiness of our ssl ports
  62. tr.Processes.Default.StartBefore(Test.Processes.ts)
  63. tr.Processes.Default.Command = 'curl --verbose --ipv4 --http1.1 --proxy localhost:{} http://www.example.com'.format(
  64. ts.Variables.port)
  65. tr.Processes.Default.ReturnCode = 0
  66. tr.StillRunningAfter = server
  67. tr.StillRunningAfter = ts
  68. # HTTP 1.0
  69. tr = Test.AddTestRun()
  70. tr.Processes.Default.Command = 'curl --verbose --ipv4 --http1.0 --proxy localhost:{} http://www.example.com'.format(
  71. ts.Variables.port)
  72. tr.Processes.Default.ReturnCode = 0
  73. tr.StillRunningAfter = server
  74. tr.StillRunningAfter = ts
  75. # HTTP 2
  76. tr = Test.AddTestRun()
  77. tr.Processes.Default.Command = 'curl --verbose --ipv4 --insecure --header "Host: www.example.com" https://localhost:{}'.format(
  78. ts.Variables.ssl_port)
  79. tr.Processes.Default.ReturnCode = 0
  80. tr.StillRunningAfter = server
  81. tr.StillRunningAfter = ts
  82. # TLS
  83. tr = Test.AddTestRun()
  84. tr.Processes.Default.Command = 'curl --verbose --ipv4 --http1.1 --insecure --header "Host: www.example.com" https://localhost:{}'.format(
  85. ts.Variables.ssl_port)
  86. tr.Processes.Default.ReturnCode = 0
  87. tr.StillRunningAfter = server
  88. tr.StillRunningAfter = ts
  89. # IPv6
  90. tr = Test.AddTestRun()
  91. tr.Processes.Default.Command = 'curl --verbose --ipv6 --http1.1 --proxy localhost:{} http://www.example.com'.format(
  92. ts.Variables.portv6)
  93. tr.Processes.Default.ReturnCode = 0
  94. tr.StillRunningAfter = server
  95. tr.StillRunningAfter = ts
  96. tr = Test.AddTestRun()
  97. tr.Processes.Default.Command = 'curl --verbose --ipv6 --http1.1 --insecure --header "Host: www.example.com" https://localhost:{}'.format(
  98. ts.Variables.ssl_portv6)
  99. tr.Processes.Default.ReturnCode = 0
  100. tr.StillRunningAfter = server
  101. tr.StillRunningAfter = ts