1
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:
David Maloney 2013-07-20 17:49:03 -05:00
parent d6f2b28708
commit d66779ba4c
3 changed files with 25 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,3 @@
foo
bar
baz

View 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