Added additionally error handling to BrowserStack test cases
This commit is contained in:
@@ -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']
|
||||
else
|
||||
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
|
||||
@driver.quit
|
||||
|
||||
print_info "Shutting down server"
|
||||
Process.kill("KILL",@pid)
|
||||
Process.kill("KILL",@pids)
|
||||
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"
|
||||
|
||||
@@ -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
|
||||
@driver.quit
|
||||
|
||||
print_info "Shutting down server"
|
||||
Process.kill("KILL",@pid)
|
||||
Process.kill("KILL",@pids)
|
||||
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"
|
||||
|
||||
@@ -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
|
||||
@@ -100,12 +101,16 @@ RSpec.describe 'Browser hooking with Websockets', :run_on_browserstack => true d
|
||||
end
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
@driver.quit
|
||||
|
||||
print_info "Shutting down server"
|
||||
Process.kill("KILL",@pid)
|
||||
Process.kill("KILL",@pids)
|
||||
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
|
||||
@@ -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"
|
||||
|
||||
@@ -96,12 +96,13 @@ 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']
|
||||
@session = @hooks['hooked-browsers']['online']['0']['session']
|
||||
else
|
||||
@session = @driver.execute_script("return window.beef.session.get_hook_session_id()")
|
||||
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
|
||||
print_info "Encountered Exception: #{exception}"
|
||||
@@ -119,97 +120,213 @@ RSpec.describe 'BeEF Debug Command Modules:', :run_on_browserstack => true do
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
@driver.quit
|
||||
|
||||
print_info "Shutting down server"
|
||||
Process.kill("KILL",@pid)
|
||||
Process.kill("KILL",@pids)
|
||||
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
|
||||
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"
|
||||
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
|
||||
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"
|
||||
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
|
||||
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"
|
||||
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
|
||||
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"
|
||||
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
|
||||
cmd_mod_id = @debug_mod_names_ids['Test_return_long_string']
|
||||
response = RestClient.post "#{RESTAPI_MODULES}/#{@session}/#{cmd_mod_id}?token=#{@token}",
|
||||
{ "repeat": 20,
|
||||
"repeat_string": "beef" }.to_json,
|
||||
:content_type => :json
|
||||
result_data = JSON.parse(response.body)
|
||||
expect(result_data['success']).to eq "true"
|
||||
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,
|
||||
"repeat_string": "beef" }.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 Network Request command module successfully executes' do
|
||||
cmd_mod_id = @debug_mod_names_ids['Test_network_request']
|
||||
response = RestClient.post "#{RESTAPI_MODULES}/#{@session}/#{cmd_mod_id}?token=#{@token}",
|
||||
{ "scheme": "http",
|
||||
"method": "GET",
|
||||
"domain": "#{ATTACK_DOMAIN}",
|
||||
"port": "#{@config.get('beef.http.port')}",
|
||||
"path": "/hook.js",
|
||||
"anchor": "anchor",
|
||||
"data": "query=testquerydata",
|
||||
"timeout": "10",
|
||||
"dataType": "script" }.to_json,
|
||||
:content_type => :json
|
||||
result_data = JSON.parse(response.body)
|
||||
expect(result_data['success']).to eq "true"
|
||||
begin
|
||||
cmd_mod_id = @debug_mod_names_ids['Test_network_request']
|
||||
response = RestClient.post "#{RESTAPI_MODULES}/#{@session}/#{cmd_mod_id}?token=#{@token}",
|
||||
{ "scheme": "http",
|
||||
"method": "GET",
|
||||
"domain": "#{ATTACK_DOMAIN}",
|
||||
"port": "#{@config.get('beef.http.port')}",
|
||||
"path": "/hook.js",
|
||||
"anchor": "anchor",
|
||||
"data": "query=testquerydata",
|
||||
"timeout": "10",
|
||||
"dataType": "script" }.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 DNS Tunnel command module successfully executes' do
|
||||
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",
|
||||
"data": "Lorem ipsum" }.to_json,
|
||||
:content_type => :json
|
||||
result_data = JSON.parse(response.body)
|
||||
expect(result_data['success']).to eq "true"
|
||||
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",
|
||||
"data": "Lorem ipsum" }.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 CORS Request command module successfully executes' do
|
||||
cmd_mod_id = @debug_mod_names_ids['Test_cors_request']
|
||||
response = RestClient.post "#{RESTAPI_MODULES}/#{@session}/#{cmd_mod_id}?token=#{@token}",
|
||||
{ "method": "GET",
|
||||
"url": "example.com",
|
||||
"data": {
|
||||
"test": "data"
|
||||
}}.to_json,
|
||||
content_type: :json
|
||||
result_data = JSON.parse(response.body)
|
||||
expect(result_data['success']).to eq "true"
|
||||
begin
|
||||
cmd_mod_id = @debug_mod_names_ids['Test_cors_request']
|
||||
response = RestClient.post "#{RESTAPI_MODULES}/#{@session}/#{cmd_mod_id}?token=#{@token}",
|
||||
{ "method": "GET",
|
||||
"url": "example.com",
|
||||
"data": {
|
||||
"test": "data"
|
||||
}}.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
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user