diff --git a/extensions/dns/rest/dns.rb b/extensions/dns/rest/dns.rb index 05e076140..754277df7 100644 --- a/extensions/dns/rest/dns.rb +++ b/extensions/dns/rest/dns.rb @@ -50,6 +50,8 @@ module Dns end result = BeEF::Extension::Dns::Server.instance.get_rule(id) + halt 404 if result.length == 0 + result.to_json rescue InvalidParamError => e print_error e.message diff --git a/test/integration/tc_dns_rest.rb b/test/integration/tc_dns_rest.rb index 8c749f47a..052d050b2 100644 --- a/test/integration/tc_dns_rest.rb +++ b/test/integration/tc_dns_rest.rb @@ -278,7 +278,7 @@ class TC_DnsRest < Test::Unit::TestCase end end - # Tests GET /api/dns/rule/:id handler + # Tests GET /api/dns/rule/:id handler with valid input def test_4_get_rule_good pattern = 'wheres.the.beef' type = 'A' @@ -307,6 +307,21 @@ class TC_DnsRest < Test::Unit::TestCase assert_equal(dns_response, result['response']) end + # Tests GET /api/dns/rule/:id handler with invalid input + def test_4_get_rule_bad + id = 42 + + assert_raise RestClient::ResourceNotFound do + response = RestClient.get("#{RESTAPI_DNS}/rule/#{id}", :params => {:token => @@token}) + end + + id = '(*_*)' + + assert_raise RestClient::BadRequest do + RestClient.get("#{RESTAPI_DNS}/rule/#{id}", :params => {:token => @@token}) + end + end + private # Adds a new DNS rule