Skip to content

Commit d85f988

Browse files
David MaloneyDavid Maloney
authored andcommitted
fix command dispatcher specs
1 parent ab2e88a commit d85f988

File tree

4 files changed

+102
-86
lines changed

4 files changed

+102
-86
lines changed

lib/msf/ui/console/command_dispatcher/core.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ class Core
9090
"-h" => [ false, "Help banner." ],
9191
"-e" => [ true, "Expression to evaluate." ])
9292

93-
# Constant for disclosure date formatting in search functions
94-
DISCLOSURE_DATE_FORMAT = "%Y-%m-%d"
93+
9594

9695
# Constant for a retry timeout on using modules before they're loaded
9796
CMD_USE_TIMEOUT = 3

lib/msf/ui/console/command_dispatcher/modules.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ class Modules
1919

2020
include Msf::Ui::Console::CommandDispatcher
2121

22+
# Constant for disclosure date formatting in search functions
23+
DISCLOSURE_DATE_FORMAT = "%Y-%m-%d"
24+
2225
@@search_opts = Rex::Parser::Arguments.new(
2326
"-h" => [ false, "Help banner."]
2427
)

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

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -12,90 +12,6 @@
1212
described_class.new(driver)
1313
end
1414

15-
context '#search_modules_sql' do
16-
def search_modules_sql
17-
core.search_modules_sql(match)
18-
end
19-
20-
let(:match) do
21-
''
22-
end
23-
24-
it 'should generate Matching Modules table' do
25-
expect(core).to receive(:generate_module_table).with('Matching Modules').and_call_original
26-
27-
search_modules_sql
28-
end
29-
30-
it 'should call Msf::DBManager#search_modules' do
31-
expect(db_manager).to receive(:search_modules).with(match).and_return([])
32-
33-
search_modules_sql
34-
end
35-
36-
context 'with matching Mdm::Module::Details' do
37-
let(:match) do
38-
module_detail.fullname
39-
end
40-
41-
let!(:module_detail) do
42-
FactoryGirl.create(:mdm_module_detail)
43-
end
44-
45-
context 'printed table' do
46-
def cell(table, row, column)
47-
row_line_number = 6 + row
48-
line_number = 0
49-
50-
cell = nil
51-
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,}/)
57-
58-
cell = cells[column]
59-
break
60-
end
61-
62-
line_number += 1
63-
end
64-
65-
cell
66-
end
67-
68-
let(:printed_table) do
69-
table = ''
70-
71-
expect(core).to receive(:print_line) do |string|
72-
table = string
73-
end
74-
75-
search_modules_sql
76-
77-
table
78-
end
79-
80-
it 'should have fullname in first column' do
81-
expect(cell(printed_table, 0, 0)).to include(module_detail.fullname)
82-
end
83-
84-
it 'should have disclosure date in second column' do
85-
expect(cell(printed_table, 0, 1)).to include(module_detail.disclosure_date.strftime("%Y-%m-%d"))
86-
end
87-
88-
it 'should have rank name in third column' do
89-
expect(cell(printed_table, 0, 2)).to include(Msf::RankingName[module_detail.rank])
90-
end
91-
92-
it 'should have name in fourth column' do
93-
expect(cell(printed_table, 0, 3)).to include(module_detail.name)
94-
end
95-
end
96-
end
97-
end
98-
9915
it { is_expected.to respond_to :cmd_get }
10016
it { is_expected.to respond_to :cmd_getg }
10117

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
require 'spec_helper'
2+
3+
require 'msf/ui'
4+
require 'msf/ui/console/module_command_dispatcher'
5+
require 'msf/ui/console/command_dispatcher/core'
6+
7+
RSpec.describe Msf::Ui::Console::CommandDispatcher::Modules do
8+
include_context 'Msf::DBManager'
9+
include_context 'Msf::UIDriver'
10+
11+
subject(:core) do
12+
described_class.new(driver)
13+
end
14+
15+
context '#search_modules_sql' do
16+
def search_modules_sql
17+
core.search_modules_sql(match)
18+
end
19+
20+
let(:match) do
21+
''
22+
end
23+
24+
it 'should generate Matching Modules table' do
25+
expect(core).to receive(:generate_module_table).with('Matching Modules').and_call_original
26+
27+
search_modules_sql
28+
end
29+
30+
it 'should call Msf::DBManager#search_modules' do
31+
expect(db_manager).to receive(:search_modules).with(match).and_return([])
32+
33+
search_modules_sql
34+
end
35+
36+
context 'with matching Mdm::Module::Details' do
37+
let(:match) do
38+
module_detail.fullname
39+
end
40+
41+
let!(:module_detail) do
42+
FactoryGirl.create(:mdm_module_detail)
43+
end
44+
45+
context 'printed table' do
46+
def cell(table, row, column)
47+
row_line_number = 6 + row
48+
line_number = 0
49+
50+
cell = nil
51+
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,}/)
57+
58+
cell = cells[column]
59+
break
60+
end
61+
62+
line_number += 1
63+
end
64+
65+
cell
66+
end
67+
68+
let(:printed_table) do
69+
table = ''
70+
71+
expect(core).to receive(:print_line) do |string|
72+
table = string
73+
end
74+
75+
search_modules_sql
76+
77+
table
78+
end
79+
80+
it 'should have fullname in first column' do
81+
expect(cell(printed_table, 0, 0)).to include(module_detail.fullname)
82+
end
83+
84+
it 'should have disclosure date in second column' do
85+
expect(cell(printed_table, 0, 1)).to include(module_detail.disclosure_date.strftime("%Y-%m-%d"))
86+
end
87+
88+
it 'should have rank name in third column' do
89+
expect(cell(printed_table, 0, 2)).to include(Msf::RankingName[module_detail.rank])
90+
end
91+
92+
it 'should have name in fourth column' do
93+
expect(cell(printed_table, 0, 3)).to include(module_detail.name)
94+
end
95+
end
96+
end
97+
end
98+
end

0 commit comments

Comments
 (0)