From 004fa2d1feb15ada1a5f720d60ecce3436da2a5b Mon Sep 17 00:00:00 2001 From: Wangchong Zhou Date: Mon, 14 Nov 2022 17:56:10 +0800 Subject: [PATCH] chore(tests): remove hardcoded dns resolver in tests (#9748) FTI-3133 --- spec/01-unit/03-conf_loader_spec.lua | 4 +- spec/01-unit/04-prefix_handler_spec.lua | 4 +- spec/01-unit/09-balancer/01-generic_spec.lua | 7 +- .../09-balancer/02-least_connections_spec.lua | 2 +- .../03-consistent_hashing_spec.lua | 7 +- .../09-balancer/04-round_robin_spec.lua | 14 +-- spec/01-unit/14-dns_spec.lua | 2 +- spec/01-unit/21-dns-client/01-utils_spec.lua | 18 ++-- spec/01-unit/21-dns-client/02-client_spec.lua | 89 +++++++++---------- .../21-dns-client/03-client_cache_spec.lua | 8 +- spec/fixtures/headers.conf | 1 - spec/fixtures/invalid.conf | 1 - spec/fixtures/to-strip.conf | 2 - spec/kong_tests.conf | 1 - 14 files changed, 77 insertions(+), 83 deletions(-) diff --git a/spec/01-unit/03-conf_loader_spec.lua b/spec/01-unit/03-conf_loader_spec.lua index 7f0a8b9c7bbe..fa8796f0f1c1 100644 --- a/spec/01-unit/03-conf_loader_spec.lua +++ b/spec/01-unit/03-conf_loader_spec.lua @@ -655,7 +655,7 @@ describe("Configuration loader", function() assert.is_nil(conf) conf, err = conf_loader(nil, { - dns_resolver = "8.8.8.8:53" + dns_resolver = "198.51.100.0:53" }) assert.is_nil(err) assert.is_table(conf) @@ -667,7 +667,7 @@ describe("Configuration loader", function() assert.is_table(conf) conf, err = conf_loader(nil, { - dns_resolver = "8.8.8.8,1.2.3.4:53,::1,[::1]:53" + dns_resolver = "198.51.100.0,1.2.3.4:53,::1,[::1]:53" }) assert.is_nil(err) assert.is_table(conf) diff --git a/spec/01-unit/04-prefix_handler_spec.lua b/spec/01-unit/04-prefix_handler_spec.lua index 550d15a85aeb..a85b423ef962 100644 --- a/spec/01-unit/04-prefix_handler_spec.lua +++ b/spec/01-unit/04-prefix_handler_spec.lua @@ -763,11 +763,11 @@ describe("NGINX conf compiler", function() end) it("converts dns_resolver to string", function() local nginx_conf = prefix_handler.compile_nginx_conf({ - dns_resolver = { "8.8.8.8", "8.8.4.4" } + dns_resolver = { "1.2.3.4", "5.6.7.8" } }, [[ "resolver ${{DNS_RESOLVER}} ipv6=off;" ]]) - assert.matches("resolver%s+8%.8%.8%.8 8%.8%.4%.4 ipv6=off;", nginx_conf) + assert.matches("resolver%s+1%.2%.3%.4 5%.6%.7%.8 ipv6=off;", nginx_conf) end) end) diff --git a/spec/01-unit/09-balancer/01-generic_spec.lua b/spec/01-unit/09-balancer/01-generic_spec.lua index 6322d5a01991..9baee61b796d 100644 --- a/spec/01-unit/09-balancer/01-generic_spec.lua +++ b/spec/01-unit/09-balancer/01-generic_spec.lua @@ -220,9 +220,10 @@ for _, algorithm in ipairs{ "consistent-hashing", "least-connections", "round-ro setup_block() assert(client.init { hosts = {}, - resolvConf = { - "nameserver 8.8.8.8" - }, + -- don't supply resolvConf and fallback to default resolver + -- so that CI and docker can have reliable results + -- but remove `search` and `domain` + search = {}, }) snapshot = assert:snapshot() assert:set_parameter("TableFormatLevel", 10) diff --git a/spec/01-unit/09-balancer/02-least_connections_spec.lua b/spec/01-unit/09-balancer/02-least_connections_spec.lua index 65d4899a266a..65be77d67782 100644 --- a/spec/01-unit/09-balancer/02-least_connections_spec.lua +++ b/spec/01-unit/09-balancer/02-least_connections_spec.lua @@ -221,7 +221,7 @@ describe("[least-connections]", function() assert(client.init { hosts = {}, resolvConf = { - "nameserver 8.8.8.8" + "nameserver 198.51.100.0" }, }) snapshot = assert:snapshot() diff --git a/spec/01-unit/09-balancer/03-consistent_hashing_spec.lua b/spec/01-unit/09-balancer/03-consistent_hashing_spec.lua index 750e9a1f9951..2c37cf49c82e 100644 --- a/spec/01-unit/09-balancer/03-consistent_hashing_spec.lua +++ b/spec/01-unit/09-balancer/03-consistent_hashing_spec.lua @@ -264,9 +264,10 @@ describe("[consistent_hashing]", function() setup_block() assert(client.init { hosts = {}, - resolvConf = { - "nameserver 8.8.8.8" - }, + -- don't supply resolvConf and fallback to default resolver + -- so that CI and docker can have reliable results + -- but remove `search` and `domain` + search = {}, }) snapshot = assert:snapshot() end) diff --git a/spec/01-unit/09-balancer/04-round_robin_spec.lua b/spec/01-unit/09-balancer/04-round_robin_spec.lua index a439d3e20ab5..e96fa8843220 100644 --- a/spec/01-unit/09-balancer/04-round_robin_spec.lua +++ b/spec/01-unit/09-balancer/04-round_robin_spec.lua @@ -303,9 +303,10 @@ describe("[round robin balancer]", function() setup_block() assert(client.init { hosts = {}, - resolvConf = { - "nameserver 8.8.8.8" - }, + -- don't supply resolvConf and fallback to default resolver + -- so that CI and docker can have reliable results + -- but remove `search` and `domain` + search = {}, }) snapshot = assert:snapshot() end) @@ -1263,9 +1264,10 @@ describe("[round robin balancer]", function() -- reconfigure the dns client to make sure next query works again assert(client.init { hosts = {}, - resolvConf = { - "nameserver 8.8.8.8" - }, + -- don't supply resolvConf and fallback to default resolver + -- so that CI and docker can have reliable results + -- but remove `search` and `domain` + search = {}, }) dnsA({ { name = "mashape.test", address = "1.2.3.4" }, diff --git a/spec/01-unit/14-dns_spec.lua b/spec/01-unit/14-dns_spec.lua index 6569bcf52b9b..3be181652ee4 100644 --- a/spec/01-unit/14-dns_spec.lua +++ b/spec/01-unit/14-dns_spec.lua @@ -26,7 +26,7 @@ local function setup_it_block() client.init { hosts = {}, resolvConf = {}, - nameservers = { "8.8.8.8" }, + nameservers = { "198.51.100.0" }, enable_ipv6 = true, order = { "LAST", "SRV", "A", "CNAME" }, } diff --git a/spec/01-unit/21-dns-client/01-utils_spec.lua b/spec/01-unit/21-dns-client/01-utils_spec.lua index f1f888346dc2..588096b04b5d 100644 --- a/spec/01-unit/21-dns-client/01-utils_spec.lua +++ b/spec/01-unit/21-dns-client/01-utils_spec.lua @@ -141,9 +141,9 @@ describe("[utils]", function() domain myservice.com -nameserver 8.8.8.8 -nameserver 2602:306:bca8:1ac0::1 ; and a comment here -nameserver 8.8.8.8:1234 ; this one has a port number (limited systems support this) +nameserver 198.51.100.0 +nameserver 2001:db8::1 ; and a comment here +nameserver 198.51.100.0:1234 ; this one has a port number (limited systems support this) nameserver 1.2.3.4 ; this one is 4th, so should be ignored # search is commented out, test below for a mutually exclusive one @@ -172,7 +172,7 @@ options use-vc local resolv, err = dnsutils.parseResolvConf(file) assert.is.Nil(err) assert.is.equal("myservice.com", resolv.domain) - assert.is.same({ "8.8.8.8", "2602:306:bca8:1ac0::1", "8.8.8.8:1234" }, resolv.nameserver) + assert.is.same({ "198.51.100.0", "2001:db8::1", "198.51.100.0:1234" }, resolv.nameserver) assert.is.same({ "list1", "list2" }, resolv.sortlist) assert.is.same({ ndots = 2, timeout = 3, attempts = 4, debug = true, rotate = true, ["no-check-names"] = true, inet6 = true, ["ip6-bytestring"] = true, @@ -221,8 +221,8 @@ search domain1.com domain2.com domain3.com domain4.com domain5.com domain6.com d [[# this is just a comment line domain myservice.com -nameserver 8.8.8.8 -nameserver 8.8.4.4 ; and a comment here +nameserver 198.51.100.0 +nameserver 198.51.100.1 ; and a comment here options ndots:1 ]]) @@ -244,8 +244,8 @@ options ndots:1 [[# this is just a comment line domain myservice.com -nameserver 8.8.8.8 -nameserver 8.8.4.4 ; and a comment here +nameserver 198.51.100.0 +nameserver 198.51.100.1 ; and a comment here options ndots:2 ]]) @@ -287,7 +287,7 @@ options ndots:2 else return { -- resolv.conf file "domain myservice.com", - "nameserver 8.8.8.8 ", + "nameserver 198.51.100.0 ", } end end diff --git a/spec/01-unit/21-dns-client/02-client_spec.lua b/spec/01-unit/21-dns-client/02-client_spec.lua index 812f30f14112..37256b6402b0 100644 --- a/spec/01-unit/21-dns-client/02-client_spec.lua +++ b/spec/01-unit/21-dns-client/02-client_spec.lua @@ -109,7 +109,7 @@ describe("[DNS client]", function() it("succeeds without i/o access", function() local result, err = assert(client.init({ - nameservers = { "8.8.8.8:53" }, + nameservers = { "198.51.100.0:53" }, hosts = {}, -- empty tables to parse to prevent defaulting to /etc/hosts resolvConf = {}, -- and resolv.conf files })) @@ -123,7 +123,7 @@ describe("[DNS client]", function() it("if absent", function() local result, err, record result, err = assert(client.init({ - nameservers = { "8.8.8.8:53" }, + nameservers = { "198.51.100.0:53" }, resolvConf = {}, hosts = {}, })) @@ -138,7 +138,7 @@ describe("[DNS client]", function() it("not if ipv4 exists", function() local result, err, record result, err = assert(client.init({ - nameservers = { "8.8.8.8:53" }, + nameservers = { "198.51.100.0:53" }, resolvConf = {}, hosts = {"1.2.3.4 localhost"}, })) @@ -157,7 +157,7 @@ describe("[DNS client]", function() it("not if ipv6 exists", function() local result, err, record result, err = assert(client.init({ - nameservers = { "8.8.8.8:53" }, + nameservers = { "198.51.100.0:53" }, resolvConf = {}, hosts = {"::1:2:3:4 localhost"}, })) @@ -184,7 +184,7 @@ describe("[DNS client]", function() it("works with a 'search' option", function() assert(client.init({ resolvConf = { - "nameserver 8.8.8.8", + "nameserver 198.51.100.0", "search one.com two.com", "options ndots:1", } @@ -212,7 +212,7 @@ describe("[DNS client]", function() it("works with a 'search .' option", function() assert(client.init({ resolvConf = { - "nameserver 8.8.8.8", + "nameserver 198.51.100.0", "search .", "options ndots:1", } @@ -232,7 +232,7 @@ describe("[DNS client]", function() it("works with a 'domain' option", function() assert(client.init({ resolvConf = { - "nameserver 8.8.8.8", + "nameserver 198.51.100.0", "domain local.domain.com", "options ndots:1", } @@ -256,7 +256,7 @@ describe("[DNS client]", function() it("handles last successful type", function() assert(client.init({ resolvConf = { - "nameserver 8.8.8.8", + "nameserver 198.51.100.0", "search one.com two.com", "options ndots:1", } @@ -291,7 +291,7 @@ describe("[DNS client]", function() it("works with a 'search' option", function() assert(client.init({ resolvConf = { - "nameserver 8.8.8.8", + "nameserver 198.51.100.0", "search one.com two.com", "options ndots:1", } @@ -311,7 +311,7 @@ describe("[DNS client]", function() it("works with a 'search .' option", function() assert(client.init({ resolvConf = { - "nameserver 8.8.8.8", + "nameserver 198.51.100.0", "search .", "options ndots:1", } @@ -331,7 +331,7 @@ describe("[DNS client]", function() it("works with a 'domain' option", function() assert(client.init({ resolvConf = { - "nameserver 8.8.8.8", + "nameserver 198.51.100.0", "domain local.domain.com", "options ndots:1", } @@ -351,7 +351,7 @@ describe("[DNS client]", function() it("handles last successful type", function() assert(client.init({ resolvConf = { - "nameserver 8.8.8.8", + "nameserver 198.51.100.0", "search one.com two.com", "options ndots:1", } @@ -378,7 +378,7 @@ describe("[DNS client]", function() it("works with a 'search' option", function() assert(client.init({ resolvConf = { - "nameserver 8.8.8.8", + "nameserver 198.51.100.0", "search one.com two.com", "options ndots:1", } @@ -398,7 +398,7 @@ describe("[DNS client]", function() it("works with a 'domain' option", function() assert(client.init({ resolvConf = { - "nameserver 8.8.8.8", + "nameserver 198.51.100.0", "domain local.domain.com", "options ndots:1", } @@ -417,7 +417,7 @@ describe("[DNS client]", function() it("ignores last successful type", function() assert(client.init({ resolvConf = { - "nameserver 8.8.8.8", + "nameserver 198.51.100.0", "search one.com two.com", "options ndots:1", } @@ -442,7 +442,7 @@ describe("[DNS client]", function() it("works with a 'search' option", function() assert(client.init({ resolvConf = { - "nameserver 8.8.8.8", + "nameserver 198.51.100.0", "search one.com two.com", "options ndots:1", } @@ -460,7 +460,7 @@ describe("[DNS client]", function() it("works with a 'domain' option", function() assert(client.init({ resolvConf = { - "nameserver 8.8.8.8", + "nameserver 198.51.100.0", "domain local.domain.com", "options ndots:1", } @@ -478,7 +478,7 @@ describe("[DNS client]", function() it("ignores last successful type", function() assert(client.init({ resolvConf = { - "nameserver 8.8.8.8", + "nameserver 198.51.100.0", "search one.com two.com", "options ndots:1", } @@ -500,7 +500,7 @@ describe("[DNS client]", function() it("honours 'ndots'", function() assert(client.init({ resolvConf = { - "nameserver 8.8.8.8", + "nameserver 198.51.100.0", "search one.com two.com", "options ndots:1", } @@ -529,7 +529,7 @@ describe("[DNS client]", function() it("hosts file always resolves first, overriding `ndots`", function() assert(client.init({ resolvConf = { - "nameserver 8.8.8.8", + "nameserver 198.51.100.0", "search one.com two.com", "options ndots:1", }, @@ -789,10 +789,10 @@ describe("[DNS client]", function() it("fetching non-type-matching records", function() assert(client.init({ - resolvConf = { - -- resolv.conf without `search` and `domain` options - "nameserver 8.8.8.8", - }, + -- don't supply resolvConf and fallback to default resolver + -- so that CI and docker can have reliable results + -- but remove `search` and `domain` + search = {}, })) local host = "srvtest.thijsschreijer.nl" @@ -805,10 +805,10 @@ describe("[DNS client]", function() it("fetching non-existing records", function() assert(client.init({ - resolvConf = { - -- resolv.conf without `search` and `domain` options - "nameserver 8.8.8.8", - }, + -- don't supply resolvConf and fallback to default resolver + -- so that CI and docker can have reliable results + -- but remove `search` and `domain` + search = {}, })) local host = "IsNotHere.thijsschreijer.nl" @@ -902,7 +902,7 @@ describe("[DNS client]", function() assert(client.init({ resolvConf = { -- resolv.conf without `search` and `domain` options - "nameserver 8.8.8.8", + "nameserver 198.51.100.0", }, })) @@ -951,7 +951,7 @@ describe("[DNS client]", function() assert(client.init({ resolvConf = { -- resolv.conf without `search` and `domain` options - "nameserver 8.8.8.8", + "nameserver 198.51.100.0", }, })) query_func = function(self, original_query_func, name, opts) @@ -978,7 +978,7 @@ describe("[DNS client]", function() assert(client.init({ resolvConf = { -- resolv.conf without `search` and `domain` options - "nameserver 8.8.8.8", + "nameserver 198.51.100.0", }, })) local lrucache = client.getcache() @@ -1006,7 +1006,7 @@ describe("[DNS client]", function() assert(client.init({ resolvConf = { -- resolv.conf without `search` and `domain` options - "nameserver 8.8.8.8", + "nameserver 198.51.100.0", }, })) local lrucache = client.getcache() @@ -1320,12 +1320,7 @@ describe("[DNS client]", function() assert.is_nil(port) end) it("recursive SRV pointing to itself",function() - assert(client.init({ - resolvConf = { - -- resolv.conf without `search` and `domain` options - "nameserver 8.8.8.8", - }, - })) + assert(client.init({ search = {}, })) local ip, record, port, host, err, _ host = "srvrecurse.thijsschreijer.nl" @@ -1402,7 +1397,7 @@ describe("[DNS client]", function() assert(client.init({ resolvConf = { -- resolv.conf without `search` and `domain` options - "nameserver 8.8.8.8", + "nameserver 198.51.100.0", }, })) local lrucache = client.getcache() @@ -1451,7 +1446,7 @@ describe("[DNS client]", function() validTtl = validTtl, resolvConf = { -- resolv.conf without `search` and `domain` options - "nameserver 8.8.8.8", + "nameserver 198.51.100.0", }, })) @@ -1486,10 +1481,10 @@ describe("[DNS client]", function() assert(client.init({ emptyTtl = emptyTtl, staleTtl = staleTtl, - resolvConf = { - -- resolv.conf without `search` and `domain` options - "nameserver 8.8.8.8", - }, + -- don't supply resolvConf and fallback to default resolver + -- so that CI and docker can have reliable results + -- but remove `search` and `domain` + search = {}, })) -- mock query function to count calls @@ -1563,7 +1558,7 @@ describe("[DNS client]", function() staleTtl = staleTtl, resolvConf = { -- resolv.conf without `search` and `domain` options - "nameserver 8.8.8.8", + "nameserver 198.51.100.0", }, })) @@ -1689,7 +1684,7 @@ describe("[DNS client]", function() retrans = 1, resolvConf = { -- resolv.conf without `search` and `domain` options - "nameserver 8.8.8.8", + "nameserver 198.51.100.0", }, })) @@ -1750,7 +1745,7 @@ describe("[DNS client]", function() assert(client.init({ resolvConf = { -- resolv.conf without `search` and `domain` options - "nameserver 8.8.8.8", + "nameserver 198.51.100.0", }, noSynchronisation = true, })) diff --git a/spec/01-unit/21-dns-client/03-client_cache_spec.lua b/spec/01-unit/21-dns-client/03-client_cache_spec.lua index 971b10354201..0f07267cdb23 100644 --- a/spec/01-unit/21-dns-client/03-client_cache_spec.lua +++ b/spec/01-unit/21-dns-client/03-client_cache_spec.lua @@ -68,7 +68,7 @@ describe("[DNS client cache]", function() local lrucache, mock_records, config before_each(function() config = { - nameservers = { "8.8.8.8" }, + nameservers = { "198.51.100.0" }, ndots = 1, search = { "domain.com" }, hosts = {}, @@ -268,7 +268,7 @@ describe("[DNS client cache]", function() local lrucache, mock_records, config before_each(function() config = { - nameservers = { "8.8.8.8" }, + nameservers = { "198.51.100.0" }, ndots = 1, search = { "domain.com" }, hosts = {}, @@ -448,7 +448,7 @@ describe("[DNS client cache]", function() local lrucache, mock_records, config -- luacheck: ignore before_each(function() config = { - nameservers = { "8.8.8.8" }, + nameservers = { "198.51.100.0" }, ndots = 1, search = { "domain.com" }, hosts = {}, @@ -561,7 +561,7 @@ describe("[DNS client cache]", function() local lrucache, mock_records, config -- luacheck: ignore before_each(function() config = { - nameservers = { "8.8.8.8" }, + nameservers = { "198.51.100.0" }, hosts = {"127.0.0.1 myname.lan"}, resolvConf = {}, validTtl = 0.1, diff --git a/spec/fixtures/headers.conf b/spec/fixtures/headers.conf index 09bd4980c3d9..16121d48e744 100644 --- a/spec/fixtures/headers.conf +++ b/spec/fixtures/headers.conf @@ -8,7 +8,6 @@ ssl_cert_key = spec/fixtures/kong_spec.key admin_ssl_cert = spec/fixtures/kong_spec.crt admin_ssl_cert_key = spec/fixtures/kong_spec.key -dns_resolver = 8.8.8.8 database = postgres pg_host = 127.0.0.1 pg_port = 5432 diff --git a/spec/fixtures/invalid.conf b/spec/fixtures/invalid.conf index a209fb352239..297dfe0a6116 100644 --- a/spec/fixtures/invalid.conf +++ b/spec/fixtures/invalid.conf @@ -1,3 +1,2 @@ pg_ssl = on -dns_resolver = 8.8.8.8 cassandra_repl_strategy = foo diff --git a/spec/fixtures/to-strip.conf b/spec/fixtures/to-strip.conf index 3ef20b764d9e..635afdcba8f6 100644 --- a/spec/fixtures/to-strip.conf +++ b/spec/fixtures/to-strip.conf @@ -6,8 +6,6 @@ pg_ssl = off # Toggles client-server TLS connections pg_password = test\#123 # do not strip an escaped octothorpe -dns_resolver = 8.8.8.8 - cassandra_data_centers = dc1:2, dc2:3 , dc3:4 plugins = foobar,hello-world diff --git a/spec/kong_tests.conf b/spec/kong_tests.conf index 4c1f89ee6936..2667e2f29ce0 100644 --- a/spec/kong_tests.conf +++ b/spec/kong_tests.conf @@ -9,7 +9,6 @@ ssl_cert_key = spec/fixtures/kong_spec.key admin_ssl_cert = spec/fixtures/kong_spec.crt admin_ssl_cert_key = spec/fixtures/kong_spec.key -dns_resolver = 8.8.8.8 database = postgres pg_host = 127.0.0.1 pg_port = 5432