|
5 | 5 | require 'msf/ui/console/command_dispatcher/core'
|
6 | 6 |
|
7 | 7 | describe Msf::Ui::Console::CommandDispatcher::Core do
|
8 |
| - include_context 'Msf::DBManager' |
| 8 | + include_context 'Msf::DBManager' |
| 9 | + include_context 'Msf::UIDriver' |
9 | 10 |
|
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 |
19 | 14 |
|
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 |
23 | 19 |
|
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 |
28 | 23 |
|
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 |
32 | 26 |
|
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 |
35 | 29 |
|
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([]) |
38 | 32 |
|
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 |
41 | 35 |
|
42 |
| - search_modules_sql |
43 |
| - end |
| 36 | + context 'with matching Mdm::Module::Details' do |
| 37 | + let(:match) do |
| 38 | + module_detail.fullname |
| 39 | + end |
44 | 40 |
|
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 |
49 | 44 |
|
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 |
53 | 49 |
|
54 |
| - context 'printed table' do |
55 |
| - def cell(table, row, column) |
56 |
| - row_line_number = 6 + row |
57 |
| - line_number = 0 |
| 50 | + cell = nil |
58 | 51 |
|
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,}/) |
60 | 57 |
|
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 |
66 | 61 |
|
67 |
| - cell = cells[column] |
68 |
| - break |
69 |
| - end |
| 62 | + line_number += 1 |
| 63 | + end |
70 | 64 |
|
71 |
| - line_number += 1 |
72 |
| - end |
| 65 | + cell |
| 66 | + end |
73 | 67 |
|
74 |
| - cell |
75 |
| - end |
| 68 | + let(:printed_table) do |
| 69 | + table = '' |
76 | 70 |
|
77 |
| - let(:printed_table) do |
78 |
| - table = '' |
| 71 | + core.stub(:print_line) do |string| |
| 72 | + table = string |
| 73 | + end |
79 | 74 |
|
80 |
| - core.stub(:print_line) do |string| |
81 |
| - table = string |
82 |
| - end |
| 75 | + search_modules_sql |
83 | 76 |
|
84 |
| - search_modules_sql |
| 77 | + table |
| 78 | + end |
85 | 79 |
|
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 |
88 | 83 |
|
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 |
92 | 87 |
|
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 |
96 | 91 |
|
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 |
107 | 98 | end
|
0 commit comments