Skip to content

Commit 0709395

Browse files
committed
Msf::ModuleManager::Loading shared example
[#47979793]
1 parent ff7a8e6 commit 0709395

File tree

2 files changed

+80
-78
lines changed

2 files changed

+80
-78
lines changed

spec/lib/msf/core/module_manager_spec.rb

Lines changed: 1 addition & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -36,83 +36,6 @@
3636
described_class.new(framework)
3737
end
3838

39+
it_should_behave_like 'Msf::ModuleManager::Loading'
3940
it_should_behave_like 'Msf::ModuleManager::ModulePaths'
40-
41-
context '#file_changed?' do
42-
let(:module_basename) do
43-
[basename_prefix, '.rb']
44-
end
45-
46-
it 'should return true if module info is not cached' do
47-
Tempfile.open(module_basename) do |tempfile|
48-
module_path = tempfile.path
49-
50-
subject.send(:module_info_by_path)[module_path].should be_nil
51-
subject.file_changed?(module_path).should be_true
52-
end
53-
end
54-
55-
it 'should return true if the cached type is Msf::MODULE_PAYLOAD' do
56-
Tempfile.open(module_basename) do |tempfile|
57-
module_path = tempfile.path
58-
modification_time = File.mtime(module_path)
59-
60-
subject.send(:module_info_by_path)[module_path] = {
61-
# :modification_time must match so that it is the :type that is causing the `true` and not the
62-
# :modification_time causing the `true`.
63-
:modification_time => modification_time,
64-
:type => Msf::MODULE_PAYLOAD
65-
}
66-
67-
subject.file_changed?(module_path).should be_true
68-
end
69-
end
70-
71-
context 'with cache module info and not a payload module' do
72-
it 'should return true if the file does not exist on the file system' do
73-
tempfile = Tempfile.new(module_basename)
74-
module_path = tempfile.path
75-
modification_time = File.mtime(module_path).to_i
76-
77-
subject.send(:module_info_by_path)[module_path] = {
78-
:modification_time => modification_time
79-
}
80-
81-
tempfile.unlink
82-
83-
File.exist?(module_path).should be_false
84-
subject.file_changed?(module_path).should be_true
85-
end
86-
87-
it 'should return true if modification time does not match the cached modification time' do
88-
Tempfile.open(module_basename) do |tempfile|
89-
module_path = tempfile.path
90-
modification_time = File.mtime(module_path).to_i
91-
cached_modification_time = (modification_time * rand).to_i
92-
93-
subject.send(:module_info_by_path)[module_path] = {
94-
:modification_time => cached_modification_time
95-
}
96-
97-
cached_modification_time.should_not == modification_time
98-
subject.file_changed?(module_path).should be_true
99-
end
100-
end
101-
102-
it 'should return false if modification time does match the cached modification time' do
103-
Tempfile.open(module_basename) do |tempfile|
104-
module_path = tempfile.path
105-
modification_time = File.mtime(module_path).to_i
106-
cached_modification_time = modification_time
107-
108-
subject.send(:module_info_by_path)[module_path] = {
109-
:modification_time => cached_modification_time
110-
}
111-
112-
cached_modification_time.should == modification_time
113-
subject.file_changed?(module_path).should be_false
114-
end
115-
end
116-
end
117-
end
11841
end
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
shared_examples_for 'Msf::ModuleManager::Loading' do
2+
context '#file_changed?' do
3+
let(:module_basename) do
4+
[basename_prefix, '.rb']
5+
end
6+
7+
it 'should return true if module info is not cached' do
8+
Tempfile.open(module_basename) do |tempfile|
9+
module_path = tempfile.path
10+
11+
subject.send(:module_info_by_path)[module_path].should be_nil
12+
subject.file_changed?(module_path).should be_true
13+
end
14+
end
15+
16+
it 'should return true if the cached type is Msf::MODULE_PAYLOAD' do
17+
Tempfile.open(module_basename) do |tempfile|
18+
module_path = tempfile.path
19+
modification_time = File.mtime(module_path)
20+
21+
subject.send(:module_info_by_path)[module_path] = {
22+
# :modification_time must match so that it is the :type that is causing the `true` and not the
23+
# :modification_time causing the `true`.
24+
:modification_time => modification_time,
25+
:type => Msf::MODULE_PAYLOAD
26+
}
27+
28+
subject.file_changed?(module_path).should be_true
29+
end
30+
end
31+
32+
context 'with cache module info and not a payload module' do
33+
it 'should return true if the file does not exist on the file system' do
34+
tempfile = Tempfile.new(module_basename)
35+
module_path = tempfile.path
36+
modification_time = File.mtime(module_path).to_i
37+
38+
subject.send(:module_info_by_path)[module_path] = {
39+
:modification_time => modification_time
40+
}
41+
42+
tempfile.unlink
43+
44+
File.exist?(module_path).should be_false
45+
subject.file_changed?(module_path).should be_true
46+
end
47+
48+
it 'should return true if modification time does not match the cached modification time' do
49+
Tempfile.open(module_basename) do |tempfile|
50+
module_path = tempfile.path
51+
modification_time = File.mtime(module_path).to_i
52+
cached_modification_time = (modification_time * rand).to_i
53+
54+
subject.send(:module_info_by_path)[module_path] = {
55+
:modification_time => cached_modification_time
56+
}
57+
58+
cached_modification_time.should_not == modification_time
59+
subject.file_changed?(module_path).should be_true
60+
end
61+
end
62+
63+
it 'should return false if modification time does match the cached modification time' do
64+
Tempfile.open(module_basename) do |tempfile|
65+
module_path = tempfile.path
66+
modification_time = File.mtime(module_path).to_i
67+
cached_modification_time = modification_time
68+
69+
subject.send(:module_info_by_path)[module_path] = {
70+
:modification_time => cached_modification_time
71+
}
72+
73+
cached_modification_time.should == modification_time
74+
subject.file_changed?(module_path).should be_false
75+
end
76+
end
77+
end
78+
end
79+
end

0 commit comments

Comments
 (0)