Skip to content

Commit

Permalink
(CAT-2164) Correct yaml_syntax_validator to error on empty file
Browse files Browse the repository at this point in the history
Previously empty yaml files would pass and be accepted as valid when PDK validate was run.
However this was contrasted by Puppet and the puppetserver requiring files to always contain a valid yaml and so we are updating the pdk to be in line with this.
  • Loading branch information
david22swan committed Dec 11, 2024
1 parent ed8714c commit f622f02
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions lib/pdk/validate/yaml/yaml_syntax_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,25 @@ def validate_target(report, target)
end

begin
::YAML.safe_load(PDK::Util::Filesystem.read_file(target), permitted_classes: YAML_ALLOWLISTED_CLASSES, permitted_symbols: [], aliases: true)

report.add_event(
file: target,
source: name,
state: :passed,
severity: 'ok'
)
0
data = ::YAML.safe_load(PDK::Util::Filesystem.read_file(target), permitted_classes: YAML_ALLOWLISTED_CLASSES, permitted_symbols: [], aliases: true)
if data.is_a?(Hash)
report.add_event(
file: target,
source: name,
state: :passed,
severity: 'ok'
)
0
else
report.add_event(

Check warning on line 62 in lib/pdk/validate/yaml/yaml_syntax_validator.rb

View check run for this annotation

Codecov / codecov/patch

lib/pdk/validate/yaml/yaml_syntax_validator.rb#L62

Added line #L62 was not covered by tests
file: target,
source: name,
state: :failure,
severity: 'error',
message: format(' File does not contain a valid YAML hash.')
)
1

Check warning on line 69 in lib/pdk/validate/yaml/yaml_syntax_validator.rb

View check run for this annotation

Codecov / codecov/patch

lib/pdk/validate/yaml/yaml_syntax_validator.rb#L69

Added line #L69 was not covered by tests
end
rescue Psych::SyntaxError => e
report.add_event(
file: target,
Expand Down

0 comments on commit f622f02

Please sign in to comment.