Skip to content

Commit

Permalink
Merge pull request #17 from jloh/dns_unit_tests
Browse files Browse the repository at this point in the history
Add unit tests for DNS endpoint
  • Loading branch information
jloh authored Feb 15, 2018
2 parents 096e867 + 9db0ad7 commit 839b862
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 1 deletion.
2 changes: 2 additions & 0 deletions conf/v1/dns.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
112 changes: 111 additions & 1 deletion t/v1/ip/04-dns.t
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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"})

0 comments on commit 839b862

Please sign in to comment.