From 95a8a25cc44550c8cdb8aefe230a2b4abd917315 Mon Sep 17 00:00:00 2001 From: Masaori Koshiba Date: Mon, 16 Nov 2020 11:13:53 +0900 Subject: [PATCH] AuTest for Split DNS --- .../splitdns/gold/test_case_0_stderr.gold | 10 +++ .../splitdns/gold/test_case_1_stderr.gold | 10 +++ tests/gold_tests/splitdns/splitdns.test.py | 79 +++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 tests/gold_tests/splitdns/gold/test_case_0_stderr.gold create mode 100644 tests/gold_tests/splitdns/gold/test_case_1_stderr.gold create mode 100644 tests/gold_tests/splitdns/splitdns.test.py diff --git a/tests/gold_tests/splitdns/gold/test_case_0_stderr.gold b/tests/gold_tests/splitdns/gold/test_case_0_stderr.gold new file mode 100644 index 00000000000..9e86235e6d7 --- /dev/null +++ b/tests/gold_tests/splitdns/gold/test_case_0_stderr.gold @@ -0,0 +1,10 @@ +`` +> GET /foo/ HTTP/1.1 +> Host: localhost:`` +> User-Agent: curl/`` +`` +< HTTP/1.1 200 OK +< Server: ATS/`` +< Date: `` +< Age: `` +`` diff --git a/tests/gold_tests/splitdns/gold/test_case_1_stderr.gold b/tests/gold_tests/splitdns/gold/test_case_1_stderr.gold new file mode 100644 index 00000000000..34c0e156aba --- /dev/null +++ b/tests/gold_tests/splitdns/gold/test_case_1_stderr.gold @@ -0,0 +1,10 @@ +`` +> GET /bar/ HTTP/1.1 +> Host: localhost:`` +> User-Agent: curl/`` +`` +< HTTP/1.1 200 OK +< Server: ATS/`` +< Date: `` +< Age: `` +`` diff --git a/tests/gold_tests/splitdns/splitdns.test.py b/tests/gold_tests/splitdns/splitdns.test.py new file mode 100644 index 00000000000..23e277cd64e --- /dev/null +++ b/tests/gold_tests/splitdns/splitdns.test.py @@ -0,0 +1,79 @@ +''' +''' +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +Test.Summary = 'Test Split DNS' + + +class SplitDNSTest: + def __init__(self): + self.setupDNSServer() + self.setupOriginServer() + self.setupTS() + + def setupDNSServer(self): + self.dns = Test.MakeDNServer("dns") + self.dns.addRecords(records={'foo.ts.a.o.': ['127.0.0.1']}) + + def setupOriginServer(self): + self.origin_server = Test.MakeOriginServer("origin_server") + self.origin_server.addResponse("sessionlog.json", + {"headers": "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n"}, + {"headers": "HTTP/1.1 200 OK\r\nServer: microserver\r\nConnection: close\r\n\r\n"}) + + def setupTS(self): + self.ts = Test.MakeATSProcess( + "ts", select_ports=True, enable_cache=False) + self.ts.Disk.records_config.update({ + "proxy.config.dns.splitDNS.enabled": 1, + "proxy.config.diags.debug.enabled": 1, + "proxy.config.diags.debug.tags": "dns|splitdns", + }) + self.ts.Disk.splitdns_config.AddLine( + f"dest_domain=foo.ts.a.o named=127.0.0.1:{self.dns.Variables.Port}") + self.ts.Disk.remap_config.AddLine( + f"map /foo/ http://foo.ts.a.o:{self.origin_server.Variables.Port}/") + self.ts.Disk.remap_config.AddLine( + f"map /bar/ http://127.0.0.1:{self.origin_server.Variables.Port}/") + + def addTestCase0(self): + tr = Test.AddTestRun() + tr.Processes.Default.Command = f"curl -v http://localhost:{self.ts.Variables.port}/foo/" + tr.Processes.Default.ReturnCode = 0 + tr.Processes.Default.Streams.stderr = "gold/test_case_0_stderr.gold" + tr.Processes.Default.StartBefore(self.dns) + tr.Processes.Default.StartBefore(self.origin_server) + tr.Processes.Default.StartBefore(self.ts) + tr.StillRunningAfter = self.dns + tr.StillRunningAfter = self.origin_server + tr.StillRunningAfter = self.ts + + def addTestCase1(self): + tr = Test.AddTestRun() + tr.Processes.Default.Command = f"curl -v http://localhost:{self.ts.Variables.port}/bar/" + tr.Processes.Default.ReturnCode = 0 + tr.Processes.Default.Streams.stderr = "gold/test_case_1_stderr.gold" + tr.StillRunningAfter = self.dns + tr.StillRunningAfter = self.origin_server + tr.StillRunningAfter = self.ts + + def run(self): + self.addTestCase0() + self.addTestCase1() + + +SplitDNSTest().run()