diff options
author | Tim Smith <tsmith@chef.io> | 2018-08-16 14:29:44 -0700 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2018-08-16 14:29:44 -0700 |
commit | 567b82e91cb4ae1b72eec8632d1712dd8608ebcc (patch) | |
tree | 0b49021c2a03239e023c47cc946ab7fabfb0728e | |
parent | d1461202273c319966a1cc3dd6872bb56582db39 (diff) | |
download | chef-567b82e91cb4ae1b72eec8632d1712dd8608ebcc.tar.gz |
Add specs for the x509_cert and x509_request resourcesopenssl_new_stuff
Fix the defaults that should be lazied and fix the duplicate class name I was using.
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/chef/resource/openssl_x509_certificate.rb | 4 | ||||
-rw-r--r-- | lib/chef/resource/openssl_x509_request.rb | 2 | ||||
-rw-r--r-- | spec/unit/resource/openssl_openssl_x509_certificate_spec.rb | 71 | ||||
-rw-r--r-- | spec/unit/resource/openssl_openssl_x509_request.rb | 67 |
4 files changed, 141 insertions, 3 deletions
diff --git a/lib/chef/resource/openssl_x509_certificate.rb b/lib/chef/resource/openssl_x509_certificate.rb index 7c354588af..04641e877b 100644 --- a/lib/chef/resource/openssl_x509_certificate.rb +++ b/lib/chef/resource/openssl_x509_certificate.rb @@ -70,11 +70,11 @@ class Chef property :extensions, Hash, description: "Hash of X509 Extensions entries, in format { 'keyUsage' => { 'values' => %w( keyEncipherment digitalSignature), 'critical' => true } }.", - default: {} + default: lazy { Hash.new } property :subject_alt_name, Array, description: "Array of Subject Alternative Name entries, in format DNS:example.com or IP:1.2.3.4.", - default: [] + default: lazy { [] } property :key_file, String, description: "The path to a certificate key file on the filesystem. If the key_file attribute is specified, the resource will attempt to source a key from this location. If no key file is found, the resource will generate a new key file at this location. If the key_file attribute is not specified, the resource will generate a key file in the same directory as the generated certificate, with the same name as the generated certificate." diff --git a/lib/chef/resource/openssl_x509_request.rb b/lib/chef/resource/openssl_x509_request.rb index b111b7e80a..a7b989d96d 100644 --- a/lib/chef/resource/openssl_x509_request.rb +++ b/lib/chef/resource/openssl_x509_request.rb @@ -18,7 +18,7 @@ require "chef/resource" class Chef class Resource - class OpensslX509Certificate < Chef::Resource + class OpensslX509Request < Chef::Resource require "chef/mixin/openssl_helper" include Chef::Mixin::OpenSSLHelper diff --git a/spec/unit/resource/openssl_openssl_x509_certificate_spec.rb b/spec/unit/resource/openssl_openssl_x509_certificate_spec.rb new file mode 100644 index 0000000000..b8e49db164 --- /dev/null +++ b/spec/unit/resource/openssl_openssl_x509_certificate_spec.rb @@ -0,0 +1,71 @@ +# +# Copyright:: Copyright 2018, Chef Software, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require "spec_helper" + +describe Chef::Resource::OpensslX509Certificate do + + let(:resource) { Chef::Resource::OpensslX509Certificate.new("fakey_fakerton") } + + it "has a resource name of :openssl_x509_certificate" do + expect(resource.resource_name).to eql(:openssl_x509_certificate) + end + + it "the path property is the name_property" do + expect(resource.path).to eql("fakey_fakerton") + end + + it "sets the default action as :create" do + expect(resource.action).to eql([:create]) + end + + it "supports :create action" do + expect { resource.action :create }.not_to raise_error + end + + it "has a default expiration of 365" do + expect(resource.expire).to eql(365) + end + + it "has a default mode of '0644'" do + expect(resource.mode).to eql("0644") + end + + it "has a default key_type of 'rsa'" do + expect(resource.key_type).to eql("rsa") + end + + it "only accepts valid key_type values" do + expect { resource.key_type "fako" }.to raise_error(ArgumentError) + end + + it "has a default key_length of '2048'" do + expect(resource.key_length).to eql(2048) + end + + it "only accepts valid key_length values" do + expect { resource.key_length 1023 }.to raise_error(ArgumentError) + end + + it "has a default key_curve of 'prime256v1'" do + expect(resource.key_curve).to eql("prime256v1") + end + + it "only accepts valid key_curve values" do + expect { resource.key_curve "fako" }.to raise_error(ArgumentError) + end +end diff --git a/spec/unit/resource/openssl_openssl_x509_request.rb b/spec/unit/resource/openssl_openssl_x509_request.rb new file mode 100644 index 0000000000..59abdc666e --- /dev/null +++ b/spec/unit/resource/openssl_openssl_x509_request.rb @@ -0,0 +1,67 @@ +# +# Copyright:: Copyright 2018, Chef Software, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require "spec_helper" + +describe Chef::Resource::OpensslX509Request do + + let(:resource) { Chef::Resource::OpensslX509Request.new("fakey_fakerton") } + + it "has a resource name of :openssl_x509_request" do + expect(resource.resource_name).to eql(:openssl_x509_request) + end + + it "the path property is the name_property" do + expect(resource.path).to eql("fakey_fakerton") + end + + it "sets the default action as :create" do + expect(resource.action).to eql([:create]) + end + + it "supports :create action" do + expect { resource.action :create }.not_to raise_error + end + + it "has a default mode of '0644'" do + expect(resource.mode).to eql("0644") + end + + it "has a default key_type of 'ec'" do + expect(resource.key_type).to eql("ec") + end + + it "only accepts valid key_type values" do + expect { resource.key_type "fako" }.to raise_error(ArgumentError) + end + + it "has a default key_length of '2048'" do + expect(resource.key_length).to eql(2048) + end + + it "only accepts valid key_length values" do + expect { resource.key_length 1023 }.to raise_error(ArgumentError) + end + + it "has a default key_curve of 'prime256v1'" do + expect(resource.key_curve).to eql("prime256v1") + end + + it "only accepts valid key_curve values" do + expect { resource.key_curve "fako" }.to raise_error(ArgumentError) + end +end |