From 1f37ceec9fcd1dbb1c29957b748a742e0b15bf96 Mon Sep 17 00:00:00 2001 From: soh_cah_toa Date: Thu, 6 Jun 2013 23:16:40 -0400 Subject: [PATCH] Began first integration tests for DNS RESTful API interface. First test is for POST /api/dns/rule handler. --- test/common/test_constants.rb | 3 +- test/integration/tc_dns_rest.rb | 49 ++++++++++++++++++++++++++++++ test/integration/ts_integration.rb | 2 ++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 test/integration/tc_dns_rest.rb diff --git a/test/common/test_constants.rb b/test/common/test_constants.rb index 856161249..b28f315f6 100644 --- a/test/common/test_constants.rb +++ b/test/common/test_constants.rb @@ -19,4 +19,5 @@ BEEF_PASSWD = "beef" RESTAPI_HOOKS = "http://" + ATTACK_DOMAIN + ":3000/api/hooks" RESTAPI_LOGS = "http://" + ATTACK_DOMAIN + ":3000/api/logs" RESTAPI_MODULES = "http://" + ATTACK_DOMAIN + ":3000/api/modules" -RESTAPI_ADMIN = "http://" + ATTACK_DOMAIN + ":3000/api/admin" \ No newline at end of file +RESTAPI_DNS = "http://" + ATTACK_DOMAIN + ":3000/api/dns" +RESTAPI_ADMIN = "http://" + ATTACK_DOMAIN + ":3000/api/admin" diff --git a/test/integration/tc_dns_rest.rb b/test/integration/tc_dns_rest.rb new file mode 100644 index 000000000..3e5eda166 --- /dev/null +++ b/test/integration/tc_dns_rest.rb @@ -0,0 +1,49 @@ +# +# Copyright (c) 2006-2013 Wade Alcorn - wade@bindshell.net +# Browser Exploitation Framework (BeEF) - http://beefproject.com +# See the file 'doc/COPYING' for copying permission +# +require 'test/unit' +require 'rest_client' +require 'json' +require '../common/test_constants' + +class TC_DnsRest < Test::Unit::TestCase + + class << self + + def startup + json = {:username => BEEF_USER, :password => BEEF_PASSWD}.to_json + @@headers = {:content_type => :json, :accept => :json} + + response = RestClient.post("#{RESTAPI_ADMIN}/login", + json, + @@headers) + + result = JSON.parse(response.body) + @@token = result['token'] + end + + end + + def test_1_add_rule + pattern = 'foo.bar' + type = 'A' + dns_response = ['1.2.3.4'] + + json = {:pattern => pattern, :type => type, :response => dns_response}.to_json + + rest_response = RestClient.post("#{RESTAPI_DNS}/rule?token=#{@@token}", + json, + @@headers) + + assert_not_nil(rest_response.body) + assert_equal(200, rest_response.code) + + result = JSON.parse(rest_response.body) + + assert(result['success']) + assert(result['id']) + end + +end diff --git a/test/integration/ts_integration.rb b/test/integration/ts_integration.rb index c148a9c9d..d25ef06c7 100644 --- a/test/integration/ts_integration.rb +++ b/test/integration/ts_integration.rb @@ -16,6 +16,7 @@ require './check_environment' # Basic log in and log out tests require './tc_debug_modules' # RESTful API tests (as well as debug modules) require './tc_login' # Basic log in and log out tests require './tc_jools' # Basic tests for jools +require './tc_dns_rest' # Basic tests for DNS RESTful API interface class TS_BeefIntegrationTests def self.suite @@ -25,6 +26,7 @@ class TS_BeefIntegrationTests suite << TC_login.suite suite << TC_DebugModules.suite suite << TC_Jools.suite + suite << TC_DnsRest.suite return suite end