From 31a19692f8932a0c4a93433862ba84db64a653ea Mon Sep 17 00:00:00 2001 From: Jack Walker Date: Fri, 15 May 2020 09:03:26 +1000 Subject: [PATCH] Moved TIMEOUT error handling to teardown. --- .../autorun_engine/autorun_engine_spec.rb | 12 +++-- .../handlers/browser_details_handler_spec.rb | 12 +++-- .../websocket_hooked_browser_spec.rb | 12 +++-- .../modules/debug/test_beef_debugs_spec.rb | 53 ++++++------------- 4 files changed, 38 insertions(+), 51 deletions(-) diff --git a/spec/beef/core/main/autorun_engine/autorun_engine_spec.rb b/spec/beef/core/main/autorun_engine/autorun_engine_spec.rb index da2672add..67664b3ca 100644 --- a/spec/beef/core/main/autorun_engine/autorun_engine_spec.rb +++ b/spec/beef/core/main/autorun_engine/autorun_engine_spec.rb @@ -120,7 +120,12 @@ RSpec.describe 'AutoRunEngine Test', :run_on_browserstack => true do begin @driver.quit rescue => exception - print_info "Error closing BrowserStack connection: #{exception}" + if exception.include?('Failed to open TCP connection') + print_info "Encountered possible false negative timeout error checking exception." + expect(exception).to include('hub-cloud.browserstack.com:80') + else + print_info "Error closing BrowserStack connection: #{exception}" + end ensure print_info "Shutting down server" Process.kill("KILL",@pid) @@ -136,10 +141,7 @@ RSpec.describe 'AutoRunEngine Test', :run_on_browserstack => true do expect(@hooks['hooked-browsers']['online']).not_to be_empty end rescue => exception - if exception.include?('Failed to open TCP connection') - print_info "Encountered possible false negative timeout error. Checking exception." - expect(exception).to include('hub-cloud.browserstack.com:80') - elsif exception.include?('401 Unauthorized') + if 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 diff --git a/spec/beef/core/main/handlers/browser_details_handler_spec.rb b/spec/beef/core/main/handlers/browser_details_handler_spec.rb index f6ce82fca..a0099c143 100644 --- a/spec/beef/core/main/handlers/browser_details_handler_spec.rb +++ b/spec/beef/core/main/handlers/browser_details_handler_spec.rb @@ -117,7 +117,12 @@ RSpec.describe 'Browser Details Handler', :run_on_browserstack => true do begin @driver.quit rescue => exception - print_info "Error closing BrowserStack connection: #{exception}" + if exception.include?('Failed to open TCP connection') + print_info "Encountered possible false negative timeout error checking exception." + expect(exception).to include('hub-cloud.browserstack.com:80') + else + print_info "Error closing BrowserStack connection: #{exception}" + end ensure print_info "Shutting down server" Process.kill("KILL",@pid) @@ -133,10 +138,7 @@ RSpec.describe 'Browser Details Handler', :run_on_browserstack => true do expect(@hooks['hooked-browsers']['online']).not_to be_empty end rescue => exception - if exception.include?('Failed to open TCP connection') - print_info "Encountered possible false negative timeout error checking exception." - expect(exception).to include('hub-cloud.browserstack.com:80') - elsif exception.include?('401 Unauthorized') + if 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 diff --git a/spec/beef/extensions/websocket_hooked_browser_spec.rb b/spec/beef/extensions/websocket_hooked_browser_spec.rb index 58a7ce33f..2b4cfca8f 100644 --- a/spec/beef/extensions/websocket_hooked_browser_spec.rb +++ b/spec/beef/extensions/websocket_hooked_browser_spec.rb @@ -106,7 +106,12 @@ RSpec.describe 'Browser hooking with Websockets', :run_on_browserstack => true d begin @driver.quit rescue => exception - print_info "Error closing BrowserStack connection: #{exception}" + if exception.include?('Failed to open TCP connection') + print_info "Encountered possible false negative timeout error checking exception." + expect(exception).to include('hub-cloud.browserstack.com:80') + else + print_info "Error closing BrowserStack connection: #{exception}" + end ensure print_info "Shutting down server" Process.kill("KILL",@pid) @@ -132,10 +137,7 @@ RSpec.describe 'Browser hooking with Websockets', :run_on_browserstack => true d expect(@hooks['hooked-browsers']['online']).not_to be_empty end rescue => exception - if exception.include?('Failed to open TCP connection') - print_info "Encountered possible false negative BrowserStack timeout error. Checking exception." - expect(exception).to include('hub-cloud.browserstack.com:80') - elsif exception.include?('401 Unauthorized') + if 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 diff --git a/spec/beef/modules/debug/test_beef_debugs_spec.rb b/spec/beef/modules/debug/test_beef_debugs_spec.rb index 90da8d0d6..15353d353 100644 --- a/spec/beef/modules/debug/test_beef_debugs_spec.rb +++ b/spec/beef/modules/debug/test_beef_debugs_spec.rb @@ -18,8 +18,8 @@ RSpec.describe 'BeEF Debug Command Modules:', :run_on_browserstack => true do # Load BeEF extensions and modules # Always load Extensions, as previous changes to the config from other tests may affect - # whether or not this test passes. - print_info "Loading in BeEF::Extensions" + # whether or not this test passes. + print_info "Loading in BeEF::Extensions" BeEF::Extensions.load sleep 2 @@ -124,7 +124,12 @@ RSpec.describe 'BeEF Debug Command Modules:', :run_on_browserstack => true do begin @driver.quit rescue => exception - print_info "Error closing BrowserStack connection: #{exception}" + if exception.include?('Failed to open TCP connection') + print_info "Encountered possible false negative timeout error checking exception." + expect(exception).to include('hub-cloud.browserstack.com:80') + else + print_info "Error closing BrowserStack connection: #{exception}" + end ensure print_info "Shutting down server" Process.kill("KILL",@pid) @@ -141,10 +146,7 @@ RSpec.describe 'BeEF Debug Command Modules:', :run_on_browserstack => true do result_data = JSON.parse(response.body) expect(result_data['success']).to eq "true" rescue => exception - if exception.include?('Failed to open TCP connection') - print_info "Encountered possible false negative timeout error checking exception." - expect(exception).to include('hub-cloud.browserstack.com:80') - elsif exception.include?('401 Unauthorized') + if 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 @@ -164,10 +166,7 @@ RSpec.describe 'BeEF Debug Command Modules:', :run_on_browserstack => true do result_data = JSON.parse(response.body) expect(result_data['success']).to eq "true" rescue => exception - if exception.include?('Failed to open TCP connection') - print_info "Encountered possible false negative timeout error checking exception." - expect(exception).to include('hub-cloud.browserstack.com:80') - elsif exception.include?('401 Unauthorized') + if 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 @@ -187,15 +186,12 @@ RSpec.describe 'BeEF Debug Command Modules:', :run_on_browserstack => true do result_data = JSON.parse(response.body) expect(result_data['success']).to eq "true" rescue => exception - if exception.include?('Failed to open TCP connection') - print_info "Encountered possible false negative timeout error checking exception." - expect(exception).to include('hub-cloud.browserstack.com:80') - elsif exception.include?('401 Unauthorized') + if 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" + print_info 'Issue retrieving hooked browser information - checking instead that client session ID exists' expect(@session).not_to be_empty end end @@ -211,10 +207,7 @@ RSpec.describe 'BeEF Debug Command Modules:', :run_on_browserstack => true do result_data = JSON.parse(response.body) expect(result_data['success']).to eq "true" rescue => exception - if exception.include?('Failed to open TCP connection') - print_info "Encountered possible false negative timeout error checking exception." - expect(exception).to include('hub-cloud.browserstack.com:80') - elsif exception.include?('401 Unauthorized') + if 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 @@ -235,10 +228,7 @@ RSpec.describe 'BeEF Debug Command Modules:', :run_on_browserstack => true do result_data = JSON.parse(response.body) expect(result_data['success']).to eq "true" rescue => exception - if exception.include?('Failed to open TCP connection') - print_info "Encountered possible false negative timeout error checking exception." - expect(exception).to include('hub-cloud.browserstack.com:80') - elsif exception.include?('401 Unauthorized') + if 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 @@ -266,10 +256,7 @@ RSpec.describe 'BeEF Debug Command Modules:', :run_on_browserstack => true do result_data = JSON.parse(response.body) expect(result_data['success']).to eq "true" rescue => exception - if exception.include?('Failed to open TCP connection') - print_info "Encountered possible false negative timeout error checking exception." - expect(exception).to include('hub-cloud.browserstack.com:80') - elsif exception.include?('401 Unauthorized') + if 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 @@ -290,10 +277,7 @@ RSpec.describe 'BeEF Debug Command Modules:', :run_on_browserstack => true do result_data = JSON.parse(response.body) expect(result_data['success']).to eq "true" rescue => exception - if exception.include?('Failed to open TCP connection') - print_info "Encountered possible false negative timeout error checking exception." - expect(exception).to include('hub-cloud.browserstack.com:80') - elsif exception.include?('401 Unauthorized') + if 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 @@ -317,10 +301,7 @@ RSpec.describe 'BeEF Debug Command Modules:', :run_on_browserstack => true do result_data = JSON.parse(response.body) expect(result_data['success']).to eq "true" rescue => exception - if exception.include?('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') + if 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