Add additional tests for edge cases

This commit is contained in:
Alan Foster
2020-08-18 16:10:28 +01:00
parent baa33df45d
commit f8523cb3e2
2 changed files with 16 additions and 0 deletions
+1
View File
@@ -25,6 +25,7 @@ module Msf::Modules::Metadata::Search
# {"platform"=>[[], ["android"]]} will exclude modules targeting the android platform
#
def self.parse_search_string(search_string)
search_string ||= ''
search_string += ' '
# Split search terms by space, but allow quoted strings
@@ -30,6 +30,17 @@ RSpec.describe Msf::Modules::Metadata::Search do
allow(subject).to receive(:get_metadata).and_return([mock_module])
end
describe '#parse_search_string' do
it { expect(described_class.parse_search_string(nil)).to eq({}) }
it { expect(described_class.parse_search_string(" ")).to eq({}) }
it { expect(described_class.parse_search_string("os:osx os:windows")).to eq({"os"=>[["osx", "windows"], []]}) }
it { expect(described_class.parse_search_string("postgres login")).to eq({"text"=>[["postgres", "login"], []]}) }
it { expect(described_class.parse_search_string("platform:android")).to eq({"platform"=>[["android"], []]}) }
it { expect(described_class.parse_search_string("platform:-android")).to eq({"platform"=>[[], ["android"]]}) }
it { expect(described_class.parse_search_string("author:egypt arch:x64")).to eq({"author"=>[["egypt"], []], "arch"=>[["x64"], []]}) }
it { expect(described_class.parse_search_string(" author:egypt arch:x64 ")).to eq({"author"=>[["egypt"], []], "arch"=>[["x64"], []]}) }
end
describe '#find' do
REF_TYPES = %w(CVE BID EDB)
@@ -188,6 +199,10 @@ RSpec.describe Msf::Modules::Metadata::Search do
it_should_behave_like 'search_filter', :accept => %w(text:blah), :reject => %w(text:foo)
end
context 'on nil and empty input' do
it_should_behave_like 'search_filter', :accept => [nil, '', ' '], :test_inverse => false
end
context 'when filtering by module #type' do
all_module_types = Msf::MODULE_TYPES
all_module_types.each do |mtype|