|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +import os |
| 18 | + |
| 19 | +Test.Summary = ''' |
| 20 | +Test PUSHing an object into the cache and the GETting it with a few variations on the client connection protocol. |
| 21 | +''' |
| 22 | + |
| 23 | +# NOTE: You can also use this to test client-side communication when GET-ing very large (multi-GB) objects |
| 24 | +# by increasing the value of the obj_kilobytes variable below. (But do not increase it on any shared branch |
| 25 | +# that we do CI runs on.) |
| 26 | + |
| 27 | +Test.SkipUnless(Condition.HasCurlFeature('http2')) |
| 28 | + |
| 29 | +ts = Test.MakeATSProcess("ts1", enable_tls=True) |
| 30 | +ts.addDefaultSSLFiles() |
| 31 | + |
| 32 | +ts.Disk.records_config.update( |
| 33 | + { |
| 34 | + 'proxy.config.diags.debug.enabled': 1, |
| 35 | + 'proxy.config.diags.debug.tags': 'http|dns|cache', |
| 36 | + 'proxy.config.http.cache.required_headers': 0, # No required headers for caching |
| 37 | + 'proxy.config.http.push_method_enabled': 1, |
| 38 | + 'proxy.config.proxy_name': 'Poxy_Proxy', # This will be the server name. |
| 39 | + 'proxy.config.ssl.server.cert.path': ts.Variables.SSLDir, |
| 40 | + 'proxy.config.ssl.server.private_key.path': ts.Variables.SSLDir, |
| 41 | + 'proxy.config.url_remap.remap_required': 0 |
| 42 | + }) |
| 43 | + |
| 44 | +ts.Disk.ssl_multicert_config.AddLine('dest_ip=* ssl_cert_name=server.pem ssl_key_name=server.key') |
| 45 | + |
| 46 | +ts.Disk.remap_config.AddLine(f'map https://localhost:{ts.Variables.ssl_port} http://localhost:{ts.Variables.port}') |
| 47 | +ts.Disk.remap_config.AddLine(f'map https://localhost:{ts.Variables.ssl_portv6} http://localhost:{ts.Variables.port}') |
| 48 | + |
| 49 | +# Size of object to get. (NOTE: If you increase this significantly you may also have to increase cache |
| 50 | +# capacity in tests/gold_tests/autest-size/min_cfg/storage.config. Also, for very large objects, if |
| 51 | +# proxy.config.diags.debug.enabled is 1, the PUSH request will timeout and fail.) |
| 52 | +# |
| 53 | +obj_kilobytes = 10 * 1024 |
| 54 | +obj_bytes = obj_kilobytes * 10 |
| 55 | +header = "HTTP/1.1 200 OK\r\nContent-length: {}\r\n\r\n".format(obj_bytes) |
| 56 | + |
| 57 | + |
| 58 | +def create_pushfile(): |
| 59 | + f = open(Test.RunDirectory + "/objfile", "w") |
| 60 | + f.write(header) |
| 61 | + f.write("x" * obj_bytes) |
| 62 | + f.close() |
| 63 | + return True |
| 64 | + |
| 65 | + |
| 66 | +tr = Test.AddTestRun("PUSH an object to the cache") |
| 67 | +# Delay on readiness of TS IPv4 ssl port |
| 68 | +tr.Processes.Default.StartBefore(ts, ready=lambda: create_pushfile()) |
| 69 | +# Put object with URL http://localhost/bigobj in cache using PUSH request. |
| 70 | +tr.MakeCurlCommand( |
| 71 | + "-v -H 'Content-Type: application/octet-stream' --data-binary @{}/objfile -X PUSH http://localhost:{}/bigobj -H 'Content-Length:{}'" |
| 72 | + .format(Test.RunDirectory, ts.Variables.port, |
| 73 | + len(header) + obj_bytes)) |
| 74 | +tr.Processes.Default.ReturnCode = 0 |
| 75 | +tr.Processes.Default.Streams.All = Testers.ContainsExpression("HTTP/1.1 201 Created", "The PUSH request should have succeeded") |
| 76 | + |
| 77 | +tr = Test.AddTestRun("GET bigobj: cleartext, HTTP/1.1, IPv4") |
| 78 | +tr.MakeCurlCommand(f'--verbose --http1.1 http://localhost:{ts.Variables.port}/bigobj') |
| 79 | +tr.Processes.Default.ReturnCode = 0 |
| 80 | +tr.Processes.Default.Streams.All = Testers.ContainsExpression("HTTP/1.1 200 OK", "Should fetch pushed object") |
| 81 | +tr.Processes.Default.Streams.All = Testers.ContainsExpression("Content-length: 102400", "Content size should be accurate") |
| 82 | + |
| 83 | +# Verify that PUSH requests are rejected when push_method_enabled is 0 (the |
| 84 | +# default configuration). |
| 85 | +ts = Test.MakeATSProcess("ts2", enable_tls=True) |
| 86 | +ts.addDefaultSSLFiles() |
| 87 | + |
| 88 | +ts.Disk.records_config.update( |
| 89 | + { |
| 90 | + 'proxy.config.diags.debug.enabled': 1, |
| 91 | + 'proxy.config.diags.debug.tags': 'http|dns|cache', |
| 92 | + 'proxy.config.http.cache.required_headers': 0, # No required headers for caching |
| 93 | + 'proxy.config.proxy_name': 'Poxy_Proxy', # This will be the server name. |
| 94 | + 'proxy.config.ssl.server.cert.path': ts.Variables.SSLDir, |
| 95 | + 'proxy.config.ssl.server.private_key.path': ts.Variables.SSLDir, |
| 96 | + 'proxy.config.url_remap.remap_required': 0 |
| 97 | + }) |
| 98 | + |
| 99 | +ts.Disk.ssl_multicert_config.AddLine('dest_ip=* ssl_cert_name=server.pem ssl_key_name=server.key') |
| 100 | + |
| 101 | +ts.Disk.remap_config.AddLine(f'map https://localhost:{ts.Variables.ssl_port} http://localhost:{ts.Variables.port}') |
| 102 | +ts.Disk.remap_config.AddLine(f'map https://localhost:{ts.Variables.ssl_portv6} http://localhost:{ts.Variables.port}') |
| 103 | + |
| 104 | +tr = Test.AddTestRun("PUSH request is rejected when push_method_enabled is 0") |
| 105 | +tr.Processes.Default.StartBefore(ts) |
| 106 | +tr.MakeCurlCommand( |
| 107 | + "-v -H 'Content-Type: application/octet-stream' --data-binary @{}/objfile -X PUSH http://localhost:{}/bigobj -H 'Content-Length:{}'" |
| 108 | + .format(Test.RunDirectory, ts.Variables.port, |
| 109 | + len(header) + obj_bytes)) |
| 110 | +tr.Processes.Default.ReturnCode = 0 |
| 111 | +tr.Processes.Default.Streams.All = Testers.ContainsExpression( |
| 112 | + "403 Access Denied", "The PUSH request should have received a 403 response.") |
0 commit comments