Added more tests for GET /api/dns/rule/:id with invalid input.

Also changed handler to return 404 when rule isn't found.
This commit is contained in:
soh_cah_toa
2013-06-08 21:58:28 -04:00
parent 3b58518cfd
commit e775748603
2 changed files with 18 additions and 1 deletions

View File

@@ -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

View File

@@ -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