2015-10-20 09:54:02 -05:00
|
|
|
RSpec.shared_context 'Msf::UIDriver' do
|
2013-09-30 13:47:53 -05:00
|
|
|
let(:driver) do
|
2021-06-25 11:46:44 +01:00
|
|
|
instance = double('Driver', framework: framework)
|
|
|
|
|
allow(instance).to receive(:on_command_proc=).with(kind_of(Proc))
|
|
|
|
|
capture_logging(instance)
|
|
|
|
|
instance
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
let(:driver_input) do
|
|
|
|
|
double(Rex::Ui::Text::Input)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
let(:driver_output) do
|
|
|
|
|
instance = double(
|
|
|
|
|
Rex::Ui::Text::Output,
|
2024-01-30 17:51:40 +00:00
|
|
|
prompting?: false,
|
|
|
|
|
prompting: false
|
2021-06-25 11:46:44 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
capture_logging(instance)
|
|
|
|
|
instance
|
|
|
|
|
end
|
|
|
|
|
|
2023-01-12 14:07:42 +00:00
|
|
|
def reset_logging!
|
|
|
|
|
@output = []
|
|
|
|
|
@error = []
|
|
|
|
|
@combined_output = []
|
|
|
|
|
end
|
|
|
|
|
|
2021-06-25 11:46:44 +01:00
|
|
|
def capture_logging(target)
|
2021-09-17 16:08:32 +01:00
|
|
|
append_output = proc do |string = ''|
|
2021-06-25 11:46:44 +01:00
|
|
|
lines = string.split("\n")
|
|
|
|
|
@output ||= []
|
|
|
|
|
@output.concat(lines)
|
|
|
|
|
@combined_output ||= []
|
|
|
|
|
@combined_output.concat(lines)
|
|
|
|
|
end
|
2021-09-17 16:08:32 +01:00
|
|
|
append_error = proc do |string = ''|
|
2021-06-25 11:46:44 +01:00
|
|
|
lines = string.split("\n")
|
|
|
|
|
@error ||= []
|
|
|
|
|
@error.concat(lines)
|
|
|
|
|
@combined_output ||= []
|
|
|
|
|
@combined_output.concat(lines)
|
|
|
|
|
end
|
|
|
|
|
|
2021-09-17 16:08:32 +01:00
|
|
|
allow(target).to receive(:print, &append_output)
|
|
|
|
|
allow(target).to receive(:print_line, &append_output)
|
|
|
|
|
allow(target).to receive(:print_status, &append_output)
|
|
|
|
|
allow(target).to receive(:print_good, &append_output)
|
|
|
|
|
|
|
|
|
|
allow(target).to receive(:print_warning, &append_error)
|
|
|
|
|
allow(target).to receive(:print_error, &append_error)
|
|
|
|
|
allow(target).to receive(:print_bad, &append_error)
|
2013-09-30 13:47:53 -05:00
|
|
|
end
|
2013-07-22 16:26:45 -05:00
|
|
|
end
|