CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/spec/lib/msf/db_manager/export_spec.rb
Views: 11704
1
require 'spec_helper'
2
3
4
RSpec.describe Msf::DBExport do
5
include_context 'Msf::DBManager'
6
7
subject(:export) do
8
described_class.new(workspace)
9
end
10
11
let(:active) do
12
true
13
end
14
15
let(:workspace) do
16
FactoryBot.create(
17
:mdm_workspace
18
)
19
end
20
21
context '#extract_module_detail_info' do
22
let(:report_file) do
23
StringIO.new
24
end
25
26
subject(:extract_module_detail_info) do
27
export.extract_module_detail_info(report_file)
28
end
29
30
context 'with Mdm::Module::Details' do
31
let(:document) do
32
Nokogiri::XML(report_file.string)
33
end
34
35
let(:module_detail_count) do
36
2
37
end
38
39
let(:root) do
40
document.root
41
end
42
43
let!(:module_details) do
44
FactoryBot.create_list(
45
:mdm_module_detail,
46
module_detail_count
47
)
48
end
49
50
before(:example) do
51
report_file.write("<root>")
52
extract_module_detail_info
53
report_file.write("</root>")
54
end
55
56
it 'should have module_detail tag for each Mdm::Module::Detail' do
57
nodes = root.xpath('module_detail')
58
59
expect(nodes.length).to eq module_detail_count
60
end
61
62
context 'module_detail' do
63
let(:module_detail) do
64
module_details.first
65
end
66
67
subject(:module_detail_node) do
68
root.at_xpath('module_detail')
69
end
70
71
it_should_behave_like 'Msf::DBExport#extract_module_detail_info module_detail child', 'description'
72
73
context '/disclosure-date' do
74
it 'should have Mdm::Module::Detail#disclosure_date present' do
75
expect(module_detail.disclosure_date).to be_present
76
end
77
78
it 'should have Mdm::Module::Detail#disclosure_date from disclosure-date content' do
79
node = module_detail_node.at_xpath('disclosure-date')
80
81
expect(DateTime.parse(node.content)).to eq module_detail.disclosure_date
82
end
83
end
84
85
it_should_behave_like 'Msf::DBExport#extract_module_detail_info module_detail child', 'file'
86
it_should_behave_like 'Msf::DBExport#extract_module_detail_info module_detail child', 'fullname'
87
it_should_behave_like 'Msf::DBExport#extract_module_detail_info module_detail child', 'license'
88
it_should_behave_like 'Msf::DBExport#extract_module_detail_info module_detail child', 'mtime'
89
it_should_behave_like 'Msf::DBExport#extract_module_detail_info module_detail child', 'mtype'
90
it_should_behave_like 'Msf::DBExport#extract_module_detail_info module_detail child', 'name'
91
it_should_behave_like 'Msf::DBExport#extract_module_detail_info module_detail child', 'privileged'
92
it_should_behave_like 'Msf::DBExport#extract_module_detail_info module_detail child', 'rank'
93
it_should_behave_like 'Msf::DBExport#extract_module_detail_info module_detail child', 'refname'
94
95
# @todo https://www.pivotaltracker.com/story/show/48451001
96
end
97
end
98
99
context 'without Mdm::Module::Details' do
100
it 'should not write anything to report_file' do
101
extract_module_detail_info
102
103
expect(report_file.string).to be_empty
104
end
105
end
106
end
107
end
108
109