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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user