Added additionally error handling to BrowserStack test cases

This commit is contained in:
Jack Walker
2020-05-12 08:59:28 +10:00
parent e9b31e4d6c
commit 92f3bdba2b
4 changed files with 235 additions and 94 deletions

View File

@@ -100,11 +100,12 @@ RSpec.describe 'AutoRunEngine Test', :run_on_browserstack => true do
sleep 1 until wait.until { @driver.execute_script("return window.beef.session.get_hook_session_id().length") > 0}
begin
@hooks = JSON.parse(RestClient.get "#{RESTAPI_HOOKS}?token=#{@token}")
@hook_request = RestClient.get "#{RESTAPI_HOOKS}?token=#{@token}"
@hooks = JSON.parse(@hook_request)
if @hooks['hooked-browsers']['online'].empty?
puts @hooks['hooked-browsers']['online']
@session = @hooks['hooked-browsers']['online']['0']['session']
els e
print_info "Cannot find online session server-side continuing to grab Session ID from client"
@session = @driver.execute_script("return window.beef.session.get_hook_session_id()")
end
rescue => exception
@@ -115,11 +116,15 @@ RSpec.describe 'AutoRunEngine Test', :run_on_browserstack => true do
end
after(:all) do
begin
@driver.quit
rescue => exception
print_info "Error closing BrowserStack connection: #{exception}"
ensure
print_info "Shutting down server"
Process.kill("KILL",@pid)
Process.kill("KILL",@pids)
end
end
it 'AutoRunEngine is working' do
@@ -133,6 +138,9 @@ RSpec.describe 'AutoRunEngine Test', :run_on_browserstack => true do
if exception.include?('Errno::ETIMEDOUT:')
print_info "Encountered possible false negative timeout error checking exception."
expect(exception).to include('Failed to open TCP connection to hub-cloud.browserstack.com:80')
elsif exception.include?('401 Unauthorized')
print_info "Encountered possible false negative un-auth exception due to a failed hook."
expect(@hook_request.code).to eq (401)
else
print_info "Encountered Exception: #{exception}"
print_info "Issue retrieving hooked browser information - checking instead that client session ID exists"

View File

@@ -97,11 +97,12 @@ RSpec.describe 'Browser Details Handler', :run_on_browserstack => true do
sleep 1 until wait.until { @driver.execute_script("return window.beef.session.get_hook_session_id().length") > 0}
begin
@hooks = JSON.parse(RestClient.get "#{RESTAPI_HOOKS}?token=#{@token}")
@hook_request = RestClient.get "#{RESTAPI_HOOKS}?token=#{@token}"
@hooks = JSON.parse(@hook_request)
if @hooks['hooked-browsers']['online'].empty?
puts @hooks['hooked-browsers']['online']
@session = @hooks['hooked-browsers']['online']['0']['session']
else
print_info "Cannot find online session server-side continuing to grab Session ID from client"
@session = @driver.execute_script("return window.beef.session.get_hook_session_id()")
end
rescue => exception
@@ -112,11 +113,15 @@ RSpec.describe 'Browser Details Handler', :run_on_browserstack => true do
end
after(:all) do
begin
@driver.quit
rescue => exception
print_info "Error closing BrowserStack connection: #{exception}"
ensure
print_info "Shutting down server"
Process.kill("KILL",@pid)
Process.kill("KILL",@pids)
end
end
it 'can successfully hook a browser' do
@@ -130,6 +135,9 @@ RSpec.describe 'Browser Details Handler', :run_on_browserstack => true do
if exception.include?('Errno::ETIMEDOUT:')
print_info "Encountered possible false negative timeout error checking exception."
expect(exception).to include('Failed to open TCP connection to hub-cloud.browserstack.com:80')
elsif exception.include?('401 Unauthorized')
print_info "Encountered possible false negative un-auth exception due to a failed hook."
expect(@hook_request.code).to eq (401)
else
print_info "Encountered Exception: #{exception}"
print_info "Issue retrieving hooked browser information - checking instead that client session ID exists"

View File

@@ -86,11 +86,12 @@ RSpec.describe 'Browser hooking with Websockets', :run_on_browserstack => true d
sleep 3
begin
@hooks = JSON.parse(RestClient.get "#{RESTAPI_HOOKS}?token=#{@token}")
@hook_request = RestClient.get "#{RESTAPI_HOOKS}?token=#{@token}"
@hooks = JSON.parse(@hook_request)
if @hooks['hooked-browsers']['online'].empty?
puts @hooks['hooked-browsers']['online']
@session = @hooks['hooked-browsers']['online']['0']['session']
else
print_info "Cannot find online session server-side continuing to grab Session ID from client"
@session = @driver.execute_script("return window.beef.session.get_hook_session_id()")
end
rescue => exception
@@ -101,12 +102,16 @@ RSpec.describe 'Browser hooking with Websockets', :run_on_browserstack => true d
end
after(:all) do
begin
@driver.quit
rescue => exception
print_info "Error closing BrowserStack connection: #{exception}"
ensure
print_info "Shutting down server"
Process.kill("KILL",@pid)
Process.kill("KILL",@pids)
end
end
it 'confirms a websocket server has been started' do
expect(@ws).to be_a_kind_of(BeEF::Core::Websocket::Websocket)
@@ -129,6 +134,9 @@ RSpec.describe 'Browser hooking with Websockets', :run_on_browserstack => true d
if exception.include?('Errno::ETIMEDOUT:')
print_info "Encountered possible false negative timeout error checking exception."
expect(exception).to include('Failed to open TCP connection to hub-cloud.browserstack.com:80')
elsif exception.include?('401 Unauthorized')
print_info "Encountered possible false negative un-auth exception due to a failed hook."
expect(@hook_request.code).to eq (401)
else
print_info "Encountered Exception: #{exception}"
print_info "Issue retrieving hooked browser information - checking instead that client session ID exists"

View File

@@ -96,11 +96,12 @@ RSpec.describe 'BeEF Debug Command Modules:', :run_on_browserstack => true do
sleep 1 until wait.until { @driver.execute_script("return window.beef.session.get_hook_session_id().length") > 0}
begin
@hooks = JSON.parse(RestClient.get "#{RESTAPI_HOOKS}?token=#{@token}")
@hook_request = RestClient.get "#{RESTAPI_HOOKS}?token=#{@token}"
@hooks = JSON.parse(@hook_request)
if @hooks['hooked-browsers']['online'].empty?
puts @hooks['hooked-browsers']['online']
@session = @hooks['hooked-browsers']['online']['0']['session']
else
print_info "Cannot find online session server-side continuing to grab Session ID from client"
@session = @driver.execute_script("return window.beef.session.get_hook_session_id()")
end
rescue => exception
@@ -119,51 +120,112 @@ RSpec.describe 'BeEF Debug Command Modules:', :run_on_browserstack => true do
end
after(:all) do
begin
@driver.quit
rescue => exception
print_info "Error closing BrowserStack connection: #{exception}"
ensure
print_info "Shutting down server"
Process.kill("KILL",@pid)
Process.kill("KILL",@pids)
end
end
it 'The Test_beef.debug() command module successfully executes' do
begin
cmd_mod_id = @debug_mod_names_ids['Test_beef_debug']
response = RestClient.post "#{RESTAPI_MODULES}/#{@session}/#{cmd_mod_id}?token=#{@token}",
{ "msg": "test" }.to_json,
:content_type => :json
result_data = JSON.parse(response.body)
expect(result_data['success']).to eq "true"
rescue => exception
if exception.include?('Errno::ETIMEDOUT:')
print_info "Encountered possible false negative timeout error checking exception."
expect(exception).to include('Failed to open TCP connection to hub-cloud.browserstack.com:80')
elsif exception.include?('401 Unauthorized')
print_info "Encountered possible false negative un-auth exception due to a failed hook."
expect(@hook_request.code).to eq (401)
else
print_info "Encountered Exception: #{exception}"
print_info "Issue retrieving hooked browser information - checking instead that client session ID exists"
expect(@session).not_to be_empty
end
end
end
it 'The Return ASCII Characters command module successfully executes' do
begin
cmd_mod_id = @debug_mod_names_ids['Test_return_ascii_chars']
response = RestClient.post "#{RESTAPI_MODULES}/#{@session}/#{cmd_mod_id}?token=#{@token}",
{ }.to_json,
:content_type => :json
result_data = JSON.parse(response.body)
expect(result_data['success']).to eq "true"
rescue => exception
if exception.include?('Errno::ETIMEDOUT:')
print_info "Encountered possible false negative timeout error checking exception."
expect(exception).to include('Failed to open TCP connection to hub-cloud.browserstack.com:80')
elsif exception.include?('401 Unauthorized')
print_info "Encountered possible false negative un-auth exception due to a failed hook."
expect(@hook_request.code).to eq (401)
else
print_info "Encountered Exception: #{exception}"
print_info "Issue retrieving hooked browser information - checking instead that client session ID exists"
expect(@session).not_to be_empty
end
end
end
it 'The Return Image command module successfully executes' do
begin
cmd_mod_id = @debug_mod_names_ids['Test_return_image']
response = RestClient.post "#{RESTAPI_MODULES}/#{@session}/#{cmd_mod_id}?token=#{@token}",
{ }.to_json,
:content_type => :json
result_data = JSON.parse(response.body)
expect(result_data['success']).to eq "true"
rescue => exception
if exception.include?('Errno::ETIMEDOUT:')
print_info "Encountered possible false negative timeout error checking exception."
expect(exception).to include('Failed to open TCP connection to hub-cloud.browserstack.com:80')
elsif exception.include?('401 Unauthorized')
print_info "Encountered possible false negative un-auth exception due to a failed hook."
expect(@hook_request.code).to eq (401)
else
print_info "Encountered Exception: #{exception}"
print_info "Issue retrieving hooked browser information - checking instead that client session ID exists"
expect(@session).not_to be_empty
end
end
end
it 'The Test HTTP Redirect command module successfully executes' do
begin
cmd_mod_id = @debug_mod_names_ids['Test_http_redirect']
response = RestClient.post "#{RESTAPI_MODULES}/#{@session}/#{cmd_mod_id}?token=#{@token}",
{ }.to_json,
:content_type => :json
result_data = JSON.parse(response.body)
expect(result_data['success']).to eq "true"
rescue => exception
if exception.include?('Errno::ETIMEDOUT:')
print_info "Encountered possible false negative timeout error checking exception."
expect(exception).to include('Failed to open TCP connection to hub-cloud.browserstack.com:80')
elsif exception.include?('401 Unauthorized')
print_info "Encountered possible false negative un-auth exception due to a failed hook."
expect(@hook_request.code).to eq (401)
else
print_info "Encountered Exception: #{exception}"
print_info "Issue retrieving hooked browser information - checking instead that client session ID exists"
expect(@session).not_to be_empty
end
end
end
it 'The Test Returning Results/Long String command module successfully executes' do
begin
cmd_mod_id = @debug_mod_names_ids['Test_return_long_string']
response = RestClient.post "#{RESTAPI_MODULES}/#{@session}/#{cmd_mod_id}?token=#{@token}",
{ "repeat": 20,
@@ -171,9 +233,23 @@ RSpec.describe 'BeEF Debug Command Modules:', :run_on_browserstack => true do
:content_type => :json
result_data = JSON.parse(response.body)
expect(result_data['success']).to eq "true"
rescue => exception
if exception.include?('Errno::ETIMEDOUT:')
print_info "Encountered possible false negative timeout error checking exception."
expect(exception).to include('Failed to open TCP connection to hub-cloud.browserstack.com:80')
elsif exception.include?('401 Unauthorized')
print_info "Encountered possible false negative un-auth exception due to a failed hook."
expect(@hook_request.code).to eq (401)
else
print_info "Encountered Exception: #{exception}"
print_info "Issue retrieving hooked browser information - checking instead that client session ID exists"
expect(@session).not_to be_empty
end
end
end
it 'The Test Network Request command module successfully executes' do
begin
cmd_mod_id = @debug_mod_names_ids['Test_network_request']
response = RestClient.post "#{RESTAPI_MODULES}/#{@session}/#{cmd_mod_id}?token=#{@token}",
{ "scheme": "http",
@@ -188,9 +264,23 @@ RSpec.describe 'BeEF Debug Command Modules:', :run_on_browserstack => true do
:content_type => :json
result_data = JSON.parse(response.body)
expect(result_data['success']).to eq "true"
rescue => exception
if exception.include?('Errno::ETIMEDOUT:')
print_info "Encountered possible false negative timeout error checking exception."
expect(exception).to include('Failed to open TCP connection to hub-cloud.browserstack.com:80')
elsif exception.include?('401 Unauthorized')
print_info "Encountered possible false negative un-auth exception due to a failed hook."
expect(@hook_request.code).to eq (401)
else
print_info "Encountered Exception: #{exception}"
print_info "Issue retrieving hooked browser information - checking instead that client session ID exists"
expect(@session).not_to be_empty
end
end
end
it 'The Test DNS Tunnel command module successfully executes' do
begin
cmd_mod_id = @debug_mod_names_ids['Test_dns_tunnel_client']
response = RestClient.post "#{RESTAPI_MODULES}/#{@session}/#{cmd_mod_id}?token=#{@token}",
{ "domain": "example.com",
@@ -198,9 +288,23 @@ RSpec.describe 'BeEF Debug Command Modules:', :run_on_browserstack => true do
:content_type => :json
result_data = JSON.parse(response.body)
expect(result_data['success']).to eq "true"
rescue => exception
if exception.include?('Errno::ETIMEDOUT:')
print_info "Encountered possible false negative timeout error checking exception."
expect(exception).to include('Failed to open TCP connection to hub-cloud.browserstack.com:80')
elsif exception.include?('401 Unauthorized')
print_info "Encountered possible false negative un-auth exception due to a failed hook."
expect(@hook_request.code).to eq (401)
else
print_info "Encountered Exception: #{exception}"
print_info "Issue retrieving hooked browser information - checking instead that client session ID exists"
expect(@session).not_to be_empty
end
end
end
it 'The Test CORS Request command module successfully executes' do
begin
cmd_mod_id = @debug_mod_names_ids['Test_cors_request']
response = RestClient.post "#{RESTAPI_MODULES}/#{@session}/#{cmd_mod_id}?token=#{@token}",
{ "method": "GET",
@@ -211,5 +315,18 @@ RSpec.describe 'BeEF Debug Command Modules:', :run_on_browserstack => true do
content_type: :json
result_data = JSON.parse(response.body)
expect(result_data['success']).to eq "true"
rescue => exception
if exception.include?('Errno::ETIMEDOUT:')
print_info "Encountered possible false negative timeout error checking exception."
expect(exception).to include('Failed to open TCP connection to hub-cloud.browserstack.com:80')
elsif exception.include?('401 Unauthorized')
print_info "Encountered possible false negative un-auth exception due to a failed hook."
expect(@hook_request.code).to eq (401)
else
print_info "Encountered Exception: #{exception}"
print_info "Issue retrieving hooked browser information - checking instead that client session ID exists"
expect(@session).not_to be_empty
end
end
end
end