Skip to content

Commit 7a5ff2a

Browse files
committed
Adds tests for nil scenarios
1 parent 57e3045 commit 7a5ff2a

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

lib/msf/core/modules/metadata/search.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,17 @@ def is_match(params, module_metadata, regex_cache)
179179
when 'aka'
180180
match = [keyword, search_term] if (module_metadata.notes['AKA'] || []).any? { |aka| aka =~ regex }
181181
when 'author', 'authors'
182-
match = [keyword, search_term] if module_metadata.author && module_metadata.author.any? { |author| author =~ regex }
182+
match = [keyword, search_term] if module_metadata.author.any? { |author| author =~ regex }
183183
when 'arch'
184184
match = [keyword, search_term] if module_metadata.arch =~ regex
185185
when 'cve'
186-
match = [keyword, search_term] if module_metadata.references && module_metadata.references.any? { |ref| ref =~ /^cve\-/i and ref =~ regex }
186+
match = [keyword, search_term] if module_metadata.references.any? { |ref| ref =~ /^cve\-/i and ref =~ regex }
187187
when 'osvdb'
188-
match = [keyword, search_term] if module_metadata.references && module_metadata.references.any? { |ref| ref =~ /^osvdb\-/i and ref =~ regex }
188+
match = [keyword, search_term] if module_metadata.references.any? { |ref| ref =~ /^osvdb\-/i and ref =~ regex }
189189
when 'bid'
190-
match = [keyword, search_term] if module_metadata.references && module_metadata.references.any? { |ref| ref =~ /^bid\-/i and ref =~ regex }
190+
match = [keyword, search_term] if module_metadata.references.any? { |ref| ref =~ /^bid\-/i and ref =~ regex }
191191
when 'edb'
192-
match = [keyword, search_term] if module_metadata.references && module_metadata.references.any? { |ref| ref =~ /^edb\-/i and ref =~ regex }
192+
match = [keyword, search_term] if module_metadata.references.any? { |ref| ref =~ /^edb\-/i and ref =~ regex }
193193
when 'check'
194194
if module_metadata.check
195195
matches_check = %w(true yes).any? { |val| val =~ regex}

spec/lib/msf/core/modules/metadata/search_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ def inverse_query_terms(search_string)
154154
it_should_behave_like 'search_filter', :accept => accept, :reject => reject
155155
end
156156

157+
context 'on a module with a #author of nil' do
158+
let(:opts) { ({ 'author' => [nil] }) }
159+
reject = %w(author:foo)
160+
161+
it_should_behave_like 'search_filter', :reject => reject
162+
end
163+
157164
context 'on a module with the authors "joev" and "blarg"' do
158165
let(:opts) { ({ 'author' => ['joev', 'blarg'] }) }
159166
accept = %w(author:joev author:joe)
@@ -260,6 +267,22 @@ def inverse_query_terms(search_string)
260267
it_should_behave_like 'search_filter', accept: accept, reject: reject
261268
end
262269

270+
context 'on a module with a #targets of ["ubuntu", "windows", "osx"]' do
271+
let(:opts) { { 'targets' => %w[ubuntu windows osx] } }
272+
accept = %w[targets:osx]
273+
reject = %w[targets:unrelated]
274+
275+
it_should_behave_like 'search_filter', accept: accept, reject: reject
276+
end
277+
278+
context 'on a module with a #targets of nil' do
279+
let(:opts) { { 'targets' => nil } }
280+
281+
reject = %w[targets:foo]
282+
283+
it_should_behave_like 'search_filter', reject: reject
284+
end
285+
263286
context 'on a module that supports the osx platform' do
264287
let(:opts) { ({ 'platform' => 'osx' }) }
265288
accept = %w(platform:osx os:osx)
@@ -387,6 +410,14 @@ def inverse_query_terms(search_string)
387410
end
388411
end
389412

413+
context 'on a module with a #reference of nil' do
414+
let(:opts) { { 'references' => nil } }
415+
416+
reject = %w[reference:foo]
417+
418+
it_should_behave_like 'search_filter', reject: reject
419+
end
420+
390421
REF_TYPES.each do |ref_type|
391422
ref_num = '1234-1111'
392423
context "on a module with reference #{ref_type}-#{ref_num}" do

0 commit comments

Comments
 (0)