puppet-check 2.5.0 → 2.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +1 -1
- data/lib/puppet-check/data_parser.rb +29 -15
- data/lib/puppet-check/puppet_parser.rb +3 -3
- data/lib/puppet-check/rspec_puppet_support.rb +1 -1
- data/lib/puppet-check/ruby_parser.rb +8 -3
- data/lib/puppet_check.rb +11 -9
- data/puppet-check.gemspec +1 -1
- data/spec/fixtures/hieradata/decrypt_error.eyaml +3 -0
- data/spec/fixtures/hieradata/nested_array.eyaml +6 -0
- data/spec/puppet-check/cli_spec.rb +2 -2
- data/spec/puppet-check/data_parser_spec.rb +97 -39
- data/spec/puppet-check/puppet_parser_spec.rb +31 -31
- data/spec/puppet-check/regression_check_spec.rb +6 -6
- data/spec/puppet-check/rspec_puppet_support_spec.rb +5 -5
- data/spec/puppet-check/ruby_parser_spec.rb +33 -33
- data/spec/puppet-check/tasks_spec.rb +3 -3
- data/spec/puppet_check_spec.rb +50 -15
- data/spec/spec_helper.rb +3 -16
- data/spec/system/system_spec.rb +7 -7
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 98b3c25f3adb4837ec7ce74efb4e06c422defab2a7360646b4daae7dda962c0f
|
|
4
|
+
data.tar.gz: 4814ad9b99fd205914ad1b976280d70479264ebff708aa0390a22346d1c4c1e6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 714bc3ea74a76dd03a2dac33274e12b236f898cfe5f6257ea1a04dd7f0a61124d4509d1b73e2c74f2bf8b8d987aa3343ece7fce5a8e387a211464f400e7aecc7
|
|
7
|
+
data.tar.gz: 9c0737fee70f019f5189a499981b4a54b1449cb43d297b92ce2e8da5fe13dfa7194b4239db4417394626747de8acc250b3d5388b20687a469998c02d4b46418d
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
### 2.5.2
|
|
2
|
+
- Fix incorrect exit code `0` when `octocatalog` detects catalog compilation failure.
|
|
3
|
+
- Avoid mutation of and optimize Rubocop argument interfacing.
|
|
4
|
+
- Fix existing module install check when using Puppet Forge source for RSpec.
|
|
5
|
+
- Upgrade EYAML validation functionality from beta to release candidate.
|
|
6
|
+
|
|
7
|
+
### 2.5.1
|
|
8
|
+
- Fix explicit `fail_on_warnings` default value assignment.
|
|
9
|
+
- Improve message transformation for Puppet::Face errors and warnings.
|
|
10
|
+
- Improve EYAML certification validation check.
|
|
11
|
+
- Verify that files to be validated are readable by current user.
|
|
12
|
+
- Fix Puppet 5.4-6.4 syntax error output format.
|
|
13
|
+
|
|
1
14
|
### 2.5.0
|
|
2
15
|
- Minimum Ruby version increased to 3.1.
|
|
3
16
|
- Minimum Puppet-Lint increased to 5.0.
|
data/README.md
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
## Description
|
|
14
14
|
Puppet Check is a gem that provides a comprehensive, streamlined, and efficient analysis of the syntax, style, and validity of your entire Puppet code and data.
|
|
15
15
|
|
|
16
|
-
**IMPORTANT**: The current support for encrypted yaml validation is experimental and should be considered a
|
|
16
|
+
**IMPORTANT**: The current support for encrypted yaml validation is semi-experimental and should be considered a release candidate feature as of 2.5.2.
|
|
17
17
|
|
|
18
18
|
### Former Method for Code and Data Checks
|
|
19
19
|

|
|
@@ -25,6 +25,7 @@ class DataParser
|
|
|
25
25
|
# checks eyaml (.eyaml/.eyml)
|
|
26
26
|
def self.eyaml(files, public, private)
|
|
27
27
|
require 'openssl'
|
|
28
|
+
require 'base64'
|
|
28
29
|
|
|
29
30
|
# keys specified?
|
|
30
31
|
if public.nil? || private.nil?
|
|
@@ -33,43 +34,56 @@ class DataParser
|
|
|
33
34
|
end
|
|
34
35
|
|
|
35
36
|
# keys exist?
|
|
36
|
-
unless File.
|
|
37
|
+
unless File.readable?(public) && File.readable?(private)
|
|
37
38
|
PuppetCheck.files[:ignored].concat(files)
|
|
38
|
-
return warn 'Specified Public X509 and/or Private RSA PKCS7 certs do not exist. EYAML checks will not be executed.'
|
|
39
|
+
return warn 'Specified Public X509 and/or Private RSA PKCS7 certs do not exist or are not readable. EYAML checks will not be executed.'
|
|
39
40
|
end
|
|
40
41
|
|
|
41
42
|
# setup decryption
|
|
42
43
|
rsa = OpenSSL::PKey::RSA.new(File.read(private))
|
|
43
44
|
x509 = OpenSSL::X509::Certificate.new(File.read(public))
|
|
44
45
|
|
|
46
|
+
# iterate through files and decrypt eyaml values
|
|
45
47
|
files.each do |file|
|
|
46
|
-
#
|
|
48
|
+
# load the file
|
|
47
49
|
parsed = YAML.safe_load_file(file, permitted_classes: [Symbol], permitted_symbols: [], aliases: true)
|
|
48
50
|
|
|
49
|
-
#
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
# decrypt the encoded yaml
|
|
53
|
-
# decrypted = OpenSSL::PKCS7.new(File.read(file)).decrypt(rsa, x509)
|
|
54
|
-
|
|
55
|
-
# check decoded eyaml syntax
|
|
56
|
-
# decoded = YAML.safe_load(decrypted)
|
|
57
|
-
|
|
58
|
-
# merge data hashes
|
|
59
|
-
# parsed = merge(parsed, decoded)
|
|
51
|
+
# decrypt any ENC[PKCS7,...] leaf values found in the parsed structure
|
|
52
|
+
decoded = decrypt_eyaml(parsed, rsa, x509)
|
|
60
53
|
rescue StandardError => err
|
|
61
54
|
PuppetCheck.files[:errors][file] = err.to_s.gsub("(#{file}): ", '').split("\n")
|
|
62
55
|
else
|
|
63
56
|
warnings = []
|
|
64
57
|
|
|
65
58
|
# perform some rudimentary hiera checks if data exists and is hieradata
|
|
66
|
-
warnings = hiera(
|
|
59
|
+
warnings = hiera(decoded, file) if decoded
|
|
67
60
|
|
|
68
61
|
next PuppetCheck.files[:warnings][file] = warnings unless warnings.empty?
|
|
69
62
|
PuppetCheck.files[:clean].push(file.to_s)
|
|
70
63
|
end
|
|
71
64
|
end
|
|
72
65
|
|
|
66
|
+
# recursively decrypts ENC[PKCS7,...] leaf values in a parsed eyaml structure
|
|
67
|
+
private_class_method def self.decrypt_eyaml(data, rsa, x509)
|
|
68
|
+
case data
|
|
69
|
+
when Hash
|
|
70
|
+
# recurse into hash values, keys are never encrypted
|
|
71
|
+
data.transform_values { |v| decrypt_eyaml(v, rsa, x509) }
|
|
72
|
+
when Array
|
|
73
|
+
# recurse into array elements
|
|
74
|
+
data.map { |v| decrypt_eyaml(v, rsa, x509) }
|
|
75
|
+
when String
|
|
76
|
+
# leave plain (non-ENC) strings untouched
|
|
77
|
+
match = data.match(/\AENC\[PKCS7,(.+)\]\z/m)
|
|
78
|
+
return data unless match
|
|
79
|
+
|
|
80
|
+
# decode the base64 payload to DER and decrypt
|
|
81
|
+
OpenSSL::PKCS7.new(Base64.decode64(match[1])).decrypt(rsa, x509)
|
|
82
|
+
else
|
|
83
|
+
data
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
73
87
|
# metadata consts
|
|
74
88
|
REQUIRED_KEYS = %w[name version author license summary source dependencies].freeze
|
|
75
89
|
REQ_DEP_KEYS = %w[requirements dependencies].freeze
|
|
@@ -32,12 +32,12 @@ class PuppetParser
|
|
|
32
32
|
new_error = Puppet::Face[:parser, :current].validate(file)
|
|
33
33
|
# puppet 6.5 output format is now a hash from the face api
|
|
34
34
|
if Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('6.5.0') && new_error != {}
|
|
35
|
-
messages.concat(new_error.values.map(&:to_s).map { |error| error.gsub(
|
|
35
|
+
messages.concat(new_error.values.map(&:to_s).map { |error| error.gsub(Regexp.escape(" (file: #{File.absolute_path(file)}(, |))"), '') }.map { |error| error.gsub('Could not parse for environment *root*: ', '') })
|
|
36
36
|
end
|
|
37
37
|
# this is the actual error that we need to rescue Puppet::Face from
|
|
38
38
|
rescue SystemExit
|
|
39
39
|
# puppet 5.4-6.4 has a new validator output format and eof errors have fake dir env info
|
|
40
|
-
messages.concat(errors.map(&:to_s).
|
|
40
|
+
messages.concat(errors.map(&:to_s).map { |error| error.gsub(Regexp.escape("file: #{File.absolute_path(file)}(, |))"), '') }.map { |error| error.gsub(/Could not parse.*: /, '') })
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
Puppet::Util::Log.close_all
|
|
@@ -50,7 +50,7 @@ class PuppetParser
|
|
|
50
50
|
# weirdly puppet >= 6.5 still does not return warnings and logs them instead unlike errors
|
|
51
51
|
unless errors.empty?
|
|
52
52
|
# puppet >= 5.4 has a new validator output format
|
|
53
|
-
warnings.concat(errors.map(&:to_s).join("\n").gsub("file: #{File.absolute_path(file)}, ", '').split("\n"))
|
|
53
|
+
warnings.concat(errors.map(&:to_s).join("\n").gsub(Regexp.escape("file: #{File.absolute_path(file)}(, |))"), '').split("\n"))
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
# check puppet style
|
|
@@ -97,7 +97,7 @@ class RSpecPuppetSupport
|
|
|
97
97
|
# download external module dependency with forge
|
|
98
98
|
private_class_method def self.forge(forge_name, args = '')
|
|
99
99
|
# is the module present? do an upgrade; otherwise, do an install
|
|
100
|
-
subcommand = File.directory?("spec/fixtures/modules/#{forge_name}") ? 'upgrade' : 'install'
|
|
100
|
+
subcommand = File.directory?("spec/fixtures/modules/#{forge_name.split('-').last}") ? 'upgrade' : 'install'
|
|
101
101
|
spawn("puppet module #{subcommand} --modulepath spec/fixtures/modules/ #{args} #{forge_name}")
|
|
102
102
|
end
|
|
103
103
|
|
|
@@ -23,10 +23,15 @@ class RubyParser
|
|
|
23
23
|
# check ruby style
|
|
24
24
|
if style
|
|
25
25
|
# add rubocop rspec plugin if the file is a spec
|
|
26
|
-
|
|
26
|
+
if file =~ /_spec\.rb$/
|
|
27
|
+
# invoke RuboCop with rspec plugin
|
|
28
|
+
rubocop_warnings = Utils.capture_stdout { rubocop_cli.run(rc_args + ['--plugin', 'rubocop-rspec','--enable-pending-cops', '--plugin', 'rubocop-performance', '--format', 'json', file]) }
|
|
29
|
+
else
|
|
30
|
+
# invoke rubocop
|
|
31
|
+
rubocop_warnings = Utils.capture_stdout { rubocop_cli.run(rc_args + ['--enable-pending-cops', '--plugin', 'rubocop-performance', '--format', 'json', file]) }
|
|
32
|
+
end
|
|
27
33
|
|
|
28
|
-
#
|
|
29
|
-
rubocop_warnings = Utils.capture_stdout { rubocop_cli.run(rc_args + ['--enable-pending-cops', '--plugin', 'rubocop-performance', '--format', 'json', file]) }
|
|
34
|
+
# parse rubocop offenses' structured JSON output
|
|
30
35
|
rubocop_offenses = JSON.parse(rubocop_warnings)['files'][0]['offenses'].map { |warning| "#{warning['location']['line']}:#{warning['location']['column']} #{warning['message']}" }
|
|
31
36
|
|
|
32
37
|
# check Reek using examiner api
|
data/lib/puppet_check.rb
CHANGED
|
@@ -42,12 +42,15 @@ class PuppetCheck
|
|
|
42
42
|
# if octocatalog-diff is not installed then continue immediately
|
|
43
43
|
rescue NameError
|
|
44
44
|
puts 'puppet-check: immediately continuing to results'
|
|
45
|
+
0
|
|
45
46
|
# smoke check failure? output message and return 2
|
|
46
47
|
rescue OctocatalogDiff::Errors::CatalogError => err
|
|
47
48
|
puts 'There was a smoke check error:'
|
|
48
49
|
puts err
|
|
49
50
|
puts catalog.error_message unless catalog.valid?
|
|
50
51
|
2
|
|
52
|
+
else
|
|
53
|
+
0
|
|
51
54
|
end
|
|
52
55
|
# perform regression checks if there were no errors and the user desires
|
|
53
56
|
# begin
|
|
@@ -61,7 +64,6 @@ class PuppetCheck
|
|
|
61
64
|
|
|
62
65
|
# code to output differences in catalog?
|
|
63
66
|
# everything passed? return 0
|
|
64
|
-
0
|
|
65
67
|
else
|
|
66
68
|
# error files? return 2
|
|
67
69
|
2
|
|
@@ -75,7 +77,7 @@ class PuppetCheck
|
|
|
75
77
|
# return settings with defaults where unspecified
|
|
76
78
|
{
|
|
77
79
|
# initialize fail on warning, style check, and regression check bools
|
|
78
|
-
|
|
80
|
+
fail_on_warnings: false,
|
|
79
81
|
style: false,
|
|
80
82
|
smoke: false,
|
|
81
83
|
regression: false,
|
|
@@ -101,11 +103,11 @@ class PuppetCheck
|
|
|
101
103
|
paths.uniq.each do |path|
|
|
102
104
|
if File.directory?(path)
|
|
103
105
|
# glob all files in directory and concat them
|
|
104
|
-
files.concat(Dir.glob("#{path}/**/*").select { |subpath| File.file?(subpath) && !subpath.include?('fixtures') })
|
|
105
|
-
elsif File.file?(path) && !path.include?('fixtures')
|
|
106
|
+
files.concat(Dir.glob("#{path}/**/*").select { |subpath| File.file?(subpath) && File.readable?(subpath) && !subpath.include?('fixtures') })
|
|
107
|
+
elsif File.file?(path) && File.readable?(path) && !path.include?('fixtures')
|
|
106
108
|
files.push(path)
|
|
107
109
|
else
|
|
108
|
-
warn "puppet-check: #{path} is not a directory, file, or symlink, and will not be considered during parsing"
|
|
110
|
+
warn "puppet-check: #{path} is not a readable directory, file, or symlink, and will not be considered during parsing"
|
|
109
111
|
end
|
|
110
112
|
end
|
|
111
113
|
|
|
@@ -120,14 +122,14 @@ class PuppetCheck
|
|
|
120
122
|
manifests, files = files.partition { |file| File.extname(file) == '.pp' }
|
|
121
123
|
PuppetParser.manifest(manifests, style, puppetlint_args) unless manifests.empty?
|
|
122
124
|
# check puppet templates
|
|
123
|
-
|
|
124
|
-
PuppetParser.template(
|
|
125
|
+
epp, files = files.partition { |file| File.extname(file) == '.epp' }
|
|
126
|
+
PuppetParser.template(epp) unless epp.empty?
|
|
125
127
|
# check ruby files
|
|
126
128
|
rubies, files = files.partition { |file| File.extname(file) == '.rb' }
|
|
127
129
|
RubyParser.ruby(rubies, style, rubocop_args) unless rubies.empty?
|
|
128
130
|
# check ruby templates
|
|
129
|
-
|
|
130
|
-
RubyParser.template(
|
|
131
|
+
erb, files = files.partition { |file| File.extname(file) == '.erb' }
|
|
132
|
+
RubyParser.template(erb) unless erb.empty?
|
|
131
133
|
# check yaml data
|
|
132
134
|
yamls, files = files.partition { |file| File.extname(file) =~ /\.ya?ml$/ }
|
|
133
135
|
DataParser.yaml(yamls) unless yamls.empty?
|
data/puppet-check.gemspec
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Gem::Specification.new do |spec|
|
|
2
2
|
spec.name = 'puppet-check'
|
|
3
|
-
spec.version = '2.5.
|
|
3
|
+
spec.version = '2.5.2'
|
|
4
4
|
spec.authors = ['Matt Schuchard']
|
|
5
5
|
spec.description = 'Puppet Check is a gem that provides a comprehensive, streamlined, and efficient analysis of the syntax, style, and validity of your entire Puppet code and data.'
|
|
6
6
|
spec.summary = 'A streamlined comprehensive set of checks for your entire Puppet code and data'
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
---
|
|
2
|
+
items:
|
|
3
|
+
- name: one
|
|
4
|
+
secret: ENC[PKCS7,MIIBeQYJKoZIhvcNAQcDoIIBajCCAWYCAQAxggEhMIIBHQIBADAFMAACAQEwDQYJKoZIhvcNAQEBBQAEggEAWYkSR19bdTGCu3NUMRGjHUIkXidzM4ejpICm7voB4JLUYyrwPxnvb8d761VA6JJwLe6dPmppm1x62k6Sp9HXyP3BqkhBlshLsgbNSbhMoLBPxfpjQhRTDFbeqZq35aY6grqj25AYB18Grfja8RoSK4jLHBECPJr0lUgW4qBANgV7KcaZndwxyDfTPFA3vCtc4r1l/r4Bg9esyV3ClJHP5A7bOmw38aibGcu1O4CHLEHCt3plvqrF7vElSFBJi62I7omGvdJitY+CVe6eTJiHLn3HnP9jeRGdRiC2eGhS+A7sE8JXK3n/ZtKFiH78payBlU6BWolgapBC3RnFw9jabTA8BgkqhkiG9w0BBwEwHQYJYIZIAWUDBAEqBBB/Ep4/M8NuRlUOin0nQKjXgBArdhX8G2RtUEdfdl3ujD89]
|
|
5
|
+
- name: two
|
|
6
|
+
secret: plain
|
|
@@ -6,7 +6,7 @@ describe PuppetCheck::CLI do
|
|
|
6
6
|
it 'targets the current working directory if no paths were specified' do
|
|
7
7
|
expect { PuppetCheck::CLI.run(%w[--fail-on-warnings]) }.not_to raise_exception
|
|
8
8
|
expect(PuppetCheck.files[:clean].length).to eql(29)
|
|
9
|
-
if
|
|
9
|
+
if CI_ENV
|
|
10
10
|
expect(PuppetCheck.files[:ignored].length).to eql(8)
|
|
11
11
|
else
|
|
12
12
|
expect(PuppetCheck.files[:ignored].length).to eql(7)
|
|
@@ -40,7 +40,7 @@ describe PuppetCheck::CLI do
|
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
it 'correctly loads a .puppet-lint.rc' do
|
|
43
|
-
expect(PuppetCheck::CLI.send(:parse, %W[-c #{
|
|
43
|
+
expect(PuppetCheck::CLI.send(:parse, %W[-c #{FIXTURES_DIR}/manifests/.puppet-lint.rc])).to include(puppetlint_args: ['--puppetlint-arg-one', '--puppetlint-arg-two'])
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
it 'correctly parses Rubocop arguments' do
|
|
@@ -13,24 +13,24 @@ describe DataParser do
|
|
|
13
13
|
|
|
14
14
|
context '.yaml' do
|
|
15
15
|
it 'puts a bad syntax yaml file in the error files hash' do
|
|
16
|
-
DataParser.yaml(["#{
|
|
17
|
-
expect(PuppetCheck.files[:errors].keys).to eql(["#{
|
|
18
|
-
expect(PuppetCheck.files[:errors]["#{
|
|
16
|
+
DataParser.yaml(["#{FIXTURES_DIR}hieradata/syntax.yaml"])
|
|
17
|
+
expect(PuppetCheck.files[:errors].keys).to eql(["#{FIXTURES_DIR}hieradata/syntax.yaml"])
|
|
18
|
+
expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}hieradata/syntax.yaml"].join("\n")).to match(/^block sequence entries are not allowed/)
|
|
19
19
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
20
20
|
expect(PuppetCheck.files[:clean]).to eql([])
|
|
21
21
|
end
|
|
22
22
|
it 'puts a good yaml file with potential hiera issues in the warning files array' do
|
|
23
|
-
DataParser.yaml(["#{
|
|
23
|
+
DataParser.yaml(["#{FIXTURES_DIR}hieradata/style.yaml"])
|
|
24
24
|
expect(PuppetCheck.files[:errors]).to eql({})
|
|
25
|
-
expect(PuppetCheck.files[:warnings].keys).to eql(["#{
|
|
26
|
-
expect(PuppetCheck.files[:warnings]["#{
|
|
25
|
+
expect(PuppetCheck.files[:warnings].keys).to eql(["#{FIXTURES_DIR}hieradata/style.yaml"])
|
|
26
|
+
expect(PuppetCheck.files[:warnings]["#{FIXTURES_DIR}hieradata/style.yaml"].join("\n")).to match(/^Value\(s\) missing in key.*\nValue\(s\) missing in key.*\nThe string --- appears more than once in this data and Hiera may fail to parse it correctly/)
|
|
27
27
|
expect(PuppetCheck.files[:clean]).to eql([])
|
|
28
28
|
end
|
|
29
29
|
it 'puts a good yaml file in the clean files array' do
|
|
30
|
-
DataParser.yaml(["#{
|
|
30
|
+
DataParser.yaml(["#{FIXTURES_DIR}hieradata/good.yaml"])
|
|
31
31
|
expect(PuppetCheck.files[:errors]).to eql({})
|
|
32
32
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
33
|
-
expect(PuppetCheck.files[:clean]).to eql(["#{
|
|
33
|
+
expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}hieradata/good.yaml"])
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
|
|
@@ -42,83 +42,141 @@ describe DataParser do
|
|
|
42
42
|
expect { DataParser.eyaml(['foo.eyaml'], 'public.pem', nil) }.to output("Public X509 and/or Private RSA PKCS7 certs were not specified. EYAML checks will not be executed.\n").to_stderr
|
|
43
43
|
end
|
|
44
44
|
it 'returns a warning if the public key or private key are not existing files' do
|
|
45
|
-
expect { DataParser.eyaml(['foo.eyaml'], 'public.pem', 'private.pem') }.to output("Specified Public X509 and/or Private RSA PKCS7 certs do not exist. EYAML checks will not be executed.\n").to_stderr
|
|
45
|
+
expect { DataParser.eyaml(['foo.eyaml'], 'public.pem', 'private.pem') }.to output("Specified Public X509 and/or Private RSA PKCS7 certs do not exist or are not readable. EYAML checks will not be executed.\n").to_stderr
|
|
46
46
|
end
|
|
47
47
|
it 'puts a bad syntax eyaml file in the error files hash' do
|
|
48
|
-
DataParser.eyaml(["#{
|
|
49
|
-
expect(PuppetCheck.files[:errors].keys).to eql(["#{
|
|
50
|
-
expect(PuppetCheck.files[:errors]["#{
|
|
48
|
+
DataParser.eyaml(["#{FIXTURES_DIR}hieradata/syntax.eyaml"], "#{FIXTURES_DIR}keys/public_key.pkcs7.pem", "#{FIXTURES_DIR}keys/private_key.pkcs7.pem")
|
|
49
|
+
expect(PuppetCheck.files[:errors].keys).to eql(["#{FIXTURES_DIR}hieradata/syntax.eyaml"])
|
|
50
|
+
expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}hieradata/syntax.eyaml"].join("\n")).to match(/^block sequence entries are not allowed/)
|
|
51
51
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
52
52
|
expect(PuppetCheck.files[:clean]).to eql([])
|
|
53
53
|
end
|
|
54
54
|
it 'puts a good eyaml file with potential hiera issues in the warning files array' do
|
|
55
|
-
DataParser.eyaml(["#{
|
|
55
|
+
DataParser.eyaml(["#{FIXTURES_DIR}hieradata/style.eyaml"], "#{FIXTURES_DIR}keys/public_key.pkcs7.pem", "#{FIXTURES_DIR}keys/private_key.pkcs7.pem")
|
|
56
56
|
expect(PuppetCheck.files[:errors]).to eql({})
|
|
57
|
-
expect(PuppetCheck.files[:warnings].keys).to eql(["#{
|
|
58
|
-
expect(PuppetCheck.files[:warnings]["#{
|
|
57
|
+
expect(PuppetCheck.files[:warnings].keys).to eql(["#{FIXTURES_DIR}hieradata/style.eyaml"])
|
|
58
|
+
expect(PuppetCheck.files[:warnings]["#{FIXTURES_DIR}hieradata/style.eyaml"].join("\n")).to match(/^Value\(s\) missing in key.*\nValue\(s\) missing in key.*\nThe string --- appears more than once in this data and Hiera may fail to parse it correctly/)
|
|
59
59
|
expect(PuppetCheck.files[:clean]).to eql([])
|
|
60
60
|
end
|
|
61
61
|
it 'puts a good eyaml file in the clean files array' do
|
|
62
|
-
DataParser.eyaml(["#{
|
|
62
|
+
DataParser.eyaml(["#{FIXTURES_DIR}hieradata/good.eyaml"], "#{FIXTURES_DIR}keys/public_key.pkcs7.pem", "#{FIXTURES_DIR}keys/private_key.pkcs7.pem")
|
|
63
63
|
expect(PuppetCheck.files[:errors]).to eql({})
|
|
64
64
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
65
|
-
expect(PuppetCheck.files[:clean]).to eql(["#{
|
|
65
|
+
expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}hieradata/good.eyaml"])
|
|
66
|
+
end
|
|
67
|
+
it 'puts an eyaml file with an undecryptable PKCS7 payload in the error files hash; distinctly from a YAML syntax error' do
|
|
68
|
+
DataParser.eyaml(["#{FIXTURES_DIR}hieradata/decrypt_error.eyaml"], "#{FIXTURES_DIR}keys/public_key.pkcs7.pem", "#{FIXTURES_DIR}keys/private_key.pkcs7.pem")
|
|
69
|
+
expect(PuppetCheck.files[:errors].keys).to eql(["#{FIXTURES_DIR}hieradata/decrypt_error.eyaml"])
|
|
70
|
+
expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}hieradata/decrypt_error.eyaml"].join("\n")).to match(/PKCS7/i)
|
|
71
|
+
expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}hieradata/decrypt_error.eyaml"].join("\n")).not_to match(/^block sequence entries are not allowed/)
|
|
72
|
+
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
73
|
+
expect(PuppetCheck.files[:clean]).to eql([])
|
|
74
|
+
end
|
|
75
|
+
it 'decrypts an ENC[PKCS7,...] value nested inside an array of hashes and puts the file in the clean files array' do
|
|
76
|
+
DataParser.eyaml(["#{FIXTURES_DIR}hieradata/nested_array.eyaml"], "#{FIXTURES_DIR}keys/public_key.pkcs7.pem", "#{FIXTURES_DIR}keys/private_key.pkcs7.pem")
|
|
77
|
+
expect(PuppetCheck.files[:errors]).to eql({})
|
|
78
|
+
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
79
|
+
expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}hieradata/nested_array.eyaml"])
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
context '.decrypt_eyaml' do
|
|
84
|
+
before(:all) do
|
|
85
|
+
require 'openssl'
|
|
86
|
+
require 'base64'
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
let(:rsa) { OpenSSL::PKey::RSA.new(File.read("#{FIXTURES_DIR}keys/private_key.pkcs7.pem")) }
|
|
90
|
+
let(:x509) { OpenSSL::X509::Certificate.new(File.read("#{FIXTURES_DIR}keys/public_key.pkcs7.pem")) }
|
|
91
|
+
|
|
92
|
+
# encrypts a plaintext value against the fixture cert and wraps it as eyaml expects
|
|
93
|
+
def encrypt(plaintext)
|
|
94
|
+
pkcs7 = OpenSSL::PKCS7.encrypt([x509], plaintext, OpenSSL::Cipher.new('AES-256-CBC'), OpenSSL::PKCS7::BINARY)
|
|
95
|
+
"ENC[PKCS7,#{Base64.strict_encode64(pkcs7.to_der)}]"
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it 'decrypts a single ENC[PKCS7,...] string to its original plaintext' do
|
|
99
|
+
expect(DataParser.send(:decrypt_eyaml, encrypt('puppetcheck'), rsa, x509)).to eql('puppetcheck')
|
|
100
|
+
end
|
|
101
|
+
it 'leaves a plain non-ENC string untouched' do
|
|
102
|
+
expect(DataParser.send(:decrypt_eyaml, 'plaintext value', rsa, x509)).to eql('plaintext value')
|
|
103
|
+
end
|
|
104
|
+
it 'leaves a string that merely resembles but does not fully match the ENC[PKCS7,...] pattern untouched' do
|
|
105
|
+
expect(DataParser.send(:decrypt_eyaml, 'prefix ENC[PKCS7,abc] suffix', rsa, x509)).to eql('prefix ENC[PKCS7,abc] suffix')
|
|
106
|
+
end
|
|
107
|
+
it 'recurses into hash values and decrypts them, while never decrypting hash keys' do
|
|
108
|
+
encrypted = encrypt('secret-value')
|
|
109
|
+
result = DataParser.send(:decrypt_eyaml, { encrypted => 'plain-key-value', 'plain-key' => encrypted }, rsa, x509)
|
|
110
|
+
expect(result.keys).to eql([encrypted, 'plain-key'])
|
|
111
|
+
expect(result[encrypted]).to eql('plain-key-value')
|
|
112
|
+
expect(result['plain-key']).to eql('secret-value')
|
|
113
|
+
end
|
|
114
|
+
it 'recurses into array elements and decrypts them' do
|
|
115
|
+
expect(DataParser.send(:decrypt_eyaml, ['plain', encrypt('array-secret')], rsa, x509)).to eql(['plain', 'array-secret'])
|
|
116
|
+
end
|
|
117
|
+
it 'recurses through nested hash/array/hash structures' do
|
|
118
|
+
expect(DataParser.send(:decrypt_eyaml, { 'list' => [{ 'inner' => encrypt('nested-secret') }] }, rsa, x509)).to eql({ 'list' => [{ 'inner' => 'nested-secret' }] })
|
|
119
|
+
end
|
|
120
|
+
it 'returns non-string/hash/array scalars unchanged' do
|
|
121
|
+
expect(DataParser.send(:decrypt_eyaml, 42, rsa, x509)).to eql(42)
|
|
122
|
+
expect(DataParser.send(:decrypt_eyaml, nil, rsa, x509)).to be_nil
|
|
123
|
+
expect(DataParser.send(:decrypt_eyaml, true, rsa, x509)).to be true
|
|
66
124
|
end
|
|
67
125
|
end
|
|
68
126
|
|
|
69
127
|
context '.json' do
|
|
70
128
|
it 'puts a bad syntax json file in the error files hash' do
|
|
71
|
-
DataParser.json(["#{
|
|
72
|
-
expect(PuppetCheck.files[:errors].keys).to eql(["#{
|
|
73
|
-
expect(PuppetCheck.files[:errors]["#{
|
|
129
|
+
DataParser.json(["#{FIXTURES_DIR}hieradata/syntax.json"])
|
|
130
|
+
expect(PuppetCheck.files[:errors].keys).to eql(["#{FIXTURES_DIR}hieradata/syntax.json"])
|
|
131
|
+
expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}hieradata/syntax.json"].join("\n")).to match(/after object value, got.*at line 3 column 3/)
|
|
74
132
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
75
133
|
expect(PuppetCheck.files[:clean]).to eql([])
|
|
76
134
|
end
|
|
77
135
|
it 'puts a bad metadata json file in the error files hash' do
|
|
78
|
-
DataParser.json(["#{
|
|
79
|
-
expect(PuppetCheck.files[:errors].keys).to eql(["#{
|
|
80
|
-
expect(PuppetCheck.files[:errors]["#{
|
|
136
|
+
DataParser.json(["#{FIXTURES_DIR}metadata_syntax/metadata.json"])
|
|
137
|
+
expect(PuppetCheck.files[:errors].keys).to eql(["#{FIXTURES_DIR}metadata_syntax/metadata.json"])
|
|
138
|
+
expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}metadata_syntax/metadata.json"].join("\n")).to match(/^Required field.*\nField 'requirements'.*\nDuplicate dependencies.*\nDeprecated field.*\nSummary exceeds/)
|
|
81
139
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
82
140
|
expect(PuppetCheck.files[:clean]).to eql([])
|
|
83
141
|
end
|
|
84
142
|
it 'puts a bad style metadata json file in the warning files array' do
|
|
85
|
-
DataParser.json(["#{
|
|
143
|
+
DataParser.json(["#{FIXTURES_DIR}metadata_style/metadata.json"])
|
|
86
144
|
expect(PuppetCheck.files[:errors]).to eql({})
|
|
87
|
-
expect(PuppetCheck.files[:warnings].keys).to eql(["#{
|
|
88
|
-
expect(PuppetCheck.files[:warnings]["#{
|
|
145
|
+
expect(PuppetCheck.files[:warnings].keys).to eql(["#{FIXTURES_DIR}metadata_style/metadata.json"])
|
|
146
|
+
expect(PuppetCheck.files[:warnings]["#{FIXTURES_DIR}metadata_style/metadata.json"].join("\n")).to match(/^'pe' is missing an upper bound.\n.*operatingsystem_support.*\nLicense identifier/)
|
|
89
147
|
expect(PuppetCheck.files[:clean]).to eql([])
|
|
90
148
|
end
|
|
91
149
|
it 'puts another bad style metadata json file in the warning files array' do
|
|
92
|
-
DataParser.json(["#{
|
|
150
|
+
DataParser.json(["#{FIXTURES_DIR}metadata_style_two/metadata.json"])
|
|
93
151
|
expect(PuppetCheck.files[:errors]).to eql({})
|
|
94
|
-
expect(PuppetCheck.files[:warnings].keys).to eql(["#{
|
|
95
|
-
expect(PuppetCheck.files[:warnings]["#{
|
|
152
|
+
expect(PuppetCheck.files[:warnings].keys).to eql(["#{FIXTURES_DIR}metadata_style_two/metadata.json"])
|
|
153
|
+
expect(PuppetCheck.files[:warnings]["#{FIXTURES_DIR}metadata_style_two/metadata.json"].join("\n")).to match(%r{^'puppetlabs/one' has non-semantic versioning.*\n'puppetlabs/two' is missing an upper bound\.\n.*operatingsystem.*\n.*operatingsystemrelease})
|
|
96
154
|
expect(PuppetCheck.files[:clean]).to eql([])
|
|
97
155
|
end
|
|
98
156
|
it 'puts a bad task metadata json file in the warning files array' do
|
|
99
|
-
DataParser.json(["#{
|
|
157
|
+
DataParser.json(["#{FIXTURES_DIR}task_metadata/task_bad.json"])
|
|
100
158
|
expect(PuppetCheck.files[:errors]).to eql({})
|
|
101
|
-
expect(PuppetCheck.files[:warnings].keys).to eql(["#{
|
|
102
|
-
expect(PuppetCheck.files[:warnings]["#{
|
|
159
|
+
expect(PuppetCheck.files[:warnings].keys).to eql(["#{FIXTURES_DIR}task_metadata/task_bad.json"])
|
|
160
|
+
expect(PuppetCheck.files[:warnings]["#{FIXTURES_DIR}task_metadata/task_bad.json"].join("\n")).to match(/^description value is not a String\ninput_method value is not one of environment, stdin, or powershell\nparameters value is not a Hash\npuppet_task_version value is not an Integer\nsupports_noop value is not a Boolean/)
|
|
103
161
|
expect(PuppetCheck.files[:clean]).to eql([])
|
|
104
162
|
end
|
|
105
163
|
it 'puts a good json file in the clean files array' do
|
|
106
|
-
DataParser.json(["#{
|
|
164
|
+
DataParser.json(["#{FIXTURES_DIR}hieradata/good.json"])
|
|
107
165
|
expect(PuppetCheck.files[:errors]).to eql({})
|
|
108
166
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
109
|
-
expect(PuppetCheck.files[:clean]).to eql(["#{
|
|
167
|
+
expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}hieradata/good.json"])
|
|
110
168
|
end
|
|
111
169
|
it 'puts a good metadata json file in the clean files array' do
|
|
112
|
-
DataParser.json(["#{
|
|
170
|
+
DataParser.json(["#{FIXTURES_DIR}metadata_good/metadata.json"])
|
|
113
171
|
expect(PuppetCheck.files[:errors]).to eql({})
|
|
114
172
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
115
|
-
expect(PuppetCheck.files[:clean]).to eql(["#{
|
|
173
|
+
expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}metadata_good/metadata.json"])
|
|
116
174
|
end
|
|
117
175
|
it 'puts a good task metadata json file in the clean files array' do
|
|
118
|
-
DataParser.json(["#{
|
|
176
|
+
DataParser.json(["#{FIXTURES_DIR}task_metadata/task_good.json"])
|
|
119
177
|
expect(PuppetCheck.files[:errors]).to eql({})
|
|
120
178
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
121
|
-
expect(PuppetCheck.files[:clean]).to eql(["#{
|
|
179
|
+
expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}task_metadata/task_good.json"])
|
|
122
180
|
end
|
|
123
181
|
end
|
|
124
|
-
end
|
|
182
|
+
end
|
|
@@ -13,12 +13,12 @@ describe PuppetParser do
|
|
|
13
13
|
|
|
14
14
|
context '.manifest' do
|
|
15
15
|
it 'puts a bad syntax Puppet manifest in the error files hash' do
|
|
16
|
-
PuppetParser.manifest(["#{
|
|
17
|
-
expect(PuppetCheck.files[:errors].keys).to eql(["#{
|
|
16
|
+
PuppetParser.manifest(["#{FIXTURES_DIR}manifests/syntax.pp"], false, [])
|
|
17
|
+
expect(PuppetCheck.files[:errors].keys).to eql(["#{FIXTURES_DIR}manifests/syntax.pp"])
|
|
18
18
|
if Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('6.5.0')
|
|
19
|
-
expect(PuppetCheck.files[:errors]["#{
|
|
19
|
+
expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}manifests/syntax.pp"].join("\n")).to match(/^Language validation logged 2 errors/)
|
|
20
20
|
else
|
|
21
|
-
expect(PuppetCheck.files[:errors]["#{
|
|
21
|
+
expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}manifests/syntax.pp"].join("\n")).to match(/^This Variable has no effect.*\nIllegal variable name/)
|
|
22
22
|
end
|
|
23
23
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
24
24
|
expect(PuppetCheck.files[:clean]).to eql([])
|
|
@@ -26,77 +26,77 @@ describe PuppetParser do
|
|
|
26
26
|
# puppet 5 api has output issues for this fixture
|
|
27
27
|
unless Gem::Version.new(Puppet::PUPPETVERSION) < Gem::Version.new('6.0.0')
|
|
28
28
|
it 'puts a bad syntax at eof Puppet manifest in the error files hash' do
|
|
29
|
-
PuppetParser.manifest(["#{
|
|
30
|
-
expect(PuppetCheck.files[:errors].keys).to eql(["#{
|
|
31
|
-
expect(PuppetCheck.files[:errors]["#{
|
|
29
|
+
PuppetParser.manifest(["#{FIXTURES_DIR}manifests/eof_syntax.pp"], false, [])
|
|
30
|
+
expect(PuppetCheck.files[:errors].keys).to eql(["#{FIXTURES_DIR}manifests/eof_syntax.pp"])
|
|
31
|
+
expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}manifests/eof_syntax.pp"].join("\n")).to match(/^Syntax error at end of input/)
|
|
32
32
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
33
33
|
expect(PuppetCheck.files[:clean]).to eql([])
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
it 'puts a bad syntax Puppet plan in the error files hash' do
|
|
37
|
-
PuppetParser.manifest(["#{
|
|
38
|
-
expect(PuppetCheck.files[:errors].keys).to eql(["#{
|
|
39
|
-
expect(PuppetCheck.files[:errors]["#{
|
|
37
|
+
PuppetParser.manifest(["#{FIXTURES_DIR}plans/syntax.pp"], false, [])
|
|
38
|
+
expect(PuppetCheck.files[:errors].keys).to eql(["#{FIXTURES_DIR}plans/syntax.pp"])
|
|
39
|
+
expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}plans/syntax.pp"].join("\n")).to match(/^Syntax error at '\)'/)
|
|
40
40
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
41
41
|
expect(PuppetCheck.files[:clean]).to eql([])
|
|
42
42
|
end
|
|
43
43
|
it 'puts a bad parser style and lint style Puppet manifest in the warning files array' do
|
|
44
|
-
PuppetParser.manifest(["#{
|
|
44
|
+
PuppetParser.manifest(["#{FIXTURES_DIR}manifests/style_parser.pp"], true, [])
|
|
45
45
|
expect(PuppetCheck.files[:errors]).to eql({})
|
|
46
|
-
expect(PuppetCheck.files[:warnings].keys).to eql(["#{
|
|
47
|
-
expect(PuppetCheck.files[:warnings]["#{
|
|
46
|
+
expect(PuppetCheck.files[:warnings].keys).to eql(["#{FIXTURES_DIR}manifests/style_parser.pp"])
|
|
47
|
+
expect(PuppetCheck.files[:warnings]["#{FIXTURES_DIR}manifests/style_parser.pp"].join("\n")).to match(/^Unrecognized escape sequence.*\nUnrecognized escape sequence.*\n.*double quoted string containing/)
|
|
48
48
|
expect(PuppetCheck.files[:clean]).to eql([])
|
|
49
49
|
end
|
|
50
50
|
it 'puts a bad lint style Puppet manifest in the warning files array' do
|
|
51
|
-
PuppetParser.manifest(["#{
|
|
51
|
+
PuppetParser.manifest(["#{FIXTURES_DIR}manifests/style_lint.pp"], true, [])
|
|
52
52
|
expect(PuppetCheck.files[:errors]).to eql({})
|
|
53
|
-
expect(PuppetCheck.files[:warnings].keys).to eql(["#{
|
|
54
|
-
expect(PuppetCheck.files[:warnings]["#{
|
|
53
|
+
expect(PuppetCheck.files[:warnings].keys).to eql(["#{FIXTURES_DIR}manifests/style_lint.pp"])
|
|
54
|
+
expect(PuppetCheck.files[:warnings]["#{FIXTURES_DIR}manifests/style_lint.pp"].join("\n")).to match(/(?:indentation of|double quoted string containing).*\n.*(?:indentation of|double quoted string containing)/)
|
|
55
55
|
expect(PuppetCheck.files[:clean]).to eql([])
|
|
56
56
|
end
|
|
57
57
|
it 'puts a bad style Puppet manifest in the clean files array when puppetlint_args ignores its warnings' do
|
|
58
|
-
PuppetParser.manifest(["#{
|
|
58
|
+
PuppetParser.manifest(["#{FIXTURES_DIR}manifests/style_lint.pp"], true, ['--no-double_quoted_strings-check', '--no-arrow_alignment-check'])
|
|
59
59
|
expect(PuppetCheck.files[:errors]).to eql({})
|
|
60
60
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
61
|
-
expect(PuppetCheck.files[:clean]).to eql(["#{
|
|
61
|
+
expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}manifests/style_lint.pp"])
|
|
62
62
|
end
|
|
63
63
|
it 'puts a bad style Puppet plan in the warning files array' do
|
|
64
|
-
PuppetParser.manifest(["#{
|
|
64
|
+
PuppetParser.manifest(["#{FIXTURES_DIR}plans/style.pp"], true, [])
|
|
65
65
|
expect(PuppetCheck.files[:errors]).to eql({})
|
|
66
|
-
expect(PuppetCheck.files[:warnings].keys).to eql(["#{
|
|
67
|
-
expect(PuppetCheck.files[:warnings]["#{
|
|
66
|
+
expect(PuppetCheck.files[:warnings].keys).to eql(["#{FIXTURES_DIR}plans/style.pp"])
|
|
67
|
+
expect(PuppetCheck.files[:warnings]["#{FIXTURES_DIR}plans/style.pp"].join("\n")).to match(/variable not enclosed in {}/)
|
|
68
68
|
expect(PuppetCheck.files[:clean]).to eql([])
|
|
69
69
|
end
|
|
70
70
|
it 'puts a good Puppet manifest in the clean files array' do
|
|
71
|
-
PuppetParser.manifest(["#{
|
|
71
|
+
PuppetParser.manifest(["#{FIXTURES_DIR}manifests/good.pp"], true, [])
|
|
72
72
|
expect(PuppetCheck.files[:errors]).to eql({})
|
|
73
73
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
74
|
-
expect(PuppetCheck.files[:clean]).to eql(["#{
|
|
74
|
+
expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}manifests/good.pp"])
|
|
75
75
|
end
|
|
76
76
|
it 'puts a good Puppet plan in the clean files array' do
|
|
77
|
-
PuppetParser.manifest(["#{
|
|
77
|
+
PuppetParser.manifest(["#{FIXTURES_DIR}plans/good.pp"], true, [])
|
|
78
78
|
expect(PuppetCheck.files[:errors]).to eql({})
|
|
79
79
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
80
|
-
expect(PuppetCheck.files[:clean]).to eql(["#{
|
|
80
|
+
expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}plans/good.pp"])
|
|
81
81
|
end
|
|
82
82
|
it 'throws a well specified error for an invalid PuppetLint argument' do
|
|
83
|
-
expect { PuppetParser.manifest(["#{
|
|
83
|
+
expect { PuppetParser.manifest(["#{FIXTURES_DIR}manifests/style_lint.pp"], true, ['--non-existent', '--does-not-exist']) }.to raise_error(RuntimeError, 'puppet-lint: invalid option supplied among --non-existent --does-not-exist')
|
|
84
84
|
end
|
|
85
85
|
end
|
|
86
86
|
|
|
87
87
|
context '.template' do
|
|
88
88
|
it 'puts a bad syntax Puppet template in the error files hash' do
|
|
89
|
-
PuppetParser.template(["#{
|
|
90
|
-
expect(PuppetCheck.files[:errors].keys).to eql(["#{
|
|
91
|
-
expect(PuppetCheck.files[:errors]["#{
|
|
89
|
+
PuppetParser.template(["#{FIXTURES_DIR}templates/syntax.epp"])
|
|
90
|
+
expect(PuppetCheck.files[:errors].keys).to eql(["#{FIXTURES_DIR}templates/syntax.epp"])
|
|
91
|
+
expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}templates/syntax.epp"].join("\n")).to match(/^This Name has no effect/)
|
|
92
92
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
93
93
|
expect(PuppetCheck.files[:clean]).to eql([])
|
|
94
94
|
end
|
|
95
95
|
it 'puts a good Puppet template in the clean files array' do
|
|
96
|
-
PuppetParser.template(["#{
|
|
96
|
+
PuppetParser.template(["#{FIXTURES_DIR}templates/good.epp"])
|
|
97
97
|
expect(PuppetCheck.files[:errors]).to eql({})
|
|
98
98
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
99
|
-
expect(PuppetCheck.files[:clean]).to eql(["#{
|
|
99
|
+
expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}templates/good.epp"])
|
|
100
100
|
end
|
|
101
101
|
end
|
|
102
102
|
end
|
|
@@ -7,10 +7,10 @@ begin
|
|
|
7
7
|
context '.config' do
|
|
8
8
|
# json gem is messed up for the EOL Ruby versions
|
|
9
9
|
it 'raise an appropriate error if the file is malformed' do
|
|
10
|
-
expect { RegressionCheck.send(:config, "#{
|
|
10
|
+
expect { RegressionCheck.send(:config, "#{FIXTURES_DIR}metadata.json") }.to raise_error(OctocatalogDiff::Errors::ConfigurationFileContentError, 'Configuration must define OctocatalogDiff::Config!')
|
|
11
11
|
end
|
|
12
12
|
it 'loads in a good octocatalog-diff config file' do
|
|
13
|
-
expect { RegressionCheck.send(:config, "#{
|
|
13
|
+
expect { RegressionCheck.send(:config, "#{OCTOCATALOG_DIFF_DIR}octocatalog_diff.cfg.rb") }.not_to raise_exception
|
|
14
14
|
end
|
|
15
15
|
it 'loads in the settings from the file correctly' do
|
|
16
16
|
# TODO
|
|
@@ -19,16 +19,16 @@ begin
|
|
|
19
19
|
|
|
20
20
|
context '.smoke' do
|
|
21
21
|
# octocatalog-diff is returning a blank error for these tests
|
|
22
|
-
unless
|
|
22
|
+
unless CI_ENV
|
|
23
23
|
it 'returns a pass for a successful catalog compilation' do
|
|
24
|
-
expect { RegressionCheck.smoke(['good.example.com'], "#{
|
|
24
|
+
expect { RegressionCheck.smoke(['good.example.com'], "#{OCTOCATALOG_DIFF_DIR}octocatalog_diff.cfg.rb") }.not_to raise_exception
|
|
25
25
|
end
|
|
26
26
|
it 'returns a failure for a catalog with an error' do
|
|
27
|
-
expect { RegressionCheck.smoke(['does_not_exist.example.com'], "#{
|
|
27
|
+
expect { RegressionCheck.smoke(['does_not_exist.example.com'], "#{OCTOCATALOG_DIFF_DIR}octocatalog_diff.cfg.rb") }.to raise_error(OctocatalogDiff::Errors::CatalogError)
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
it 'returns a failure for a good and bad catalog' do
|
|
31
|
-
# RegressionCheck.smoke(['good.example.com', 'syntax_error.example.com'], "#{
|
|
31
|
+
# RegressionCheck.smoke(['good.example.com', 'syntax_error.example.com'], "#{FIXTURES_DIR}octocatalog_diff.cfg.rb")
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
|
|
@@ -5,17 +5,17 @@ require 'fileutils'
|
|
|
5
5
|
describe RSpecPuppetSupport do
|
|
6
6
|
after(:all) do
|
|
7
7
|
# cleanup rspec_puppet_setup
|
|
8
|
-
File.delete("#{
|
|
9
|
-
%w[manifests modules].each { |dir| FileUtils.rm_r("#{
|
|
8
|
+
File.delete("#{FIXTURES_DIR}/spec/spec_helper.rb")
|
|
9
|
+
%w[manifests modules].each { |dir| FileUtils.rm_r("#{FIXTURES_DIR}/spec/fixtures/#{dir}") }
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
context '.run' do
|
|
13
13
|
let(:rspec_puppet_setup) { RSpecPuppetSupport.run }
|
|
14
|
-
before(:each) { Dir.chdir(
|
|
14
|
+
before(:each) { Dir.chdir(FIXTURES_DIR) }
|
|
15
15
|
|
|
16
16
|
it 'creates missing directories, missing site.pp, missing symlinks, and a missing spec_helper' do
|
|
17
17
|
# circle ci and gh actions
|
|
18
|
-
if
|
|
18
|
+
if CI_ENV
|
|
19
19
|
expect { rspec_puppet_setup }.to output("git is not installed and cannot be used to retrieve dependency modules\nsubversion is not installed and cannot be used to retrieve dependency modules\npuppetlabs/gruntmaster has an unspecified, or specified but unsupported, download method.\n").to_stderr
|
|
20
20
|
else
|
|
21
21
|
expect { rspec_puppet_setup }.to output("subversion is not installed and cannot be used to retrieve dependency modules\npuppetlabs/gruntmaster has an unspecified, or specified but unsupported, download method.\n").to_stderr
|
|
@@ -29,7 +29,7 @@ describe RSpecPuppetSupport do
|
|
|
29
29
|
expect(File.file?('spec/spec_helper.rb')).to be true
|
|
30
30
|
|
|
31
31
|
# .dependency_setup
|
|
32
|
-
expect(File.directory?('spec/fixtures/modules/puppetlabs-lvm')).to be true unless
|
|
32
|
+
expect(File.directory?('spec/fixtures/modules/puppetlabs-lvm')).to be true unless CI_ENV
|
|
33
33
|
expect(File.directory?('spec/fixtures/modules/stdlib')).to be true
|
|
34
34
|
end
|
|
35
35
|
end
|
|
@@ -13,96 +13,96 @@ describe RubyParser do
|
|
|
13
13
|
|
|
14
14
|
context '.ruby' do
|
|
15
15
|
it 'puts a bad syntax ruby file in the error files hash' do
|
|
16
|
-
RubyParser.ruby(["#{
|
|
17
|
-
expect(PuppetCheck.files[:errors].keys).to eql(["#{
|
|
18
|
-
expect(PuppetCheck.files[:errors]["#{
|
|
16
|
+
RubyParser.ruby(["#{FIXTURES_DIR}lib/syntax.rb"], false, [])
|
|
17
|
+
expect(PuppetCheck.files[:errors].keys).to eql(["#{FIXTURES_DIR}lib/syntax.rb"])
|
|
18
|
+
expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}lib/syntax.rb"].join("\n")).to match(/^.*syntax error/)
|
|
19
19
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
20
20
|
expect(PuppetCheck.files[:clean]).to eql([])
|
|
21
21
|
end
|
|
22
22
|
it 'puts a bad style ruby file in the warning files array' do
|
|
23
|
-
RubyParser.ruby(["#{
|
|
23
|
+
RubyParser.ruby(["#{FIXTURES_DIR}lib/style.rb"], true, [])
|
|
24
24
|
expect(PuppetCheck.files[:errors]).to eql({})
|
|
25
|
-
expect(PuppetCheck.files[:warnings].keys).to eql(["#{
|
|
26
|
-
unless
|
|
27
|
-
expect(PuppetCheck.files[:warnings]["#{
|
|
25
|
+
expect(PuppetCheck.files[:warnings].keys).to eql(["#{FIXTURES_DIR}lib/style.rb"])
|
|
26
|
+
unless CI_ENV
|
|
27
|
+
expect(PuppetCheck.files[:warnings]["#{FIXTURES_DIR}lib/style.rb"].length).to eql(8)
|
|
28
28
|
else
|
|
29
|
-
expect(PuppetCheck.files[:warnings]["#{
|
|
29
|
+
expect(PuppetCheck.files[:warnings]["#{FIXTURES_DIR}lib/style.rb"].join("\n")).to match(/Useless assignment.*\n.*Use the new.*\n.*Do not introduce.*\n.*Prefer single.*\n.*Remove unnecessary empty.*\n.*Source code comment is empty/)
|
|
30
30
|
end
|
|
31
31
|
expect(PuppetCheck.files[:clean]).to eql([])
|
|
32
32
|
end
|
|
33
33
|
it 'puts a bad style ruby file in the clean files array when rubocop_args ignores its warnings' do
|
|
34
|
-
RubyParser.ruby(["#{
|
|
34
|
+
RubyParser.ruby(["#{FIXTURES_DIR}lib/rubocop_style.rb"], true, ['--except', 'Lint/UselessAssignment,Style/HashSyntax,Style/GlobalVars,Style/StringLiterals'])
|
|
35
35
|
expect(PuppetCheck.files[:errors]).to eql({})
|
|
36
36
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
37
|
-
expect(PuppetCheck.files[:clean]).to eql(["#{
|
|
37
|
+
expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}lib/rubocop_style.rb"])
|
|
38
38
|
end
|
|
39
39
|
it 'puts a good ruby file in the clean files array' do
|
|
40
|
-
RubyParser.ruby(["#{
|
|
40
|
+
RubyParser.ruby(["#{FIXTURES_DIR}lib/good.rb"], true, [])
|
|
41
41
|
expect(PuppetCheck.files[:errors]).to eql({})
|
|
42
42
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
43
|
-
expect(PuppetCheck.files[:clean]).to eql(["#{
|
|
43
|
+
expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}lib/good.rb"])
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
context '.template' do
|
|
48
48
|
it 'puts a bad syntax ruby template file in the error files hash' do
|
|
49
|
-
RubyParser.template(["#{
|
|
50
|
-
expect(PuppetCheck.files[:errors].keys).to eql(["#{
|
|
49
|
+
RubyParser.template(["#{FIXTURES_DIR}templates/syntax.erb"])
|
|
50
|
+
expect(PuppetCheck.files[:errors].keys).to eql(["#{FIXTURES_DIR}templates/syntax.erb"])
|
|
51
51
|
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7')
|
|
52
|
-
expect(PuppetCheck.files[:errors]["#{
|
|
52
|
+
expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}templates/syntax.erb"].join("\n")).to match(/1: syntax error, unexpected.*\n.*ruby/)
|
|
53
53
|
else
|
|
54
|
-
expect(PuppetCheck.files[:errors]["#{
|
|
54
|
+
expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}templates/syntax.erb"].join("\n")).to match(/syntax error, unexpected tIDENTIFIER/)
|
|
55
55
|
end
|
|
56
56
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
57
57
|
expect(PuppetCheck.files[:clean]).to eql([])
|
|
58
58
|
end
|
|
59
59
|
it 'puts a bad style ruby template file in the warning files array' do
|
|
60
|
-
RubyParser.template(["#{
|
|
60
|
+
RubyParser.template(["#{FIXTURES_DIR}templates/style.erb"])
|
|
61
61
|
expect(PuppetCheck.files[:errors]).to eql({})
|
|
62
|
-
expect(PuppetCheck.files[:warnings].keys).to eql(["#{
|
|
63
|
-
expect(PuppetCheck.files[:warnings]["#{
|
|
62
|
+
expect(PuppetCheck.files[:warnings].keys).to eql(["#{FIXTURES_DIR}templates/style.erb"])
|
|
63
|
+
expect(PuppetCheck.files[:warnings]["#{FIXTURES_DIR}templates/style.erb"].join("\n")).to match(/already initialized constant.*\n.*previous definition of/)
|
|
64
64
|
expect(PuppetCheck.files[:clean]).to eql([])
|
|
65
65
|
end
|
|
66
66
|
it 'puts a ruby template file with ignored errors in the clean files array' do
|
|
67
|
-
RubyParser.template(["#{
|
|
67
|
+
RubyParser.template(["#{FIXTURES_DIR}templates/no_method_error.erb"])
|
|
68
68
|
expect(PuppetCheck.files[:errors]).to eql({})
|
|
69
69
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
70
|
-
expect(PuppetCheck.files[:clean]).to eql(["#{
|
|
70
|
+
expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}templates/no_method_error.erb"])
|
|
71
71
|
end
|
|
72
72
|
it 'puts a good ruby template file in the clean files array' do
|
|
73
|
-
RubyParser.template(["#{
|
|
73
|
+
RubyParser.template(["#{FIXTURES_DIR}templates/good.erb"])
|
|
74
74
|
expect(PuppetCheck.files[:errors]).to eql({})
|
|
75
75
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
76
|
-
expect(PuppetCheck.files[:clean]).to eql(["#{
|
|
76
|
+
expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}templates/good.erb"])
|
|
77
77
|
end
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
context '.librarian' do
|
|
81
81
|
it 'puts a bad syntax librarian Puppet file in the error files hash' do
|
|
82
|
-
RubyParser.librarian(["#{
|
|
83
|
-
expect(PuppetCheck.files[:errors].keys).to eql(["#{
|
|
84
|
-
expect(PuppetCheck.files[:errors]["#{
|
|
82
|
+
RubyParser.librarian(["#{FIXTURES_DIR}librarian/Puppetfile_syntax"], false, [])
|
|
83
|
+
expect(PuppetCheck.files[:errors].keys).to eql(["#{FIXTURES_DIR}librarian/Puppetfile_syntax"])
|
|
84
|
+
expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}librarian/Puppetfile_syntax"].join("\n")).to match(/^.*syntax error/)
|
|
85
85
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
86
86
|
expect(PuppetCheck.files[:clean]).to eql([])
|
|
87
87
|
end
|
|
88
88
|
it 'puts a bad style librarian Puppet file in the warning files array' do
|
|
89
|
-
RubyParser.librarian(["#{
|
|
89
|
+
RubyParser.librarian(["#{FIXTURES_DIR}librarian/Puppetfile_style"], true, [])
|
|
90
90
|
expect(PuppetCheck.files[:errors]).to eql({})
|
|
91
|
-
expect(PuppetCheck.files[:warnings].keys).to eql(["#{
|
|
92
|
-
expect(PuppetCheck.files[:warnings]["#{
|
|
91
|
+
expect(PuppetCheck.files[:warnings].keys).to eql(["#{FIXTURES_DIR}librarian/Puppetfile_style"])
|
|
92
|
+
expect(PuppetCheck.files[:warnings]["#{FIXTURES_DIR}librarian/Puppetfile_style"].join("\n")).to match(/Align the arguments.*\n.*Use the new/)
|
|
93
93
|
expect(PuppetCheck.files[:clean]).to eql([])
|
|
94
94
|
end
|
|
95
95
|
it 'puts a bad style librarian Puppet file in the clean files array when rubocop_args ignores its warnings' do
|
|
96
|
-
RubyParser.librarian(["#{
|
|
96
|
+
RubyParser.librarian(["#{FIXTURES_DIR}librarian/Puppetfile_style"], true, ['--except', 'Layout/ArgumentAlignment,Style/HashSyntax'])
|
|
97
97
|
expect(PuppetCheck.files[:errors]).to eql({})
|
|
98
98
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
99
|
-
expect(PuppetCheck.files[:clean]).to eql(["#{
|
|
99
|
+
expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}librarian/Puppetfile_style"])
|
|
100
100
|
end
|
|
101
101
|
it 'puts a good librarian Puppet file in the clean files array' do
|
|
102
|
-
RubyParser.librarian(["#{
|
|
102
|
+
RubyParser.librarian(["#{FIXTURES_DIR}librarian/Puppetfile_good"], true, [])
|
|
103
103
|
expect(PuppetCheck.files[:errors]).to eql({})
|
|
104
104
|
expect(PuppetCheck.files[:warnings]).to eql({})
|
|
105
|
-
expect(PuppetCheck.files[:clean]).to eql(["#{
|
|
105
|
+
expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}librarian/Puppetfile_good"])
|
|
106
106
|
end
|
|
107
107
|
end
|
|
108
108
|
end
|
|
@@ -5,15 +5,15 @@ require_relative '../../lib/puppet-check/tasks'
|
|
|
5
5
|
describe PuppetCheck::Tasks do
|
|
6
6
|
after(:all) do
|
|
7
7
|
# cleanup rspec_puppet_setup
|
|
8
|
-
File.delete("#{
|
|
9
|
-
%w[manifests modules].each { |dir| FileUtils.rm_r("#{
|
|
8
|
+
File.delete("#{FIXTURES_DIR}/spec/spec_helper.rb")
|
|
9
|
+
%w[manifests modules].each { |dir| FileUtils.rm_r("#{FIXTURES_DIR}/spec/fixtures/#{dir}") }
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
context 'puppetcheck:spec' do
|
|
13
13
|
let(:spec_tasks) { Rake::Task[:'puppetcheck:spec'].invoke }
|
|
14
14
|
|
|
15
15
|
it 'executes RSpec and RSpec-Puppet checks in the expected manner' do
|
|
16
|
-
Dir.chdir(
|
|
16
|
+
Dir.chdir(FIXTURES_DIR)
|
|
17
17
|
|
|
18
18
|
# rspec task executed
|
|
19
19
|
expect { spec_tasks }.to output(%r{spec/facter/facter_spec.rb}).to_stdout
|
data/spec/puppet_check_spec.rb
CHANGED
|
@@ -35,7 +35,7 @@ describe PuppetCheck do
|
|
|
35
35
|
it 'returns defaults correctly' do
|
|
36
36
|
expect(PuppetCheck.send(:defaults)).to eql(
|
|
37
37
|
{
|
|
38
|
-
|
|
38
|
+
fail_on_warnings: false,
|
|
39
39
|
style: false,
|
|
40
40
|
smoke: false,
|
|
41
41
|
regression: false,
|
|
@@ -52,7 +52,7 @@ describe PuppetCheck do
|
|
|
52
52
|
|
|
53
53
|
it 'modifies settings correctly' do
|
|
54
54
|
settings = {
|
|
55
|
-
|
|
55
|
+
fail_on_warnings: true,
|
|
56
56
|
style: true,
|
|
57
57
|
smoke: true,
|
|
58
58
|
regression: true,
|
|
@@ -69,7 +69,7 @@ describe PuppetCheck do
|
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
context '.parse_paths' do
|
|
72
|
-
before(:each) { Dir.chdir(
|
|
72
|
+
before(:each) { Dir.chdir(FIXTURES_DIR) }
|
|
73
73
|
|
|
74
74
|
let(:no_files) { PuppetCheck.send(:parse_paths, %w[foo bar baz]) }
|
|
75
75
|
let(:mixed_files) { PuppetCheck.send(:parse_paths, %w[foo lib/good.rb]) }
|
|
@@ -83,7 +83,7 @@ describe PuppetCheck do
|
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
it 'warns on invalid path and correctly parses a valid file path' do
|
|
86
|
-
expect { mixed_files }.to output("puppet-check: foo is not a directory, file, or symlink, and will not be considered during parsing\n").to_stderr
|
|
86
|
+
expect { mixed_files }.to output("puppet-check: foo is not a readable directory, file, or symlink, and will not be considered during parsing\n").to_stderr
|
|
87
87
|
expect(mixed_files[0]).to eql('lib/good.rb')
|
|
88
88
|
end
|
|
89
89
|
|
|
@@ -93,7 +93,7 @@ describe PuppetCheck do
|
|
|
93
93
|
|
|
94
94
|
it 'correctly parses one directory and returns all of its files' do
|
|
95
95
|
dir.each { |file| expect(File.file?(file)).to be true }
|
|
96
|
-
if
|
|
96
|
+
if CI_ENV
|
|
97
97
|
expect(dir.length).to eql(37)
|
|
98
98
|
else
|
|
99
99
|
expect(dir.length).to eql(40)
|
|
@@ -112,16 +112,51 @@ describe PuppetCheck do
|
|
|
112
112
|
end
|
|
113
113
|
|
|
114
114
|
context '.execute_parsers' do
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
115
|
+
before(:each) do
|
|
116
|
+
PuppetCheck.files = { errors: {}, warnings: {}, clean: [], ignored: [] }
|
|
117
|
+
end
|
|
118
|
+
let(:puppet_check) { PuppetCheck.new }
|
|
119
|
+
|
|
120
|
+
it 'correctly routes each file type to the appropriate parser and ignores unrecognized files' do
|
|
121
|
+
expect(PuppetParser).to receive(:manifest).with(['manifests/good.pp'], false, [])
|
|
122
|
+
expect(PuppetParser).to receive(:template).with(['templates/good.epp'])
|
|
123
|
+
expect(RubyParser).to receive(:ruby).with(['lib/good.rb'], false, [])
|
|
124
|
+
expect(RubyParser).to receive(:template).with(['templates/good.erb'])
|
|
125
|
+
expect(DataParser).to receive(:yaml).with(['hieradata/good.yaml', 'hieradata/good.yml'])
|
|
126
|
+
expect(DataParser).to receive(:json).with(['hieradata/good.json'])
|
|
127
|
+
expect(DataParser).to receive(:eyaml).with(['hieradata/good.eyaml'], nil, nil)
|
|
128
|
+
expect(RubyParser).to receive(:librarian).with(['librarian/Puppetfile_good'], false, [])
|
|
129
|
+
|
|
130
|
+
puppet_check.send(:execute_parsers, %w[manifests/good.pp templates/good.epp lib/good.rb templates/good.erb hieradata/good.yaml hieradata/good.yml hieradata/good.json hieradata/good.eyaml librarian/Puppetfile_good foobarbaz], false, [], [], nil, nil)
|
|
131
|
+
|
|
132
|
+
expect(PuppetCheck.files[:ignored]).to eql(['foobarbaz'])
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it 'passes style and arg options through to the correct parsers and skips parser calls when a given file category is empty' do
|
|
136
|
+
expect(PuppetParser).to receive(:manifest).with(['manifests/good.pp'], true, ['--no-140chars-check'])
|
|
137
|
+
expect(PuppetParser).not_to receive(:template)
|
|
138
|
+
expect(RubyParser).to receive(:ruby).with(['lib/good.rb'], true, ['--except', 'Style/FrozenStringLiteralComment'])
|
|
139
|
+
expect(RubyParser).to receive(:librarian).with(['librarian/Puppetfile_good'], true, ['--except', 'Style/FrozenStringLiteralComment'])
|
|
140
|
+
expect(RubyParser).not_to receive(:template)
|
|
141
|
+
expect(DataParser).to receive(:yaml).with(['hieradata/good.yaml'])
|
|
142
|
+
expect(DataParser).not_to receive(:json)
|
|
143
|
+
expect(DataParser).not_to receive(:eyaml)
|
|
144
|
+
|
|
145
|
+
puppet_check.send(
|
|
146
|
+
:execute_parsers,
|
|
147
|
+
%w[manifests/good.pp lib/good.rb hieradata/good.yaml librarian/Puppetfile_good],
|
|
148
|
+
true,
|
|
149
|
+
['--no-140chars-check'],
|
|
150
|
+
['--except', 'Style/FrozenStringLiteralComment'],
|
|
151
|
+
nil,
|
|
152
|
+
nil
|
|
153
|
+
)
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it 'returns PuppetCheck.files' do
|
|
157
|
+
allow(PuppetParser).to receive(:manifest)
|
|
158
|
+
result = puppet_check.send(:execute_parsers, ['manifests/good.pp'], false, [], [], nil, nil)
|
|
159
|
+
expect(result).to eql(PuppetCheck.files)
|
|
125
160
|
end
|
|
126
161
|
end
|
|
127
162
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,23 +1,10 @@
|
|
|
1
1
|
require 'rspec'
|
|
2
2
|
|
|
3
3
|
# for path to fixtures
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def fixtures_dir
|
|
8
|
-
@fixtures_dir = "#{File.dirname(__FILE__)}/fixtures/"
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def octocatalog_diff_dir
|
|
12
|
-
@octocatalog_diff_dir = "#{File.dirname(__FILE__)}/octocatalog-diff/"
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def ci_env
|
|
16
|
-
@ci_env = ENV['CIRCLECI'] == 'true' || ENV['GITHUB_ACTIONS'] == 'true'
|
|
17
|
-
end
|
|
18
|
-
end
|
|
4
|
+
FIXTURES_DIR = "#{File.dirname(__FILE__)}/fixtures/".freeze
|
|
5
|
+
OCTOCATALOG_DIFF_DIR = "#{File.dirname(__FILE__)}/octocatalog-diff/".freeze
|
|
6
|
+
CI_ENV = ENV['CIRCLECI'] == 'true' || ENV['GITHUB_ACTIONS'] == 'true'
|
|
19
7
|
|
|
20
8
|
RSpec.configure do |config|
|
|
21
|
-
config.include Variables
|
|
22
9
|
config.color = true
|
|
23
10
|
end
|
data/spec/system/system_spec.rb
CHANGED
|
@@ -6,18 +6,18 @@ require_relative '../../lib/puppet-check/tasks'
|
|
|
6
6
|
describe PuppetCheck do
|
|
7
7
|
context 'executed as a system from the CLI with arguments and various files to be processed' do
|
|
8
8
|
it 'outputs diagnostic results correctly after processing all of the files' do
|
|
9
|
-
Dir.chdir(
|
|
9
|
+
Dir.chdir(FIXTURES_DIR)
|
|
10
10
|
|
|
11
11
|
# see regression_check_spec
|
|
12
|
-
if
|
|
12
|
+
if CI_ENV
|
|
13
13
|
expect(PuppetCheck::CLI.run(%w[-s --puppet-lint no-hard_tabs-check,no-140chars-check --rubocop Layout/LineLength,Style/Encoding --public keys/public_key.pkcs7.pem --private keys/private_key.pkcs7.pem .])).to eql(2)
|
|
14
14
|
else
|
|
15
15
|
expect(PuppetCheck::CLI.run(%w[-s --puppet-lint no-hard_tabs-check,no-140chars-check --rubocop Layout/LineLength,Style/Encoding --public keys/public_key.pkcs7.pem --private keys/private_key.pkcs7.pem --smoke -n good.example.com --octoconfig spec/octocatalog-diff/octocatalog-diff.cfg.rb .])).to eql(2)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
expect(PuppetCheck.files[:errors].length).to eql(
|
|
18
|
+
expect(PuppetCheck.files[:errors].length).to eql(12)
|
|
19
19
|
expect(PuppetCheck.files[:warnings].length).to eql(13)
|
|
20
|
-
expect(PuppetCheck.files[:clean].length).to eql(
|
|
20
|
+
expect(PuppetCheck.files[:clean].length).to eql(14)
|
|
21
21
|
expect(PuppetCheck.files[:ignored].length).to eql(3)
|
|
22
22
|
end
|
|
23
23
|
end
|
|
@@ -25,7 +25,7 @@ describe PuppetCheck do
|
|
|
25
25
|
context 'executed as a system from the Rakefile with arguments and various files to be processed' do
|
|
26
26
|
it 'outputs diagnostic results correctly after processing all of the files' do
|
|
27
27
|
# ensure rake only checks the files inside fixtures
|
|
28
|
-
Dir.chdir(
|
|
28
|
+
Dir.chdir(FIXTURES_DIR)
|
|
29
29
|
|
|
30
30
|
# clear out files member from previous system test
|
|
31
31
|
PuppetCheck.files = {
|
|
@@ -47,7 +47,7 @@ describe PuppetCheck do
|
|
|
47
47
|
|
|
48
48
|
it 'uses override settings and outputs diagnostic results correctly after processing all of the files' do
|
|
49
49
|
# ensure rake only checks the files inside fixtures
|
|
50
|
-
Dir.chdir(
|
|
50
|
+
Dir.chdir(FIXTURES_DIR)
|
|
51
51
|
|
|
52
52
|
# clear out files member from previous system test
|
|
53
53
|
PuppetCheck.files = {
|
|
@@ -60,7 +60,7 @@ describe PuppetCheck do
|
|
|
60
60
|
# assign settings
|
|
61
61
|
settings = { style: true }
|
|
62
62
|
# see regression_check_spec
|
|
63
|
-
unless
|
|
63
|
+
unless CI_ENV
|
|
64
64
|
settings[:smoke] = true
|
|
65
65
|
settings[:octonodes] = %w[good.example.com]
|
|
66
66
|
settings[:octoconfig] = 'spec/octocatalog-diff/octocatalog-diff.cfg.rb'
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: puppet-check
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.5.
|
|
4
|
+
version: 2.5.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Matt Schuchard
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-07-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: puppet
|
|
@@ -153,9 +153,11 @@ files:
|
|
|
153
153
|
- lib/puppet_check.rb
|
|
154
154
|
- puppet-check.gemspec
|
|
155
155
|
- spec/fixtures/foobarbaz
|
|
156
|
+
- spec/fixtures/hieradata/decrypt_error.eyaml
|
|
156
157
|
- spec/fixtures/hieradata/good.eyaml
|
|
157
158
|
- spec/fixtures/hieradata/good.json
|
|
158
159
|
- spec/fixtures/hieradata/good.yaml
|
|
160
|
+
- spec/fixtures/hieradata/nested_array.eyaml
|
|
159
161
|
- spec/fixtures/hieradata/style.eyaml
|
|
160
162
|
- spec/fixtures/hieradata/style.yaml
|
|
161
163
|
- spec/fixtures/hieradata/syntax.eyaml
|