Remove reliance on deprecated print_* methods
This commit is contained in:
+5
-4
@@ -13,14 +13,15 @@ module Msf
|
||||
include Msf::Ui::Console::CommandDispatcher
|
||||
|
||||
class CaptureJobListener
|
||||
def initialize(name, done_event)
|
||||
def initialize(name, done_event, dispatcher)
|
||||
@name = name
|
||||
@done_event = done_event
|
||||
@dispatcher = dispatcher
|
||||
end
|
||||
|
||||
def waiting(_id)
|
||||
self.succeeded = true
|
||||
print_good("#{@name} started")
|
||||
@dispatcher.print_good("#{@name} started")
|
||||
@done_event.set
|
||||
end
|
||||
|
||||
@@ -29,7 +30,7 @@ module Msf
|
||||
def completed(id, result, mod); end
|
||||
|
||||
def failed(_id, _error, _mod)
|
||||
print_error("#{@name} failed to start")
|
||||
@dispatcher.print_error("#{@name} failed to start")
|
||||
@done_event.set
|
||||
end
|
||||
|
||||
@@ -323,7 +324,7 @@ module Msf
|
||||
|
||||
modules_to_run.each do |svc, mod, opts|
|
||||
event = Rex::Sync::Event.new(false, false)
|
||||
job_listener = CaptureJobListener.new(mod.name, event)
|
||||
job_listener = CaptureJobListener.new(mod.name, event, self)
|
||||
|
||||
result = Msf::Simple::Auxiliary.run_simple(mod, opts, job_listener: job_listener)
|
||||
job_id = result[1]
|
||||
|
||||
@@ -31,3 +31,51 @@ RSpec.describe Msf::Plugin::Capture::ConsoleCommandDispatcher do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
RSpec.describe Msf::Plugin::Capture::ConsoleCommandDispatcher::CaptureJobListener do
|
||||
let(:dispatcher) do
|
||||
instance_double(
|
||||
Msf::Plugin::Capture::ConsoleCommandDispatcher,
|
||||
print_error: nil,
|
||||
print_good: nil
|
||||
)
|
||||
end
|
||||
let(:done_event) { instance_double(Rex::Sync::Event, set: nil) }
|
||||
let(:name) { 'my-little-module' }
|
||||
|
||||
subject { described_class.new(name, done_event, dispatcher) }
|
||||
|
||||
describe '#waiting' do
|
||||
it 'sets the `succeeded` flag' do
|
||||
subject.waiting('ignored')
|
||||
|
||||
expect(subject.succeeded).to eql true
|
||||
end
|
||||
|
||||
it 'outputs a message via the dispatcher' do
|
||||
expect(dispatcher).to receive(:print_good).with("#{name} started")
|
||||
|
||||
subject.waiting('ignored')
|
||||
end
|
||||
|
||||
it 'sets the done event' do
|
||||
expect(done_event).to receive(:set)
|
||||
|
||||
subject.waiting('ignored')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#failed' do
|
||||
it 'outputs a message via the dispatcher' do
|
||||
expect(dispatcher).to receive(:print_error).with("#{name} failed to start")
|
||||
|
||||
subject.failed('ignored', 'ignored', 'ignored')
|
||||
end
|
||||
|
||||
it 'sets the done event' do
|
||||
expect(done_event).to receive(:set)
|
||||
|
||||
subject.failed('ignored', 'ignored', 'ignored')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user