diff --git a/conf/v1/dns.conf b/conf/v1/dns.conf index 73b2f87..db8d884 100644 --- a/conf/v1/dns.conf +++ b/conf/v1/dns.conf @@ -17,6 +17,7 @@ location = /v1/dns/ptr { } } location = /v1/dns/ptr.json { + default_type application/json; content_by_lua_block { -- Function to get our PTR! local getptr = require("geojs.utils").get_ptr @@ -41,6 +42,7 @@ location = /v1/dns/ptr.json { } } location = /v1/dns/ptr.js { + default_type application/javascript; content_by_lua_block { -- Function to get our PTR! local getptr = require("geojs.utils").get_ptr diff --git a/t/v1/ip/04-dns.t b/t/v1/ip/04-dns.t index cd6a5be..4b1646a 100644 --- a/t/v1/ip/04-dns.t +++ b/t/v1/ip/04-dns.t @@ -14,8 +14,10 @@ our $HttpConfig = qq{ geoip_country "$pwd/download-cache/maxmind/GeoIPv6.dat"; geoip_city "$pwd/download-cache/maxmind/GeoLiteCityv6.dat"; geoip_org "$pwd/download-cache/maxmind/GeoIPASNumv6.dat"; - lua_package_path "$pwd/lib/?.lua;;"; + lua_package_path "$pwd/lib/?.lua;$pwd/repos/lua-resty-dns/lib/?.lua;;"; + real_ip_header X-IP; set_real_ip_from 127.0.0.1/32; + }; run_tests(); @@ -35,3 +37,111 @@ GET /sanity [error] --- response_body OK + + +=== TEST 2.a: Plain text endpoint +--- http_config eval +"$::HttpConfig" +--- config + include "../../../conf/v1/dns.conf"; + set $geojs_dns_server '8.8.8.8'; +--- request +GET /v1/dns/ptr +--- more_headers +X-IP: 8.8.8.8 +--- no_error_log +[error] +--- response_headers +Content-Type: text/plain +--- response_body +google-public-dns-a.google.com + + +=== TEST 2.b: Plain text endpoint IP arg +--- http_config eval +"$::HttpConfig" +--- config + include "../../../conf/v1/dns.conf"; + set $geojs_dns_server '8.8.8.8'; +--- request +GET /v1/dns/ptr?ip=8.8.4.4 +--- more_headers +X-IP: 8.8.8.8 +--- no_error_log +[error] +--- response_headers +Content-Type: text/plain +--- response_body +google-public-dns-b.google.com + + +=== TEST 3.a: JSON Endpoint +--- http_config eval +"$::HttpConfig" +--- config + include "../../../conf/v1/dns.conf"; + set $geojs_dns_server '8.8.8.8'; +--- request +GET /v1/dns/ptr.json +--- more_headers +X-IP: 8.8.8.8 +--- no_error_log +[error] +--- response_headers +Content-Type: application/json +--- response_body +{"ptr":"google-public-dns-a.google.com"} + + +=== TEST 3.b: JSON Endpoint IP arg +--- http_config eval +"$::HttpConfig" +--- config + include "../../../conf/v1/dns.conf"; + set $geojs_dns_server '8.8.8.8'; +--- request +GET /v1/dns/ptr.json?ip=8.8.4.4 +--- more_headers +X-IP: 8.8.8.8 +--- no_error_log +[error] +--- response_headers +Content-Type: application/json +--- response_body +{"ptr":"google-public-dns-b.google.com"} + + +=== TEST 4.a: JS Endpoint +--- http_config eval +"$::HttpConfig" +--- config + include "../../../conf/v1/dns.conf"; + set $geojs_dns_server '8.8.8.8'; +--- request +GET /v1/dns/ptr.js +--- more_headers +X-IP: 8.8.8.8 +--- no_error_log +[error] +--- response_headers +Content-Type: application/javascript +--- response_body +ptr({"ptr":"google-public-dns-a.google.com"}) + + +=== TEST 4.b: JS Endpoint IP arg +--- http_config eval +"$::HttpConfig" +--- config + include "../../../conf/v1/dns.conf"; + set $geojs_dns_server '8.8.8.8'; +--- request +GET /v1/dns/ptr.js?ip=8.8.4.4 +--- more_headers +X-IP: 8.8.8.8 +--- no_error_log +[error] +--- response_headers +Content-Type: application/javascript +--- response_body +ptr({"ptr":"google-public-dns-b.google.com"})