|
| 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 = 'Test Split DNS' |
| 20 | + |
| 21 | + |
| 22 | +class SplitDNSTest: |
| 23 | + def __init__(self): |
| 24 | + self.setupDNSServer() |
| 25 | + self.setupOriginServer() |
| 26 | + self.setupTS() |
| 27 | + |
| 28 | + def setupDNSServer(self): |
| 29 | + self.dns = Test.MakeDNServer("dns") |
| 30 | + self.dns.addRecords(records={'foo.ts.a.o.': ['127.0.0.1']}) |
| 31 | + |
| 32 | + def setupOriginServer(self): |
| 33 | + self.origin_server = Test.MakeOriginServer("origin_server") |
| 34 | + self.origin_server.addResponse("sessionlog.json", |
| 35 | + {"headers": "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n"}, |
| 36 | + {"headers": "HTTP/1.1 200 OK\r\nServer: microserver\r\nConnection: close\r\n\r\n"}) |
| 37 | + |
| 38 | + def setupTS(self): |
| 39 | + self.ts = Test.MakeATSProcess( |
| 40 | + "ts", select_ports=True, enable_cache=False) |
| 41 | + self.ts.Disk.records_config.update({ |
| 42 | + "proxy.config.dns.splitDNS.enabled": 1, |
| 43 | + "proxy.config.diags.debug.enabled": 1, |
| 44 | + "proxy.config.diags.debug.tags": "dns|splitdns", |
| 45 | + }) |
| 46 | + self.ts.Disk.splitdns_config.AddLine( |
| 47 | + f"dest_domain=foo.ts.a.o named=127.0.0.1:{self.dns.Variables.Port}") |
| 48 | + self.ts.Disk.remap_config.AddLine( |
| 49 | + f"map /foo/ http://foo.ts.a.o:{self.origin_server.Variables.Port}/") |
| 50 | + self.ts.Disk.remap_config.AddLine( |
| 51 | + f"map /bar/ http://127.0.0.1:{self.origin_server.Variables.Port}/") |
| 52 | + |
| 53 | + def addTestCase0(self): |
| 54 | + tr = Test.AddTestRun() |
| 55 | + tr.Processes.Default.Command = f"curl -v http://localhost:{self.ts.Variables.port}/foo/" |
| 56 | + tr.Processes.Default.ReturnCode = 0 |
| 57 | + tr.Processes.Default.Streams.stderr = "gold/test_case_0_stderr.gold" |
| 58 | + tr.Processes.Default.StartBefore(self.dns) |
| 59 | + tr.Processes.Default.StartBefore(self.origin_server) |
| 60 | + tr.Processes.Default.StartBefore(self.ts) |
| 61 | + tr.StillRunningAfter = self.dns |
| 62 | + tr.StillRunningAfter = self.origin_server |
| 63 | + tr.StillRunningAfter = self.ts |
| 64 | + |
| 65 | + def addTestCase1(self): |
| 66 | + tr = Test.AddTestRun() |
| 67 | + tr.Processes.Default.Command = f"curl -v http://localhost:{self.ts.Variables.port}/bar/" |
| 68 | + tr.Processes.Default.ReturnCode = 0 |
| 69 | + tr.Processes.Default.Streams.stderr = "gold/test_case_1_stderr.gold" |
| 70 | + tr.StillRunningAfter = self.dns |
| 71 | + tr.StillRunningAfter = self.origin_server |
| 72 | + tr.StillRunningAfter = self.ts |
| 73 | + |
| 74 | + def run(self): |
| 75 | + self.addTestCase0() |
| 76 | + self.addTestCase1() |
| 77 | + |
| 78 | + |
| 79 | +SplitDNSTest().run() |
0 commit comments