From 6d9747a3f1169406f68ad18f4d0e77022ba3776a Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Mon, 1 Mar 2021 13:30:26 -0700 Subject: [PATCH] Fix tls setup code in tests --- common_test.go | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/common_test.go b/common_test.go index 70460e5f..b8bad5f8 100644 --- a/common_test.go +++ b/common_test.go @@ -98,22 +98,21 @@ func (c *caddyTestServer) server() *caddyhttp.Server { // create the routes var routes caddyhttp.RouteList + if c.tls { + // cheap hack for our tests to get TLS certs for the hostnames that + // it needs TLS certs for: create an empty route with a single host + // matcher for that hostname, and auto HTTPS will do the rest + hostMatcherJSON, err := json.Marshal(caddyhttp.MatchHost{host}) + if err != nil { + panic(err) + } + matchersRaw := caddyhttp.RawMatcherSets{ + caddy.ModuleMap{"host": hostMatcherJSON}, + } + routes = append(routes, caddyhttp.Route{MatcherSetsRaw: matchersRaw}) + } if c.proxyHandler != nil { if host != "" { - if c.tls { - // cheap hack for our tests to get TLS certs for the hostnames that - // it needs TLS certs for: create an empty route with a single host - // matcher for that hostname, and auto HTTPS will do the rest - hostMatcherJSON, err := json.Marshal(caddyhttp.MatchHost{host}) - if err != nil { - panic(err) - } - matchersRaw := caddyhttp.RawMatcherSets{ - caddy.ModuleMap{"host": hostMatcherJSON}, - } - routes = append(routes, caddyhttp.Route{MatcherSetsRaw: matchersRaw}) - } - // tell the proxy which hostname to serve the proxy on; this must // be distinct from the host matcher, since the proxy basically // does its own host matching