capture_spec.rb 2.1 KB

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