Skip to content

Commit f8b5f1b

Browse files
committed
Adds specs for different ref types.
1 parent f4b0ab8 commit f8b5f1b

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

spec/lib/msf/core/module_spec.rb

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@
3535
end
3636

3737

38+
REF_TYPES = %w(CVE BID OSVDB EDB)
39+
3840
describe Msf::Module do
3941
describe '#search_filter' do
40-
before { subject.stub(:type => 'server') }
4142
let(:opts) { Hash.new }
43+
before { subject.stub(:fullname => '/module') }
4244
subject { Msf::Module.new(opts) }
43-
4445
accept = []
4546
reject = []
4647

@@ -82,40 +83,40 @@
8283

8384
context 'on a module that supports the osx platform' do
8485
let(:opts) { ({ 'Platform' => %w(osx) }) }
85-
accept = %w(platform:osx)
86-
reject = %w(platform:bsd platform:windows platform:unix)
86+
accept = %w(platform:osx os:osx)
87+
reject = %w(platform:bsd platform:windows platform:unix os:bsd os:windows os:unix)
8788

8889
it_should_behave_like 'search_filter', :accept => accept, :reject => reject
8990
end
9091

9192
context 'on a module that supports the linux platform' do
9293
let(:opts) { ({ 'Platform' => %w(linux) }) }
93-
accept = %w(platform:linux)
94-
reject = %w(platform:bsd platform:windows platform:unix)
94+
accept = %w(platform:linux os:linux)
95+
reject = %w(platform:bsd platform:windows platform:unix os:bsd os:windows os:unix)
9596

9697
it_should_behave_like 'search_filter', :accept => accept, :reject => reject
9798
end
9899

99100
context 'on a module that supports the windows platform' do
100101
let(:opts) { ({ 'Platform' => %w(windows) }) }
101-
accept = %w(platform:windows)
102-
reject = %w(platform:bsd platform:osx platform:unix)
102+
accept = %w(platform:windows os:windows)
103+
reject = %w(platform:bsd platform:osx platform:unix os:bsd os:osx os:unix)
103104

104105
it_should_behave_like 'search_filter', :accept => accept, :reject => reject
105106
end
106107

107108
context 'on a module that supports the osx and linux platforms' do
108109
let(:opts) { ({ 'Platform' => %w(osx linux) }) }
109-
accept = %w(platform:osx platform:linux)
110-
reject = %w(platform:bsd platform:windows platform:unix)
110+
accept = %w(platform:osx platform:linux os:osx os:linux)
111+
reject = %w(platform:bsd platform:windows platform:unix os:bsd os:windows os:unix)
111112

112113
it_should_behave_like 'search_filter', :accept => accept, :reject => reject
113114
end
114115

115116
context 'on a module that supports the windows and irix platforms' do
116117
let(:opts) { ({ 'Platform' => %w(windows irix) }) }
117-
accept = %w(platform:windows platform:irix)
118-
reject = %w(platform:bsd platform:osx platform:linux)
118+
accept = %w(platform:windows platform:irix os:windows os:irix)
119+
reject = %w(platform:bsd platform:osx platform:linux os:bsd os:osx os:linux)
119120

120121
it_should_behave_like 'search_filter', :accept => accept, :reject => reject
121122
end
@@ -129,19 +130,19 @@
129130
end
130131

131132
context 'on a module with a #name of "blah"' do
132-
before { subject.stub(:name => 'blah') }
133+
let(:opts) { ({ 'Name' => 'blah' }) }
133134
it_should_behave_like 'search_filter', :accept => %w(text:blah), :reject => %w(text:foo)
134135
it_should_behave_like 'search_filter', :accept => %w(name:blah), :reject => %w(name:foo)
135136
end
136137

137138
context 'on a module with a #fullname of "blah"' do
138-
before { subject.stub(:fullname => 'blah/blah') }
139+
before { subject.stub(:fullname => '/c/d/e/blah') }
139140
it_should_behave_like 'search_filter', :accept => %w(text:blah), :reject => %w(text:foo)
140141
it_should_behave_like 'search_filter', :accept => %w(path:blah), :reject => %w(path:foo)
141142
end
142143

143144
context 'on a module with a #description of "blah"' do
144-
before { subject.stub(:description => 'blah') }
145+
let(:opts) { ({ 'Description' => 'blah' }) }
145146
it_should_behave_like 'search_filter', :accept => %w(text:blah), :reject => %w(text:foo)
146147
end
147148

@@ -159,6 +160,17 @@
159160
end
160161
end
161162

163+
REF_TYPES.each do |ref_type|
164+
ref_num = '1234-1111'
165+
context 'on a module with reference #{ref_type}-#{ref_num}' do
166+
let(:opts) { ({ 'References' => [[ref_type, ref_num]] }) }
167+
accept = ["#{ref_type.downcase}:#{ref_num}"]
168+
reject = %w(1235-1111 1234-1112 bad).map { |n| "#{ref_type.downcase}:#{n}" }
169+
170+
it_should_behave_like 'search_filter', :accept => accept, :reject => reject
171+
end
172+
end
173+
162174
#
163175
# Still missing 'cve:', 'bid:', 'osvdb:', and 'edb:' test cases...
164176
#

0 commit comments

Comments
 (0)