Merge pull request #4673 from jacksontj/helpful_dns_error
More helpful dns error
This commit is contained in:
commit
bd07afb1cc
2 changed files with 8 additions and 9 deletions
|
@ -40,38 +40,37 @@ describe("dns.lookup", function()
|
||||||
it("returns host when the query returns nil", function()
|
it("returns host when the query returns nil", function()
|
||||||
helpers.mock_resty_dns_query(nil, nil, "oops!")
|
helpers.mock_resty_dns_query(nil, nil, "oops!")
|
||||||
assert.are.same({ "example.com" }, dns_lookup("example.com"))
|
assert.are.same({ "example.com" }, dns_lookup("example.com"))
|
||||||
assert.spy(spy_ngx_log).was_called_with(ngx.ERR, "failed to query the DNS server:\noops!\noops!")
|
assert.spy(spy_ngx_log).was_called_with(ngx.ERR, "failed to query the DNS server for ", "example.com", ":\n", "oops!\noops!")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("returns host when the query returns empty answer", function()
|
it("returns host when the query returns empty answer", function()
|
||||||
helpers.mock_resty_dns_query(nil, {})
|
helpers.mock_resty_dns_query(nil, {})
|
||||||
assert.are.same({ "example.com" }, dns_lookup("example.com"))
|
assert.are.same({ "example.com" }, dns_lookup("example.com"))
|
||||||
assert.spy(spy_ngx_log).was_called_with(ngx.ERR, "failed to query the DNS server:\nno A record resolved\nno AAAA record resolved")
|
assert.spy(spy_ngx_log).was_called_with(ngx.ERR, "failed to query the DNS server for ", "example.com", ":\n", "no A record resolved\nno AAAA record resolved")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("returns host when there's answer but with error", function()
|
it("returns host when there's answer but with error", function()
|
||||||
helpers.mock_resty_dns_query(nil, { errcode = 1, errstr = "format error" })
|
helpers.mock_resty_dns_query(nil, { errcode = 1, errstr = "format error" })
|
||||||
assert.are.same({ "example.com" }, dns_lookup("example.com"))
|
assert.are.same({ "example.com" }, dns_lookup("example.com"))
|
||||||
assert.spy(spy_ngx_log).was_called_with(ngx.ERR, "failed to query the DNS server:\n" ..
|
assert.spy(spy_ngx_log).was_called_with(ngx.ERR, "failed to query the DNS server for ", "example.com", ":\n", "server returned error code: 1: format error\nserver returned error code: 1: format error")
|
||||||
"server returned error code: 1: format error\nserver returned error code: 1: format error")
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("retuns host when there's answer but no A/AAAA record in it", function()
|
it("retuns host when there's answer but no A/AAAA record in it", function()
|
||||||
helpers.mock_resty_dns_query(nil, { { name = "example.com", cname = "sub.example.com", ttl = 60 } })
|
helpers.mock_resty_dns_query(nil, { { name = "example.com", cname = "sub.example.com", ttl = 60 } })
|
||||||
assert.are.same({ "example.com" }, dns_lookup("example.com"))
|
assert.are.same({ "example.com" }, dns_lookup("example.com"))
|
||||||
assert.spy(spy_ngx_log).was_called_with(ngx.ERR, "failed to query the DNS server:\nno A record resolved\nno AAAA record resolved")
|
assert.spy(spy_ngx_log).was_called_with(ngx.ERR, "failed to query the DNS server for ", "example.com", ":\n", "no A record resolved\nno AAAA record resolved")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("returns host when the query returns nil and number of dots is not less than configured ndots", function()
|
it("returns host when the query returns nil and number of dots is not less than configured ndots", function()
|
||||||
helpers.mock_resty_dns_query(nil, nil, "oops!")
|
helpers.mock_resty_dns_query(nil, nil, "oops!")
|
||||||
assert.are.same({ "a.b.c.d.example.com" }, dns_lookup("a.b.c.d.example.com"))
|
assert.are.same({ "a.b.c.d.example.com" }, dns_lookup("a.b.c.d.example.com"))
|
||||||
assert.spy(spy_ngx_log).was_called_with(ngx.ERR, "failed to query the DNS server:\noops!\noops!")
|
assert.spy(spy_ngx_log).was_called_with(ngx.ERR, "failed to query the DNS server for ", "a.b.c.d.example.com", ":\n", "oops!\noops!")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("returns host when the query returns nil for a fully qualified domain", function()
|
it("returns host when the query returns nil for a fully qualified domain", function()
|
||||||
helpers.mock_resty_dns_query("example.com.", nil, "oops!")
|
helpers.mock_resty_dns_query("example.com.", nil, "oops!")
|
||||||
assert.are.same({ "example.com." }, dns_lookup("example.com."))
|
assert.are.same({ "example.com." }, dns_lookup("example.com."))
|
||||||
assert.spy(spy_ngx_log).was_called_with(ngx.ERR, "failed to query the DNS server:\noops!\noops!")
|
assert.spy(spy_ngx_log).was_called_with(ngx.ERR, "failed to query the DNS server for ", "example.com.", ":\n", "oops!\noops!")
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,7 @@ function _M.lookup(host)
|
||||||
return addresses
|
return addresses
|
||||||
end
|
end
|
||||||
|
|
||||||
ngx_log(ngx_ERR, "failed to query the DNS server:\n" .. table_concat(dns_errors, "\n"))
|
ngx_log(ngx_ERR, "failed to query the DNS server for ", host, ":\n", table_concat(dns_errors, "\n"))
|
||||||
|
|
||||||
return { host }
|
return { host }
|
||||||
end
|
end
|
||||||
|
@ -147,7 +147,7 @@ function _M.lookup(host)
|
||||||
end
|
end
|
||||||
|
|
||||||
if #dns_errors > 0 then
|
if #dns_errors > 0 then
|
||||||
ngx_log(ngx_ERR, "failed to query the DNS server:\n" .. table_concat(dns_errors, "\n"))
|
ngx_log(ngx_ERR, "failed to query the DNS server for ", host, ":\n", table_concat(dns_errors, "\n"))
|
||||||
end
|
end
|
||||||
|
|
||||||
return { host }
|
return { host }
|
||||||
|
|
Loading…
Reference in a new issue