diff --git a/Rakefile b/Rakefile index e40188318..d27412b0a 100644 --- a/Rakefile +++ b/Rakefile @@ -32,6 +32,22 @@ task :integration => ["install"] do Rake::Task['beef_stop'].invoke end +# TODO: Remove task before comitting +desc "Run DNS integration tests" +task :dns_rest do + Rake::Task['beef_start'].invoke + sh "cd test/integration; ruby -W0 ts_dns_rest.rb" + Rake::Task['beef_stop'].invoke +end + +# TODO: Remove task before comitting +desc "Run DNS unit tests" +task :dns do + Rake::Task['beef_start'].invoke + sh "cd test/unit; ruby -W0 ts_unit_dns.rb" + Rake::Task['beef_stop'].invoke +end + desc "Run integration unit tests" task :unit => ["install"] do sh "cd test/unit;ruby -W0 ts_unit.rb" diff --git a/test/integration/ts_dns_rest.rb b/test/integration/ts_dns_rest.rb new file mode 100644 index 000000000..301d30bba --- /dev/null +++ b/test/integration/ts_dns_rest.rb @@ -0,0 +1,20 @@ +# +# 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 '../common/ts_common' +require './tc_dns_rest' + +class TS_DnsIntegrationTests + + def self.suite + suite = Test::Unit::TestSuite.new(name="BeEF DNS Integration Test Suite") + suite << TC_DnsRest.suite + + return suite + end + +end + +Test::Unit::UI::Console::TestRunner.run(TS_DnsIntegrationTests) diff --git a/test/unit/extensions/tc_dns.rb b/test/unit/extensions/tc_dns.rb index 63d7c9b81..d9a2ab64d 100644 --- a/test/unit/extensions/tc_dns.rb +++ b/test/unit/extensions/tc_dns.rb @@ -4,16 +4,39 @@ # See the file 'doc/COPYING' for copying permission # require 'test/unit' +require 'resolv' class TC_Dns < Test::Unit::TestCase - def setup - $:.unshift(File.join(File.expand_path(File.dirname(__FILE__)), '.')) - $root_dir = File.expand_path('../../../../', __FILE__) + class << self + + def startup + $:.unshift(File.join(File.expand_path(File.dirname(__FILE__)), '../../../')) + + require 'core/loader' + require 'extensions/dns/extension' + + config = BeEF::Core::Configuration.instance + + @@address = config.get('beef.extension.dns.address') + @@port = config.get('beef.extension.dns.port') + + Thread.new do + dns = BeEF::Extension::Dns::Server.instance + dns.run_server(@@address, @@port) + end + end + end - def test_dns - assert(true) + def test_add_rule + dns = BeEF::Extension::Dns::Server.instance + + id = dns.add_rule('foo.bar', Resolv::DNS::Resource::IN::A) do |transaction| + transaction.respond!('1.2.3.4') + end + + assert_not_nil(id) end end diff --git a/test/unit/ts_unit_dns.rb b/test/unit/ts_unit_dns.rb new file mode 100644 index 000000000..986eb3f17 --- /dev/null +++ b/test/unit/ts_unit_dns.rb @@ -0,0 +1,20 @@ +# +# 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 '../common/ts_common' +require './extensions/tc_dns' + +class TS_BeefDnsTests + + def self.suite + suite = Test::Unit::TestSuite.new(name="BeEF DNS Unit Tests") + suite << TC_Dns.suite + + return suite + end + +end + +Test::Unit::UI::Console::TestRunner.run(TS_BeefDnsTests)