Skip to content

Commit

Permalink
Auto-correct rubocop offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
smortex committed Aug 18, 2023
1 parent 2d0d7a0 commit 7285844
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lib/facter/openssl_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
setcode do
if Facter::Util::Resolution.which('openssl')
openssl_version = Facter::Util::Resolution.exec('openssl version 2>&1')
matches = %r{^OpenSSL ([\w.\-]+)(\s+FIPS)?( +)([\d.]+)( +)([\w.]+)( +)([\d.]+)}.match(openssl_version)
matches = %r{^OpenSSL ([\w.-]+)(\s+FIPS)?( +)([\d.]+)( +)([\w.]+)( +)([\d.]+)}.match(openssl_version)
matches[1] if matches
end
end
Expand Down
8 changes: 2 additions & 6 deletions lib/puppet/provider/cert_file/posix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@ def exists?
def create
case resource[:format]
when :pem
File.open(resource[:path], 'wt') do |localcert_file|
localcert_file.write(remotecert.to_pem)
end
File.write(resource[:path], remotecert.to_pem)
when :der
File.open(resource[:path], 'wb') do |localcert_file|
localcert_file.write(remotecert.to_der)
end
File.binwrite(resource[:path], remotecert.to_der)
else
raise ArgumentError, 'Output format not implemented.'
end
Expand Down
4 changes: 1 addition & 3 deletions lib/puppet/provider/ssl_pkey/openssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ def exists?
def create
key = self.class.generate_key(resource)
pem = self.class.to_pem(resource, key)
File.open(resource[:path], 'w') do |f|
f.write(pem)
end
File.write(resource[:path], pem)
end

def destroy
Expand Down
2 changes: 1 addition & 1 deletion spec/functions/cert_aia_caissuers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'spec_helper'

describe 'openssl::cert_aia_caissuers' do
it { is_expected.not_to eq(nil) }
it { is_expected.not_to be_nil }

it 'raises an error if called with no argument' do
is_expected.to run.with_params.and_raise_error(StandardError)
Expand Down
2 changes: 1 addition & 1 deletion spec/functions/cert_date_valid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'spec_helper'
describe 'openssl::cert_date_valid' do
it { is_expected.not_to eq(nil) }
it { is_expected.not_to be_nil }

it 'raises an error if called with no argument' do
is_expected.to run.with_params.and_raise_error(StandardError)
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/puppet/provider/cert_file/posix_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

it 'exists? returns false on arbitraty path' do
allow_any_instance_of(Pathname).to receive(:exist?).and_return(false) # rubocop:disable RSpec/AnyInstance
expect(resource.provider.exists?).to eq(false)
expect(resource.provider.exists?).to be(false)
end

it 'downloads a certificate and stores it' do
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/puppet/provider/ssl_pkey/openssl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
it 'exists? should return true if key exists' do
expect(Pathname).to receive(:new).twice.with(path).and_return(pathname)
expect(pathname).to receive(:exist?).and_return(true)
expect(resource.provider.exists?).to eq(true)
expect(resource.provider.exists?).to be(true)
end

it 'exists? should return false if certificate does not exist' do
expect(Pathname).to receive(:new).twice.with(path).and_return(pathname)
expect(pathname).to receive(:exist?).and_return(false)
expect(resource.provider.exists?).to eq(false)
expect(resource.provider.exists?).to be(false)
end

context 'when creating a key with defaults' do
Expand Down
10 changes: 5 additions & 5 deletions spec/unit/puppet/provider/x509_cert/openssl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
allow_any_instance_of(Pathname).to receive(:exist?).and_return(true) # rubocop:disable RSpec/AnyInstance
c = OpenSSL::X509::Certificate.new # Fake certificate for mocking
allow(OpenSSL::X509::Certificate).to receive(:new).and_return(c)
expect(resource.provider.exists?).to eq(true)
expect(resource.provider.exists?).to be(true)
end

it 'exists? should return false if certificate does not exist' do
allow_any_instance_of(Pathname).to receive(:exist?).and_return(false) # rubocop:disable RSpec/AnyInstance
expect(resource.provider.exists?).to eq(false)
expect(resource.provider.exists?).to be(false)
end

it 'creates a certificate with the proper options' do
Expand Down Expand Up @@ -87,7 +87,7 @@
allow(OpenSSL::X509::Certificate).to receive(:new).and_return(cert)
allow(OpenSSL::PKey::RSA).to receive(:new)
expect(cert).to receive(:check_private_key).and_return(true)
expect(resource.provider.exists?).to eq(true)
expect(resource.provider.exists?).to be(true)
end

it 'exists? should return false if certificate exists and is not synced' do
Expand All @@ -97,13 +97,13 @@
allow(OpenSSL::X509::Certificate).to receive(:new).and_return(cert)
allow(OpenSSL::PKey::RSA).to receive(:new)
expect(cert).to receive(:check_private_key).and_return(false)
expect(resource.provider.exists?).to eq(false)
expect(resource.provider.exists?).to be(false)
end

it 'exists? should return false if certificate does not exist' do
resource[:force] = true
allow_any_instance_of(Pathname).to receive(:exist?).and_return(false) # rubocop:disable RSpec/AnyInstance
expect(resource.provider.exists?).to eq(false)
expect(resource.provider.exists?).to be(false)
end
end

Expand Down
10 changes: 5 additions & 5 deletions spec/unit/puppet/provider/x509_request/openssl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
context 'when not forcing key' do
it 'exists? should return true if csr exists' do
allow_any_instance_of(Pathname).to receive(:exist?).and_return(true) # rubocop:disable RSpec/AnyInstance
expect(resource.provider.exists?).to eq(true)
expect(resource.provider.exists?).to be(true)
end

it 'exists? should return false if csr exists' do
allow_any_instance_of(Pathname).to receive(:exist?).and_return(false) # rubocop:disable RSpec/AnyInstance
expect(resource.provider.exists?).to eq(false)
expect(resource.provider.exists?).to be(false)
end

it 'creates a certificate with the proper options' do
Expand Down Expand Up @@ -54,7 +54,7 @@
allow(OpenSSL::X509::Request).to receive(:new).and_return(cert)
allow(OpenSSL::PKey::RSA).to receive(:new)
expect(cert).to receive(:verify).and_return(true)
expect(resource.provider.exists?).to eq(true)
expect(resource.provider.exists?).to be(true)
end

it 'exists? should return false if certificate exists and is not synced' do
Expand All @@ -64,13 +64,13 @@
allow(OpenSSL::X509::Request).to receive(:new).and_return(cert)
allow(OpenSSL::PKey::RSA).to receive(:new)
expect(cert).to receive(:verify).and_return(false)
expect(resource.provider.exists?).to eq(false)
expect(resource.provider.exists?).to be(false)
end

it 'exists? should return false if certificate does not exist' do
resource[:force] = true
allow_any_instance_of(Pathname).to receive(:exist?).and_return(false) # rubocop:disable RSpec/AnyInstance
expect(resource.provider.exists?).to eq(false)
expect(resource.provider.exists?).to be(false)
end
end

Expand Down

0 comments on commit 7285844

Please sign in to comment.