lib/puppet-check/data_parser.rb in puppet-check-1.3.0 vs lib/puppet-check/data_parser.rb in puppet-check-1.3.1
- old
+ new
@@ -48,13 +48,15 @@
# check for required keys
%w(name version author license summary source dependencies).each do |key|
errors.push("Required field '#{key}' not found.") unless parsed.key?(key)
end
- # check for duplicate dependencies and requirements
+ # check for duplicate dependencies and requirements, and that both are an array of hashes if they exist
%w(requirements dependencies).each do |key|
next unless parsed.key?(key)
+ next errors.push("Field '#{key}' is not an array of hashes.") unless (parsed[key].is_a? Array) && (parsed[key].empty? || (parsed[key][0].is_a? Hash))
+
names = []
parsed[key].each do |req_dep|
name = req_dep['name']
errors.push("Duplicate #{key} on #{name}.") if names.include?(name)
names << name
@@ -70,11 +72,40 @@
errors.push('Summary exceeds 144 characters.') if parsed.key?('summary') && parsed['summary'].size > 144
next PuppetCheck.error_files.push("#{file}:\n#{errors.join("\n")}") unless errors.empty?
# check for warnings
- # check for operatingsystem_support
- warnings.push('Recommended field \'operatingsystem_support\' not found.') unless parsed.key?('operatingsystem_support')
+ # check for operatingsystem_support hash array
+ if parsed.key?('operatingsystem_support')
+ # check if operatingsystem_support array is actually empty
+ if !(parsed['operatingsystem_support'].is_a? Array) || parsed['operatingsystem_support'].empty? || (!parsed['operatingsystem_support'].empty? && !(parsed['operatingsystem_support'][0].is_a? Hash))
+ warnings.push('Recommended field \'operatingsystem\' not found.')
+ warnings.push('Recommended field \'operatingsystemrelease\' not found.')
+ else
+ # check for operatingsystem string
+ if parsed['operatingsystem_support'][0].key?('operatingsystem')
+ warnings.push('Field \'operatingsystem\' is not a string.') unless parsed['operatingsystem_support'][0]['operatingsystem'].is_a? String
+ else
+ warnings.push('Recommended field \'operatingsystem\' not found.')
+ end
+ # check for operatingsystemrelease string array
+ if parsed['operatingsystem_support'][0].key?('operatingsystemrelease')
+ warnings.push('Field \'operatingsystemrelease\' is not a string array.') unless parsed['operatingsystem_support'][0]['operatingsystemrelease'][0].is_a? String
+ else
+ warnings.push('Recommended field \'operatingsystemrelease\' not found.')
+ end
+ end
+ else
+ warnings.push('Recommended field \'operatingsystem_support\' not found.')
+ end
+
+ # check for requirement and dependency upper bounds
+ %w(requirements dependencies).each do |key|
+ next if parsed[key].empty?
+ parsed[key].each do |req_dep|
+ warnings.push("'#{req_dep['name']}' is missing an upper bound.") unless req_dep['version_requirement'].include?('<')
+ end
+ end
# check for spdx license (rubygems/util/licenses for rubygems >= 2.5 in the far future)
if parsed.key?('license') && !SpdxLicenses.exist?(parsed['license']) && parsed['license'] !~ /[pP]roprietary/
warnings.push("License identifier '#{parsed['license']}' is not in the SPDX list: http://spdx.org/licenses/")
end