diff --git a/lib/facter/openssl_version.rb b/lib/facter/openssl_version.rb index 442385c3..c5d9c913 100644 --- a/lib/facter/openssl_version.rb +++ b/lib/facter/openssl_version.rb @@ -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 diff --git a/lib/puppet/provider/cert_file/posix.rb b/lib/puppet/provider/cert_file/posix.rb index b25b3fa2..27401df8 100644 --- a/lib/puppet/provider/cert_file/posix.rb +++ b/lib/puppet/provider/cert_file/posix.rb @@ -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 diff --git a/lib/puppet/provider/ssl_pkey/openssl.rb b/lib/puppet/provider/ssl_pkey/openssl.rb index b2b2cc7d..8ca7df99 100644 --- a/lib/puppet/provider/ssl_pkey/openssl.rb +++ b/lib/puppet/provider/ssl_pkey/openssl.rb @@ -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 diff --git a/spec/functions/cert_aia_caissuers_spec.rb b/spec/functions/cert_aia_caissuers_spec.rb index 85ce66a9..45e20548 100644 --- a/spec/functions/cert_aia_caissuers_spec.rb +++ b/spec/functions/cert_aia_caissuers_spec.rb @@ -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) diff --git a/spec/functions/cert_date_valid_spec.rb b/spec/functions/cert_date_valid_spec.rb index 94bcb07e..6528d05f 100644 --- a/spec/functions/cert_date_valid_spec.rb +++ b/spec/functions/cert_date_valid_spec.rb @@ -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) diff --git a/spec/unit/puppet/provider/cert_file/posix_spec.rb b/spec/unit/puppet/provider/cert_file/posix_spec.rb index 34b41de3..03819e38 100644 --- a/spec/unit/puppet/provider/cert_file/posix_spec.rb +++ b/spec/unit/puppet/provider/cert_file/posix_spec.rb @@ -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 diff --git a/spec/unit/puppet/provider/ssl_pkey/openssl_spec.rb b/spec/unit/puppet/provider/ssl_pkey/openssl_spec.rb index 8e1f7541..4ee19549 100644 --- a/spec/unit/puppet/provider/ssl_pkey/openssl_spec.rb +++ b/spec/unit/puppet/provider/ssl_pkey/openssl_spec.rb @@ -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 diff --git a/spec/unit/puppet/provider/x509_cert/openssl_spec.rb b/spec/unit/puppet/provider/x509_cert/openssl_spec.rb index 2ce29fb9..f9419dfe 100644 --- a/spec/unit/puppet/provider/x509_cert/openssl_spec.rb +++ b/spec/unit/puppet/provider/x509_cert/openssl_spec.rb @@ -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 @@ -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 @@ -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 diff --git a/spec/unit/puppet/provider/x509_request/openssl_spec.rb b/spec/unit/puppet/provider/x509_request/openssl_spec.rb index f1879542..74c44210 100644 --- a/spec/unit/puppet/provider/x509_request/openssl_spec.rb +++ b/spec/unit/puppet/provider/x509_request/openssl_spec.rb @@ -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 @@ -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 @@ -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