spec: Fix some rubocop violations (#2011)

This commit is contained in:
jcrew99
2022-01-23 22:49:44 +10:00
committed by GitHub
parent 01c3413687
commit 29e025bbfc
7 changed files with 36 additions and 54 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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