Skip to content

Commit a70d63e

Browse files
committed
Spec Msf::ModuleManager#on_module_load
[#47720609]
1 parent 604da84 commit a70d63e

File tree

1 file changed

+86
-0
lines changed
  • spec/support/shared/examples/msf/module_manager

1 file changed

+86
-0
lines changed

spec/support/shared/examples/msf/module_manager/loading.rb

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,90 @@
7676
end
7777
end
7878
end
79+
80+
context '#on_module_load' do
81+
def on_module_load
82+
module_manager.on_module_load(klass, type, reference_name, options)
83+
end
84+
85+
let(:annotated_class) do
86+
# stub out include? so calls in auto_subscribe_module work.
87+
mock('Annotated Class', :include? => false)
88+
end
89+
90+
let(:klass) do
91+
Class.new(Msf::Auxiliary)
92+
end
93+
94+
let(:module_set) do
95+
module_manager.module_set(type)
96+
end
97+
98+
let(:options) do
99+
{
100+
'files' => [
101+
path
102+
],
103+
'paths' => [
104+
reference_name
105+
],
106+
'type' => type
107+
}
108+
end
109+
110+
let(:path) do
111+
type_directory = Mdm::Module::Detail::DIRECTORY_BY_TYPE[type]
112+
113+
Metasploit::Framework.root.join(
114+
'modules',
115+
type_directory,
116+
"#{reference_name}.rb"
117+
).to_path
118+
end
119+
120+
let(:reference_name) do
121+
FactoryGirl.generate :mdm_module_detail_refname
122+
end
123+
124+
let(:type) do
125+
klass.type
126+
end
127+
128+
it "should add module to type's module_set" do
129+
module_set.should_receive(:add_module).with(
130+
klass,
131+
reference_name,
132+
options
133+
).and_return(annotated_class)
134+
135+
on_module_load
136+
end
137+
138+
context 'annotated class' do
139+
before(:each) do
140+
module_set.stub(:add_module).and_return(annotated_class)
141+
end
142+
143+
it 'should return annotated class from Msf::ModuleSet#add_module' do
144+
on_module_load.should == annotated_class
145+
end
146+
147+
it 'should pass annotated class to Msf::ModuleManager#auto_subscribe_module' do
148+
module_manager.should_receive(:auto_subscribe_module).with(annotated_class)
149+
150+
on_module_load
151+
end
152+
153+
it 'should fire on_module_load event' do
154+
framework.events.should_receive(:on_module_load).with(
155+
reference_name,
156+
annotated_class
157+
)
158+
159+
on_module_load
160+
end
161+
end
162+
163+
164+
end
79165
end

0 commit comments

Comments
 (0)