diff --git a/test/integration/tc_debug_modules.rb b/test/integration/tc_debug_modules.rb index c5c3db680..56ab4ba3f 100644 --- a/test/integration/tc_debug_modules.rb +++ b/test/integration/tc_debug_modules.rb @@ -18,8 +18,13 @@ class TC_DebugModules < Test::Unit::TestCase @@mod_debug_ascii_chars = nil @@mod_debug_test_network = nil + # NOTE: Tests within the same test class are called in the order they are defined. + # NOTE: However, test classes are run in alphabetical order by classname. + # That's why we use the prefix x_N_y, with N being the order of execution. + # + # Test RESTful API authentication with default credentials, returns the API token to be used later. - def test_restful_auth + def test_1_restful_auth response = RestClient.post "#{RESTAPI_ADMIN}/login", { 'username' => "#{BEEF_USER}", 'password' => "#{BEEF_PASSWD}"}.to_json, @@ -34,9 +39,9 @@ class TC_DebugModules < Test::Unit::TestCase end # Test RESTful API hooks handler hooking a victim browser, and then retrieving his BeEF session - def test_restful_hooks + def test_2_restful_hooks BeefTest.new_victim - sleep 2.0 + sleep 5.0 response = RestClient.get "#{RESTAPI_HOOKS}", {:params => {:token => @@token}} assert_equal 200, response.code assert_not_nil response.body @@ -46,7 +51,7 @@ class TC_DebugModules < Test::Unit::TestCase end # Test RESTful API modules handler, retrieving the IDs of the 3 debug modules currently in the framework - def test_restful_modules + def test_3_restful_modules response = RestClient.get "#{RESTAPI_MODULES}", {:params => {:token => @@token}} assert_equal 200, response.code assert_not_nil response.body @@ -65,8 +70,8 @@ class TC_DebugModules < Test::Unit::TestCase assert_not_nil @@mod_debug_ascii_chars assert_not_nil @@mod_debug_test_network end - - # Test debug module "Test_return_long_string" using the RESTful API + # + ## Test debug module "Test_return_long_string" using the RESTful API def test_return_long_string repeat_string = "BeEF" repeat_count = 20 @@ -83,17 +88,25 @@ class TC_DebugModules < Test::Unit::TestCase assert success cmd_id = result['command_id'] - sleep 3.0 - response = RestClient.get "#{RESTAPI_MODULES}/#{@@hb_session}/#{@@mod_debug_long_string}/#{cmd_id}", {:params => {:token => @@token}} + count = 0 + response = RestClient.get "#{RESTAPI_MODULES}/#{@@hb_session}/#{@@mod_debug_long_string}/#{cmd_id}?token=#{@@token}" + + #TODO if the response is empty, the body size is 2, basically an empty Hash. + # don't know why empty?, nil and other checks are not working. + while(response.body.size <= 2 && count < 10) + response = RestClient.get "#{RESTAPI_MODULES}/#{@@hb_session}/#{@@mod_debug_long_string}/#{cmd_id}?token=#{@@token}" + sleep 2 + count += 1 + end assert_equal 200, response.code assert_not_nil response.body result = JSON.parse(response.body) - data = JSON.parse(result["data"]) + data = JSON.parse(result['0']['data'])['data'] assert_not_nil data - assert_equal data["data"],(repeat_string * repeat_count) + assert_equal data,(repeat_string * repeat_count) end - - # Test debug module "Test_return_ascii_chars" using the RESTful API + # + ## Test debug module "Test_return_ascii_chars" using the RESTful API def test_return_ascii_chars response = RestClient.post "#{RESTAPI_MODULES}/#{@@hb_session}/#{@@mod_debug_ascii_chars}?token=#{@@token}", {}.to_json, # module does not expect any input @@ -104,18 +117,25 @@ class TC_DebugModules < Test::Unit::TestCase result = JSON.parse(response.body) success = result['success'] assert success - cmd_id = result['command_id'] - sleep 3.0 - response = RestClient.get "#{RESTAPI_MODULES}/#{@@hb_session}/#{@@mod_debug_ascii_chars}/#{cmd_id}", {:params => {:token => @@token}} + count = 0 + response = RestClient.get "#{RESTAPI_MODULES}/#{@@hb_session}/#{@@mod_debug_ascii_chars}/#{cmd_id}?token=#{@@token}" + + #TODO if the response is empty, the body size is 2, basically an empty Hash. + # don't know why empty?, nil and other checks are not working. + while(response.body.size <= 2 && count < 10) + response = RestClient.get "#{RESTAPI_MODULES}/#{@@hb_session}/#{@@mod_debug_ascii_chars}/#{cmd_id}?token=#{@@token}" + sleep 2 + count += 1 + end assert_equal 200, response.code assert_not_nil response.body result = JSON.parse(response.body) - data = JSON.parse(result["data"]) + data = JSON.parse(result['0']['data'])['data'] assert_not_nil data ascii_chars = "" (32..127).each do |i| ascii_chars << i.chr end - assert_equal ascii_chars,data["data"] + assert_equal ascii_chars,data end # Test debug module "Test_network_request" using the RESTful API @@ -134,16 +154,23 @@ class TC_DebugModules < Test::Unit::TestCase assert success cmd_id = result['command_id'] - sleep 3.0 - response = RestClient.get "#{RESTAPI_MODULES}/#{@@hb_session}/#{@@mod_debug_test_network}/#{cmd_id}", {:params => {:token => @@token}} + count = 0 + response = RestClient.get "#{RESTAPI_MODULES}/#{@@hb_session}/#{@@mod_debug_test_network}/#{cmd_id}?token=#{@@token}" + + #TODO if the response is empty, the body size is 2, basically an empty Hash. + # don't know why empty?, nil and other checks are not working. + while(response.body.size <= 2 && count < 10) + response = RestClient.get "#{RESTAPI_MODULES}/#{@@hb_session}/#{@@mod_debug_test_network}/#{cmd_id}?token=#{@@token}" + sleep 2 + count += 1 + end assert_equal 200, response.code assert_not_nil response.body result = JSON.parse(response.body) - data = JSON.parse(result["data"]) - res = JSON.parse(data["data"]) - assert_not_nil res - assert_equal 200, res["status_code"] - assert res["response_body"].include?("However you should still be capable of accessing it\n\t\tusing the Requester") + data = JSON.parse(result['0']['data'])['data'] + assert_not_nil data + assert_equal 200, JSON.parse(data)["status_code"] + assert JSON.parse(data)["response_body"].include?("However you should still be capable of accessing it\n\t\tusing the Requester") end end \ No newline at end of file diff --git a/test/integration/tc_login.rb b/test/integration/tc_login.rb index 698c2782e..008f0a3a9 100644 --- a/test/integration/tc_login.rb +++ b/test/integration/tc_login.rb @@ -63,7 +63,7 @@ class TC_login < Test::Unit::TestCase attacker = BeefTest.new_attacker victim = BeefTest.new_victim - sleep 2.0 + sleep 5.0 attacker.has_content?(VICTIM_DOMAIN) attacker.has_content?('127.0.0.1') diff --git a/test/integration/ts_integration.rb b/test/integration/ts_integration.rb index f82c130a0..c148a9c9d 100644 --- a/test/integration/ts_integration.rb +++ b/test/integration/ts_integration.rb @@ -22,8 +22,8 @@ class TS_BeefIntegrationTests suite = Test::Unit::TestSuite.new(name="BeEF Integration Test Suite") suite << TC_CheckEnvironment.suite - #suite << TC_DebugModules.suite suite << TC_login.suite + suite << TC_DebugModules.suite suite << TC_Jools.suite return suite