add OptFloat datastore option

bug/bundler_fix
Brent Cook 2017-08-05 02:21:31 -05:00
parent 331279d891
commit 47dc3772a7
3 changed files with 51 additions and 0 deletions

24
lib/msf/core/opt_float.rb Normal file
View File

@ -0,0 +1,24 @@
# -*- coding: binary -*-
module Msf
###
#
# Float option.
#
###
class OptFloat < OptBase
def type
'float'
end
def normalize(value)
Float(value) if value.present? && valid?(value)
end
def valid?(value, check_empty: true)
return false if check_empty && empty_required_value?(value)
Float(value) rescue return false if value.present?
super
end
end
end

View File

@ -12,6 +12,7 @@ module Msf
autoload :OptBool, 'msf/core/opt_bool'
autoload :OptEnum, 'msf/core/opt_enum'
autoload :OptInt, 'msf/core/opt_int'
autoload :OptFloat, 'msf/core/opt_float'
autoload :OptPath, 'msf/core/opt_path'
autoload :OptPort, 'msf/core/opt_port'
autoload :OptRaw, 'msf/core/opt_raw'
@ -35,6 +36,7 @@ module Msf
# * {OptAddress} - IP address or hostname
# * {OptPath} - Path name on disk or an Object ID
# * {OptInt} - An integer value
# * {OptFloat} - A float value
# * {OptEnum} - Select from a set of valid values
# * {OptAddressRange} - A subnet or range of addresses
# * {OptRegexp} - Valid Ruby regular expression

View File

@ -0,0 +1,25 @@
# -*- coding:binary -*-
require 'spec_helper'
require 'msf/core/option_container'
RSpec.describe Msf::OptFloat do
valid_values = [
{ :value => "1", :normalized => 1.0 },
{ :value => "1.1", :normalized => 1.1 },
{ :value => "0", :normalized => 0.0 },
{ :value => "-1", :normalized => -1.0 },
{ :value => "01", :normalized => 1.0 },
{ :value => "0xff", :normalized => 255.0 },
]
invalid_values = [
{ :value => "0xblah", },
{ :value => "-12cat", },
{ :value => "covfefe", },
{ :value => "NaN", },
]
it_behaves_like "an option", valid_values, invalid_values, 'float'
end