Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spec/lib/msf/core/modules/loader/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ class MetasploitModule < Msf::Auxiliary
allow(module_manager).to receive(:on_module_load)

# if the module eval error includes the module_path then the module_path was passed along correctly
expect(subject).to receive(:elog).with(/#{Regexp.escape(module_path)}/)
expect(subject).to receive(:elog).with(/#{Regexp.escape(module_path)}/, error: an_instance_of(NoMethodError))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error is from the malformed module content intentionally having a mistake:

        # purposeful typo to check that module path is used in backtrace
        inclde Exploit::Remote::Tcp

Which results in a NoMethodError being raised

expect(subject.load_module(parent_path, type, module_reference_name, :reload => true)).to be_falsey
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def initialize(info = {})
RUBY
end

it 'registers an offense when there is additional whitespace', focus: true do
it 'registers an offense when there is additional whitespace' do
expect_offense(<<~RUBY)
class DummyModule
def initialize(info = {})
Expand Down
8 changes: 6 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@
# to individual examples or groups you care about by tagging them with
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
# get run.
config.filter_run :focus
config.run_all_when_everything_filtered = true
if ENV['CI']
config.before(:example, :focus) { raise "Should not commit focused specs" }
else
config.filter_run focus: true
config.run_all_when_everything_filtered = true
end

# allow more verbose output when running an individual spec file.
if config.files_to_run.one?
Expand Down
21 changes: 7 additions & 14 deletions spec/support/shared/examples/msf/db_manager/migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,35 +52,28 @@ def migrate
end

context 'with StandardError from ActiveRecord::Migration.migrate' do
let(:error) do
let(:standard_error) do
StandardError.new(message)
end

let(:message) do
"Error during migration"
"DB.migrate threw an exception"
Comment thread
jmartin-tech marked this conversation as resolved.
end

before(:example) do
expect(ActiveRecord::Migrator).to receive(:migrate).and_raise(error)
expect(ActiveRecord::Migrator).to receive(:migrate).and_raise(standard_error)
end

it 'should set Msf::DBManager#error' do
migrate

expect(db_manager.error).to eq error
expect(db_manager.error).to eq standard_error
end

it 'should log error message at error level' do
expect(db_manager).to receive(:elog) do |error_message|
expect(error_message).to include(error.to_s)
end

migrate
end

it 'should log error backtrace at debug level' do
expect(db_manager).to receive(:dlog) do |debug_message|
expect(debug_message).to include('Call stack')
expect(db_manager).to receive(:elog) do |error_message, error:|
expect(error_message).to include(standard_error.to_s)
expect(error).to eql(standard_error)
end
Comment thread
jmartin-tech marked this conversation as resolved.

migrate
Expand Down