mirror of
https://github.com/rapid7/metasploit-framework
synced 2024-11-12 11:52:01 +01:00
OptString specs and better validation
This commit is contained in:
parent
d6f2b28708
commit
d66779ba4c
@ -173,6 +173,7 @@ class OptString < OptBase
|
||||
|
||||
def valid?(value=self.value)
|
||||
value = normalize(value)
|
||||
return false unless value.kind_of?(String) or value.kind_of?(NilClass)
|
||||
return false if empty_required_value?(value)
|
||||
return super
|
||||
end
|
||||
|
3
spec/file_fixtures/string_list.txt
Normal file
3
spec/file_fixtures/string_list.txt
Normal file
@ -0,0 +1,3 @@
|
||||
foo
|
||||
bar
|
||||
baz
|
21
spec/lib/msf/core/options/opt_string_spec.rb
Normal file
21
spec/lib/msf/core/options/opt_string_spec.rb
Normal file
@ -0,0 +1,21 @@
|
||||
# -*- coding:binary -*-
|
||||
|
||||
require 'spec_helper'
|
||||
require 'msf/core/option_container'
|
||||
|
||||
describe Msf::OptString do
|
||||
valid_values = [
|
||||
{ :value => 'foo', :normalized => 'foo' },
|
||||
{ :value => "file:#{File.expand_path('string_list.txt',FILE_FIXTURES_PATH)}",:normalized => "foo\nbar\nbaz" },
|
||||
]
|
||||
invalid_values = [
|
||||
# Non-string values
|
||||
{ :value => true},
|
||||
{ :value => 5 },
|
||||
{ :value => []},
|
||||
{ :value => [1,2]},
|
||||
{ :value => {}},
|
||||
]
|
||||
|
||||
it_behaves_like "an option", valid_values, invalid_values, 'string'
|
||||
end
|
Loading…
Reference in New Issue
Block a user