Bug #3004: Role names, only word characters (letter, number, underscore) are allowed

This commit is contained in:
Daniel Molina committed 2014-07-21 18:56:47 +02:00
1 parent c5332c8cc1
commit 736c64dff3
2 files changed
+39 -1

No files matched your search

+2 -1
View File
@@ -24,7 +24,8 @@ module OpenNebula
:properties => {
'name' => {
:type => :string,
:required => true
:required => true,
:regex => /^\w+$/
},
'cardinality' => {
:type => :integer,
+37
View File
@@ -377,6 +377,7 @@ class Validator
# @note Schema options supported
# :format
# :enum
# :regex
#
def validate_string(body, schema_string, schema_key)
if body.instance_of?(String)
@@ -384,6 +385,8 @@ class Validator
check_format(body, schema_string, schema_key)
elsif schema_string[:enum]
check_enum(body, schema_string, schema_key)
elsif schema_string[:regex]
check_regex(body, schema_string, schema_key)
else
body
end
@@ -468,6 +471,40 @@ class Validator
" #{schema_string[:enum].join(', ')}; SCHEMA: #{schema_string}"
end
end
# Validate an string regex
#
# @param [String] body_value to be validated
# @param [Hash] schema_string of the object to validate the body
# @param [String] schema_key of the body that will be validated in this step
#
# @return [String] The modified body
#
# @raise [ParseException] if the body does not meet the schema definition
#
# @example Validate array
# schema = {
# :type => :string,
# :regex => /^\w+$/
# }
#
# body = "juan"
#
# Validator.check_regex(body, schema)
# #=> "juan"
#
# @note The parameter body will be modified
# @note Schema options supported
# :enum
#
def check_regex(body_value, schema_string, schema_key)
if schema_string[:regex] =~ body_value
body_value
else
raise ParseException, "KEY: '#{schema_key}' malformed; "\
"SCHEMA: #{schema_string}"
end
end
end
end