diff --git a/spec/beef/extensions/requester_spec.rb b/spec/beef/extensions/requester_spec.rb index 189695ade..9025fc327 100644 --- a/spec/beef/extensions/requester_spec.rb +++ b/spec/beef/extensions/requester_spec.rb @@ -117,12 +117,10 @@ RSpec.describe 'BeEF Extension Requester' do https.where(:hooked_browser_id => hb_session).delete_all # kill the server - Process.kill("KILL",@pid) - Process.kill("KILL",@pids) + Process.kill('KILL', @pid) + Process.kill('KILL', @pids) puts "waiting for server to die.." sleep 1 - end - end diff --git a/spec/beef/extensions/webrtc_spec.rb b/spec/beef/extensions/webrtc_spec.rb index 987603b70..610863825 100644 --- a/spec/beef/extensions/webrtc_spec.rb +++ b/spec/beef/extensions/webrtc_spec.rb @@ -1,7 +1,6 @@ require 'rest-client' RSpec.describe 'BeEF Extension WebRTC' do - before(:all) do @config = BeEF::Core::Configuration.instance @config.load_extensions_config diff --git a/spec/beef/extensions/xssrays_spec.rb b/spec/beef/extensions/xssrays_spec.rb index f7953f411..114bc7339 100644 --- a/spec/beef/extensions/xssrays_spec.rb +++ b/spec/beef/extensions/xssrays_spec.rb @@ -1,7 +1,6 @@ require 'extensions/xssrays/extension' RSpec.describe 'BeEF Extension XSSRays' do - before(:all) do @config = BeEF::Core::Configuration.instance @config.load_extensions_config diff --git a/spec/beef/filesystem_checks_spec.rb b/spec/beef/filesystem_checks_spec.rb index a3630cc8e..75248bea7 100644 --- a/spec/beef/filesystem_checks_spec.rb +++ b/spec/beef/filesystem_checks_spec.rb @@ -1,5 +1,4 @@ RSpec.describe 'BeEF Filesystem' do - def file_test(file) expect(File.file?(file)).to be(true) expect(File.zero?(file)).to be(false) @@ -26,5 +25,4 @@ RSpec.describe 'BeEF Filesystem' do expect(File.executable?(d)).to be(true) end end - end diff --git a/spec/beef/security_checks_spec.rb b/spec/beef/security_checks_spec.rb index 3dfb487ef..9f8bf0cce 100644 --- a/spec/beef/security_checks_spec.rb +++ b/spec/beef/security_checks_spec.rb @@ -1,17 +1,15 @@ RSpec.describe 'BeEF Security Checks' do - it 'dangerous eval usage' do Dir['**/*.rb'].each do |path| File.open(path) do |f| next if /#{File.basename(__FILE__)}/.match(path) # skip this file - next if /\/msf-test\//.match(path) # skip this file - next if /extensions\/dns/.match(path) # skip this file + next if %r{/msf-test/}.match(path) # skip this file + next if %r{extensions/dns}.match(path) # skip this file f.grep(/\Weval\W/im) do |line| - fail "Illegal use of 'eval' found in\n Path: #{path}\nLine: #{line}" + raise "Illegal use of 'eval' found in\n Path: #{path}\nLine: #{line}" end end end end - end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 78d161393..ac2c2aa4d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,12 +1,10 @@ require 'core/loader.rb' -# Notes -# We need to load vairables that 'beef' usually does for us -## config +# @note We need to load variables that 'beef' usually does for us + +# @todo review this config (this isn't used or is shadowed by the monkey patching, needs a further look to fix properly) config = BeEF::Core::Configuration.new('config.yaml') -## home_dir $home_dir = Dir.pwd -## root_dir $root_dir = Dir.pwd require 'core/bootstrap.rb' @@ -31,9 +29,7 @@ ARGV = [] # Monkey patch to avoid reset sessions class Capybara::Selenium::Driver < Capybara::Driver::Base def reset! - if @browser - @browser.navigate.to('about:blank') - end + @browser.navigate.to('about:blank') if @browser end end @@ -47,17 +43,16 @@ CONFIG['key'] = ENV['BROWSERSTACK_ACCESS_KEY'] || '' ## DB config ActiveRecord::Base.logger = nil OTR::ActiveRecord.migrations_paths = [File.join('core', 'main', 'ar-migrations')] -OTR::ActiveRecord.configure_from_hash!(adapter:'sqlite3', database:':memory:') -# otr-activerecord require you to manually establish the connection with the following line -#Also a check to confirm that the correct Gem version is installed to require it, likely easier for old systems. +OTR::ActiveRecord.configure_from_hash!(adapter: 'sqlite3', database: ':memory:') + +# otr-activerecord requires manually establishing the connection with the following line +# Also a check to confirm that the correct Gem version is installed to require it, likely easier for old systems. if Gem.loaded_specs['otr-activerecord'].version > Gem::Version.create('1.4.2') OTR::ActiveRecord.establish_connection! end ActiveRecord::Schema.verbose = false context = ActiveRecord::Migration.new.migration_context -if context.needs_migration? - ActiveRecord::Migrator.new(:up, context.migrations, context.schema_migration).migrate -end +ActiveRecord::Migrator.new(:up, context.migrations, context.schema_migration).migrate if context.needs_migration? RSpec.configure do |config| config.disable_monkey_patching! @@ -76,18 +71,16 @@ RSpec.configure do |config| end def server_teardown(webdriver, server_pid, server_pids) - begin - webdriver.quit - rescue => exception - print_info "Exception: #{exception}" - print_info "Exception Class: #{exception.class}" - print_info "Exception Message: #{exception.message}" - print_info "Exception Stack Trace: #{exception.backtrace}" - exit 0 - ensure - print_info "Shutting down server" - Process.kill("KILL", server_pid) - Process.kill("KILL", server_pids) - end + webdriver.quit + rescue StandardError => e + print_info "Exception: #{e}" + print_info "Exception Class: #{e.class}" + print_info "Exception Message: #{e.message}" + print_info "Exception Stack Trace: #{e.backtrace}" + exit 0 + ensure + print_info 'Shutting down server' + Process.kill('KILL', server_pid) + Process.kill('KILL', server_pids) end end diff --git a/spec/support/simple_rest_client.rb b/spec/support/simple_rest_client.rb index 9d8eff8dd..ef51a584c 100644 --- a/spec/support/simple_rest_client.rb +++ b/spec/support/simple_rest_client.rb @@ -17,20 +17,17 @@ class BeefRestClient end def auth - begin - response = RestClient.post "#{@url}admin/login", - { 'username': "#{@user}", - 'password': "#{@pass}" }.to_json, - content_type: :json, - accept: :json - result = JSON.parse(response.body) - @token = result['token'] - { success: result['success'], payload: result, token: @token } - rescue => e - { success: false, payload: e.message } - end + response = RestClient.post "#{@url}admin/login", + { 'username': "#{@user}", + 'password': "#{@pass}" }.to_json, + content_type: :json, + accept: :json + result = JSON.parse(response.body) + @token = result['token'] + { success: result['success'], payload: result, token: @token } + rescue StandardError => e + { success: false, payload: e.message } end - def version return { success: false, payload: 'no token' } if @token.nil? @@ -39,7 +36,7 @@ class BeefRestClient result = JSON.parse(response.body) { success: result['success'], payload: result } - rescue => e + rescue StandardError => e print_error "Could not retrieve BeEF version: #{e.message}" { success: false, payload: e.message } end