Skip to content

Commit 45fea32

Browse files
committed
Use 'Metasploit::Simple::Framework#modules loading' in 'payloads can be instantiated'
MSP-11130 Use `expect_to_load_module_ancestor` and `load_and_create_module` in favor of the custom code in 'payloads can be instantiated'.
1 parent c115ad3 commit 45fea32

File tree

1 file changed

+12
-34
lines changed

1 file changed

+12
-34
lines changed

spec/support/shared/examples/payload_can_be_instantiated.rb

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -79,54 +79,32 @@
7979

8080
module_type = 'payload'
8181

82-
include_context 'Msf::Simple::Framework'
82+
include_context 'Msf::Simple::Framework#modules loading'
8383

8484
#
8585
# lets
8686
#
8787

88-
let(:loader) {
89-
loader = framework.modules.send(:loaders).find { |loader|
90-
loader.loadable?(modules_path)
91-
}
92-
93-
# Override load_error so that rspec will print it instead of going to framework log
94-
def loader.load_error(module_path, error)
95-
raise error
96-
end
97-
98-
loader
99-
}
100-
101-
let(:module_set) {
102-
framework.modules.module_set(module_type)
103-
}
104-
10588
context reference_name do
10689
ancestor_reference_names.each do |ancestor_reference_name|
10790
it "can load '#{module_type}/#{ancestor_reference_name}'" do
10891
@actual_ancestor_reference_name_set.add(ancestor_reference_name)
10992

110-
loaded = loader.load_module(modules_path, module_type, ancestor_reference_name)
111-
112-
expect(loaded).to eq(true), "#{ancestor_reference_name} failed to load from #{modules_path}"
93+
expect_to_load_module_ancestor(
94+
ancestor_reference_name: ancestor_reference_name,
95+
module_type: module_type,
96+
modules_path: modules_path
97+
)
11398
end
11499
end
115100

116101
it 'can be instantiated' do
117-
ancestor_reference_names.each do |ancestor_reference_name|
118-
loaded = loader.load_module(modules_path, module_type, ancestor_reference_name)
119-
120-
expect(loaded).to eq(true), "#{ancestor_reference_name} failed to load from #{modules_path}"
121-
end
122-
123-
module_instance = nil
124-
125-
expect {
126-
module_instance = module_set.create(reference_name)
127-
}.not_to raise_error
128-
129-
expect(module_instance).not_to be_nil, "Could not instantiate #{module_type}/#{reference_name}"
102+
load_and_create_module(
103+
ancestor_reference_names: ancestor_reference_names,
104+
module_type: module_type,
105+
modules_path: modules_path,
106+
reference_name: reference_name
107+
)
130108
end
131109
end
132110
end

0 commit comments

Comments
 (0)