Skip to content

Commit ff7a8e6

Browse files
committed
Msf::ModuleManager::ModulePaths shared example
[#47979793]
1 parent 960392d commit ff7a8e6

File tree

2 files changed

+79
-72
lines changed

2 files changed

+79
-72
lines changed

spec/lib/msf/core/module_manager_spec.rb

Lines changed: 2 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -32,81 +32,11 @@
3232
Msf::Framework.new
3333
end
3434

35-
subject do
35+
subject(:module_manager) do
3636
described_class.new(framework)
3737
end
3838

39-
context '#add_module_path' do
40-
it 'should strip trailing File::SEPARATOR from the path' do
41-
Dir.mktmpdir do |path|
42-
path_with_trailing_separator = path + File::SEPARATOR
43-
subject.add_module_path(path_with_trailing_separator)
44-
45-
subject.send(:module_paths).should_not include(path_with_trailing_separator)
46-
subject.send(:module_paths).should include(path)
47-
end
48-
end
49-
50-
context 'with Fastlib archive' do
51-
it 'should raise an ArgumentError unless the File exists' do
52-
file = Tempfile.new(archive_basename)
53-
# unlink will clear path, so copy it to a variable
54-
path = file.path
55-
file.unlink
56-
57-
File.exist?(path).should be_false
58-
59-
expect {
60-
subject.add_module_path(path)
61-
}.to raise_error(ArgumentError, "The path supplied does not exist")
62-
end
63-
64-
it 'should add the path to #module_paths if the File exists' do
65-
Tempfile.open(archive_basename) do |temporary_file|
66-
path = temporary_file.path
67-
68-
File.exist?(path).should be_true
69-
70-
subject.add_module_path(path)
71-
72-
subject.send(:module_paths).should include(path)
73-
end
74-
end
75-
end
76-
77-
context 'with directory' do
78-
it 'should add path to #module_paths' do
79-
Dir.mktmpdir do |path|
80-
subject.add_module_path(path)
81-
82-
subject.send(:module_paths).should include(path)
83-
end
84-
end
85-
86-
context 'containing Fastlib archives' do
87-
it 'should add each Fastlib archive to #module_paths' do
88-
Dir.mktmpdir do |directory|
89-
Tempfile.open(archive_basename, directory) do |file|
90-
subject.add_module_path(directory)
91-
92-
subject.send(:module_paths).should include(directory)
93-
subject.send(:module_paths).should include(file.path)
94-
end
95-
end
96-
end
97-
end
98-
end
99-
100-
context 'with other file' do
101-
it 'should raise ArgumentError' do
102-
Tempfile.open(basename_prefix) do |file|
103-
expect {
104-
subject.add_module_path(file.path)
105-
}.to raise_error(ArgumentError, 'The path supplied is not a valid directory.')
106-
end
107-
end
108-
end
109-
end
39+
it_should_behave_like 'Msf::ModuleManager::ModulePaths'
11040

11141
context '#file_changed?' do
11242
let(:module_basename) do
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
shared_examples_for 'Msf::ModuleManager::ModulePaths' do
2+
def module_paths
3+
module_manager.send(:module_paths)
4+
end
5+
6+
context '#add_module_path' do
7+
it 'should strip trailing File::SEPARATOR from the path' do
8+
Dir.mktmpdir do |path|
9+
path_with_trailing_separator = path + File::SEPARATOR
10+
module_manager.add_module_path(path_with_trailing_separator)
11+
12+
module_paths.should_not include(path_with_trailing_separator)
13+
module_paths.should include(path)
14+
end
15+
end
16+
17+
context 'with Fastlib archive' do
18+
it 'should raise an ArgumentError unless the File exists' do
19+
file = Tempfile.new(archive_basename)
20+
# unlink will clear path, so copy it to a variable
21+
path = file.path
22+
file.unlink
23+
24+
File.exist?(path).should be_false
25+
26+
expect {
27+
module_manager.add_module_path(path)
28+
}.to raise_error(ArgumentError, "The path supplied does not exist")
29+
end
30+
31+
it 'should add the path to #module_paths if the File exists' do
32+
Tempfile.open(archive_basename) do |temporary_file|
33+
path = temporary_file.path
34+
35+
File.exist?(path).should be_true
36+
37+
module_manager.add_module_path(path)
38+
39+
module_paths.should include(path)
40+
end
41+
end
42+
end
43+
44+
context 'with directory' do
45+
it 'should add path to #module_paths' do
46+
Dir.mktmpdir do |path|
47+
module_manager.add_module_path(path)
48+
49+
module_paths.should include(path)
50+
end
51+
end
52+
53+
context 'containing Fastlib archives' do
54+
it 'should add each Fastlib archive to #module_paths' do
55+
Dir.mktmpdir do |directory|
56+
Tempfile.open(archive_basename, directory) do |file|
57+
module_manager.add_module_path(directory)
58+
59+
module_paths.should include(directory)
60+
module_paths.should include(file.path)
61+
end
62+
end
63+
end
64+
end
65+
end
66+
67+
context 'with other file' do
68+
it 'should raise ArgumentError' do
69+
Tempfile.open(basename_prefix) do |file|
70+
expect {
71+
subject.add_module_path(file.path)
72+
}.to raise_error(ArgumentError, 'The path supplied is not a valid directory.')
73+
end
74+
end
75+
end
76+
end
77+
end

0 commit comments

Comments
 (0)