CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/spec/plugins/capture_spec.rb
Views: 1904
1
require 'spec_helper'
2
require Metasploit::Framework.root.join('plugins/capture.rb').to_path
3
4
RSpec.describe Msf::Plugin::Capture::ConsoleCommandDispatcher do
5
include_context 'Msf::UIDriver'
6
7
let(:framework) { instance_double(Msf::Framework) }
8
9
describe '#cmd_captureg' do
10
subject { described_class.new(driver) }
11
12
context 'when called without args' do
13
it 'returns generic help text' do
14
expect(subject.cmd_captureg).to eql subject.help
15
end
16
end
17
18
context 'when there is a single arg matching the HELP regex' do
19
it 'returns generic help text' do
20
expect(subject.cmd_captureg('--help')).to eql subject.help
21
end
22
end
23
24
context 'when there are two args with first one matching the HELP regex' do
25
it 'calls `help` with second arg' do
26
expect(subject.cmd_captureg('--help', 'start')).to eql subject.help('start')
27
end
28
end
29
end
30
end
31
32
RSpec.describe Msf::Plugin::Capture::ConsoleCommandDispatcher::CaptureJobListener do
33
include_context 'Msf::UIDriver'
34
let(:dispatcher) { instance_double(Msf::Plugin::Capture::ConsoleCommandDispatcher) }
35
let(:done_event) { instance_double(Rex::Sync::Event, set: nil) }
36
let(:name) { 'my-little-module' }
37
38
subject { described_class.new(name, done_event, dispatcher) }
39
40
before(:each) do
41
capture_logging(dispatcher)
42
end
43
44
describe '#waiting' do
45
it 'sets the `succeeded` flag' do
46
subject.waiting('ignored')
47
48
expect(subject.succeeded).to eql true
49
end
50
51
it 'outputs a message via the dispatcher' do
52
subject.waiting('ignored')
53
54
expect(@output).to include("#{name} started")
55
end
56
57
it 'sets the done event' do
58
expect(done_event).to receive(:set)
59
60
subject.waiting('ignored')
61
end
62
end
63
64
describe '#failed' do
65
it 'outputs a message via the dispatcher' do
66
subject.failed('ignored', 'ignored', 'ignored')
67
68
expect(@error).to include("#{name} failed to start")
69
end
70
71
it 'sets the done event' do
72
expect(done_event).to receive(:set)
73
74
subject.failed('ignored', 'ignored', 'ignored')
75
end
76
end
77
end
78
79