Skip to content

Commit

Permalink
test(rubocop): fix all violations
Browse files Browse the repository at this point in the history
  • Loading branch information
myii committed Apr 26, 2021
1 parent 8b81042 commit 12030ab
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 39 deletions.
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ repos:
stages: [manual]
additional_dependencies: ['@commitlint/config-conventional@8.3.4']
always_run: true
- repo: https://github.com/rubocop-hq/rubocop
rev: v1.9.1
hooks:
- id: rubocop
name: Check Ruby files with rubocop
args: [--debug]
always_run: true
pass_filenames: false
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.7.1.1
hooks:
Expand Down
76 changes: 39 additions & 37 deletions test/integration/default/controls/managed.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
control 'managed' do
# frozen_string_literal: true

control 'managed' do
impact 1.0
title 'certficates and keys are managed'
desc 'verifies that certificates are present or absent'
Expand All @@ -13,48 +15,48 @@
key_dir = '/etc/pki/tls/private/'
end

describe file(cert_dir + 'cert.from.src.to.add.crt') do
its('content') { should match /^-----BEGIN CERTIFICATE-----/ }
its('content') { should match /^CERT FROM SOURCE FILE/ }
its('content') { should match /^-----END CERTIFICATE-----/ }
end
describe file(cert_dir + 'cert.and.key.to.add.crt') do
its('content') { should match /^-----BEGIN CERTIFICATE-----/ }
its('content') { should match /^1MOCKED CERT AND KEY/ }
its('content') { should match /^-----END CERTIFICATE-----/ }
end
describe file(key_dir + 'cert.and.key.to.add.key') do
its('content') { should match /^-----BEGIN RSA PRIVATE KEY-----/ }
its('content') { should match /^1MOCKED CERT AND KEY/ }
its('content') { should match /^-----END RSA PRIVATE KEY-----/ }
end
describe file(cert_dir + 'cert.and.key.with.ext.to.add.pem') do
its('content') { should match /^-----BEGIN CERTIFICATE-----/ }
its('content') { should match /^4MOCKED CERT AND KEY/ }
its('content') { should match /^-----END CERTIFICATE-----/ }
end
describe file(key_dir + 'cert.and.key.with.ext.to.add.priv') do
its('content') { should match /^-----BEGIN RSA PRIVATE KEY-----/ }
its('content') { should match /^4MOCKED CERT AND KEY/ }
its('content') { should match /^-----END RSA PRIVATE KEY-----/ }
end
describe file(cert_dir + 'cert.to.add.crt') do
its('content') { should match /^-----BEGIN CERTIFICATE-----/ }
its('content') { should match /^2MOCKED CERT/ }
its('content') { should match /^-----END CERTIFICATE-----/ }
end
describe file(cert_dir + 'cert.and.key.to.remove.crt') do
describe file("#{cert_dir}cert.from.src.to.add.crt") do
its('content') { should match(/^-----BEGIN CERTIFICATE-----/) }
its('content') { should match(/^CERT FROM SOURCE FILE/) }
its('content') { should match(/^-----END CERTIFICATE-----/) }
end
describe file("#{cert_dir}cert.and.key.to.add.crt") do
its('content') { should match(/^-----BEGIN CERTIFICATE-----/) }
its('content') { should match(/^1MOCKED CERT AND KEY/) }
its('content') { should match(/^-----END CERTIFICATE-----/) }
end
describe file("#{key_dir}cert.and.key.to.add.key") do
its('content') { should match(/^-----BEGIN RSA PRIVATE KEY-----/) }
its('content') { should match(/^1MOCKED CERT AND KEY/) }
its('content') { should match(/^-----END RSA PRIVATE KEY-----/) }
end
describe file("#{cert_dir}cert.and.key.with.ext.to.add.pem") do
its('content') { should match(/^-----BEGIN CERTIFICATE-----/) }
its('content') { should match(/^4MOCKED CERT AND KEY/) }
its('content') { should match(/^-----END CERTIFICATE-----/) }
end
describe file("#{key_dir}cert.and.key.with.ext.to.add.priv") do
its('content') { should match(/^-----BEGIN RSA PRIVATE KEY-----/) }
its('content') { should match(/^4MOCKED CERT AND KEY/) }
its('content') { should match(/^-----END RSA PRIVATE KEY-----/) }
end
describe file("#{cert_dir}cert.to.add.crt") do
its('content') { should match(/^-----BEGIN CERTIFICATE-----/) }
its('content') { should match(/^2MOCKED CERT/) }
its('content') { should match(/^-----END CERTIFICATE-----/) }
end
describe file("#{cert_dir}cert.and.key.to.remove.crt") do
it { should_not exist }
end
describe file(key_dir + 'cert.and.key.to.remove.key') do
describe file("#{key_dir}cert.and.key.to.remove.key") do
it { should_not exist }
end
if os.family == 'debian'
describe file('/etc/ssl/certs/ca-certificates.crt') do
its('content') { should match /^CERT FROM SOURCE FILE/ }
its('content') { should match /^1MOCKED CERT AND KEY/ }
its('content') { should match /^2MOCKED CERT/ }
its('content') { should_not match /^3MOCKED CERT AND KEY/ }
its('content') { should match(/^CERT FROM SOURCE FILE/) }
its('content') { should match(/^1MOCKED CERT AND KEY/) }
its('content') { should match(/^2MOCKED CERT/) }
its('content') { should_not match(/^3MOCKED CERT AND KEY/) }
end
end
end
8 changes: 6 additions & 2 deletions test/integration/default/controls/nocerts.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# frozen_string_literal: true

control 'nocerts' do
impact 1.0
title 'no certificates or keys are managed'
desc 'verifies that if you do not specify certificates or keys, this formula will not cause problems'
desc 'verifies that if you do not specify certificates or keys, ' \
'this formula will not cause problems'

if os.family == 'debian'
describe file('/etc/ssl/certs/ca-certificates.crt') do
it { should exist }
end
end
end
end

0 comments on commit 12030ab

Please sign in to comment.