diff --git a/test/unit/BeEF.rc b/test/thirdparty/msf/unit/BeEF.rc similarity index 100% rename from test/unit/BeEF.rc rename to test/thirdparty/msf/unit/BeEF.rc diff --git a/test/thirdparty/msf/unit/check_environment.rb b/test/thirdparty/msf/unit/check_environment.rb new file mode 100644 index 000000000..3594ba117 --- /dev/null +++ b/test/thirdparty/msf/unit/check_environment.rb @@ -0,0 +1,10 @@ +require 'test/unit' + +class TC_CheckEnvironment < Test::Unit::TestCase + + def test_check_env + # Add environment checks here + + end + +end \ No newline at end of file diff --git a/test/unit/extensions/tc_metasploit.rb b/test/thirdparty/msf/unit/tc_metasploit.rb similarity index 81% rename from test/unit/extensions/tc_metasploit.rb rename to test/thirdparty/msf/unit/tc_metasploit.rb index f0478f35b..3f625ca9b 100644 --- a/test/unit/extensions/tc_metasploit.rb +++ b/test/thirdparty/msf/unit/tc_metasploit.rb @@ -19,8 +19,13 @@ require 'pp' class TC_Metasploit < Test::Unit::TestCase def setup - $root_dir="../../" - $:.unshift File.join( %w{ ../../ } ) + $root_dir="../../../../" + $:.unshift File.join( %w{ ../../../../ } ) + require 'core/loader' + end + + def teardown + $root_dir = nil end # @@ -42,12 +47,12 @@ class TC_Metasploit < Test::Unit::TestCase # Create an api instance def new_api - load_config - require 'extensions/metasploit/extension.rb' - @api = BeEF::Extension::Metasploit::RpcClient.instance - @api.unit_test_init() + load_config + require 'extensions/metasploit/extension.rb' + @api = BeEF::Extension::Metasploit::RpcClient.instance + @api.unit_test_init() end - + # # Verify that the config file has required information # @@ -74,7 +79,7 @@ class TC_Metasploit < Test::Unit::TestCase # Verify that the login is working # def test_login - new_api + new_api assert(@api.login) end @@ -83,13 +88,13 @@ class TC_Metasploit < Test::Unit::TestCase @api.login assert(@api.call('core.version')) end - + def test_browser_exploits new_api @api.login exploits = nil assert_nothing_raised do - exploits = @api.browser_exploits() + exploits = @api.browser_exploits() end assert(exploits.length > 5) end @@ -99,17 +104,17 @@ class TC_Metasploit < Test::Unit::TestCase @api.login info = nil assert_nothing_raised do - info = @api.get_exploit_info('windows/dcerpc/ms03_026_dcom') + info = @api.get_exploit_info('windows/dcerpc/ms03_026_dcom') end assert( info['name'].nil? != true) end - + def test_get_options new_api @api.login info = nil assert_nothing_raised do - info = @api.get_options('windows/dcerpc/ms03_026_dcom') + info = @api.get_options('windows/dcerpc/ms03_026_dcom') end assert( info['RHOST'].nil? != true) end @@ -119,7 +124,7 @@ class TC_Metasploit < Test::Unit::TestCase @api.login payloads = nil assert_nothing_raised do - payloads = @api.payloads + payloads = @api.payloads end assert( payloads.length > 5 ) end @@ -130,7 +135,7 @@ class TC_Metasploit < Test::Unit::TestCase opts = { 'PAYLOAD' => 'windows/meterpreter/bind_tcp', 'URIPATH' => '/test1','SRVPORT' => 8080} ret = nil assert_nothing_raised do - ret = @api.launch_exploit('windows/browser/adobe_utilprintf',opts) + ret = @api.launch_exploit('windows/browser/adobe_utilprintf',opts) end assert(ret['job_id'] != nil ) end @@ -140,7 +145,7 @@ class TC_Metasploit < Test::Unit::TestCase @api.login ret = nil assert_nothing_raised do - ret = @api.launch_autopwn + ret = @api.launch_autopwn end assert(ret['job_id'] != nil ) end diff --git a/test/thirdparty/msf/unit/ts_metasploit.rb b/test/thirdparty/msf/unit/ts_metasploit.rb new file mode 100644 index 000000000..8e5754d71 --- /dev/null +++ b/test/thirdparty/msf/unit/ts_metasploit.rb @@ -0,0 +1,43 @@ +# +# Copyright 2012 Wade Alcorn wade@bindshell.net +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Common lib for BeEF tests +require '../../../common/ts_common' + +begin + require 'msfrpc-client' +rescue LoadError + puts "The following instruction failed: require 'msfrpc-client'" + puts "Please run: sudo gem install msfrpc-client" + exit +end + +require './check_environment' +require './tc_metasploit' + +class TS_BeefTests + def self.suite + + suite = Test::Unit::TestSuite.new(name="BeEF MSF TestSuite") + suite << TC_CheckEnvironment.suite + suite << TC_Metasploit.suite + + return suite + end +end + +Test::Unit::UI::Console::TestRunner.run(TS_BeefTests) +