Skip to content

Commit b0c74db

Browse files
committed
Land rapid7#2120, specs for command_dispatcher
2 parents 6055ae7 + 03cd3ff commit b0c74db

File tree

5 files changed

+409
-76
lines changed

5 files changed

+409
-76
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require 'spec_helper'
2+
3+
require 'msf/ui'
4+
require 'msf/ui/console/command_dispatcher/auxiliary'
5+
6+
describe Msf::Ui::Console::CommandDispatcher::Auxiliary do
7+
include_context 'Msf::DBManager'
8+
include_context 'Msf::UIDriver'
9+
10+
subject(:aux) do
11+
described_class.new(driver)
12+
end
13+
14+
describe "#cmd_run" do
15+
end
16+
17+
describe "#cmd_rerun" do
18+
end
19+
20+
describe "#cmd_exploit" do
21+
end
22+
23+
describe "#cmd_reload" do
24+
end
25+
end

spec/lib/msf/ui/command_dispatcher/core_spec.rb

Lines changed: 67 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -5,103 +5,94 @@
55
require 'msf/ui/console/command_dispatcher/core'
66

77
describe Msf::Ui::Console::CommandDispatcher::Core do
8-
include_context 'Msf::DBManager'
8+
include_context 'Msf::DBManager'
9+
include_context 'Msf::UIDriver'
910

10-
let(:driver) do
11-
mock(
12-
'Driver',
13-
:framework => framework
14-
).tap { |driver|
15-
driver.stub(:on_command_proc=).with(kind_of(Proc))
16-
driver.stub(:print_line).with(kind_of(String))
17-
}
18-
end
11+
subject(:core) do
12+
described_class.new(driver)
13+
end
1914

20-
subject(:core) do
21-
described_class.new(driver)
22-
end
15+
context '#search_modules_sql' do
16+
def search_modules_sql
17+
core.search_modules_sql(match)
18+
end
2319

24-
context '#search_modules_sql' do
25-
def search_modules_sql
26-
core.search_modules_sql(match)
27-
end
20+
let(:match) do
21+
''
22+
end
2823

29-
let(:match) do
30-
''
31-
end
24+
it 'should generate Matching Modules table' do
25+
core.should_receive(:generate_module_table).with('Matching Modules').and_call_original
3226

33-
it 'should generate Matching Modules table' do
34-
core.should_receive(:generate_module_table).with('Matching Modules').and_call_original
27+
search_modules_sql
28+
end
3529

36-
search_modules_sql
37-
end
30+
it 'should call Msf::DBManager#search_modules' do
31+
db_manager.should_receive(:search_modules).with(match).and_return([])
3832

39-
it 'should call Msf::DBManager#search_modules' do
40-
db_manager.should_receive(:search_modules).with(match).and_return([])
33+
search_modules_sql
34+
end
4135

42-
search_modules_sql
43-
end
36+
context 'with matching Mdm::Module::Details' do
37+
let(:match) do
38+
module_detail.fullname
39+
end
4440

45-
context 'with matching Mdm::Module::Details' do
46-
let(:match) do
47-
module_detail.fullname
48-
end
41+
let!(:module_detail) do
42+
FactoryGirl.create(:mdm_module_detail)
43+
end
4944

50-
let!(:module_detail) do
51-
FactoryGirl.create(:mdm_module_detail)
52-
end
45+
context 'printed table' do
46+
def cell(table, row, column)
47+
row_line_number = 6 + row
48+
line_number = 0
5349

54-
context 'printed table' do
55-
def cell(table, row, column)
56-
row_line_number = 6 + row
57-
line_number = 0
50+
cell = nil
5851

59-
cell = nil
52+
table.each_line do |line|
53+
if line_number == row_line_number
54+
# strip prefix and postfix
55+
padded_cells = line[3...-1]
56+
cells = padded_cells.split(/\s{2,}/)
6057

61-
table.each_line do |line|
62-
if line_number == row_line_number
63-
# strip prefix and postfix
64-
padded_cells = line[3...-1]
65-
cells = padded_cells.split(/\s{2,}/)
58+
cell = cells[column]
59+
break
60+
end
6661

67-
cell = cells[column]
68-
break
69-
end
62+
line_number += 1
63+
end
7064

71-
line_number += 1
72-
end
65+
cell
66+
end
7367

74-
cell
75-
end
68+
let(:printed_table) do
69+
table = ''
7670

77-
let(:printed_table) do
78-
table = ''
71+
core.stub(:print_line) do |string|
72+
table = string
73+
end
7974

80-
core.stub(:print_line) do |string|
81-
table = string
82-
end
75+
search_modules_sql
8376

84-
search_modules_sql
77+
table
78+
end
8579

86-
table
87-
end
80+
it 'should have fullname in first column' do
81+
cell(printed_table, 0, 0).should include(module_detail.fullname)
82+
end
8883

89-
it 'should have fullname in first column' do
90-
cell(printed_table, 0, 0).should include(module_detail.fullname)
91-
end
84+
it 'should have disclosure date in second column' do
85+
cell(printed_table, 0, 1).should include(module_detail.disclosure_date.to_s)
86+
end
9287

93-
it 'should have disclosure date in second column' do
94-
cell(printed_table, 0, 1).should include(module_detail.disclosure_date.to_s)
95-
end
88+
it 'should have rank name in third column' do
89+
cell(printed_table, 0, 2).should include(Msf::RankingName[module_detail.rank])
90+
end
9691

97-
it 'should have rank name in third column' do
98-
cell(printed_table, 0, 2).should include(Msf::RankingName[module_detail.rank])
99-
end
100-
101-
it 'should have name in fourth column' do
102-
cell(printed_table, 0, 3).should include(module_detail.name)
103-
end
104-
end
105-
end
106-
end
92+
it 'should have name in fourth column' do
93+
cell(printed_table, 0, 3).should include(module_detail.name)
94+
end
95+
end
96+
end
97+
end
10798
end

0 commit comments

Comments
 (0)