summaryrefslogtreecommitdiff
path: root/spec/unit/mixin
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/mixin')
-rw-r--r--spec/unit/mixin/openssl_helper_spec.rb200
-rw-r--r--spec/unit/mixin/params_validate_spec.rb108
2 files changed, 154 insertions, 154 deletions
diff --git a/spec/unit/mixin/openssl_helper_spec.rb b/spec/unit/mixin/openssl_helper_spec.rb
index a6a6fb0e71..d68fcb71eb 100644
--- a/spec/unit/mixin/openssl_helper_spec.rb
+++ b/spec/unit/mixin/openssl_helper_spec.rb
@@ -32,9 +32,9 @@ describe Chef::Mixin::OpenSSLHelper do
describe "#get_key_filename" do
context "When the input is not a string" do
it "Throws a TypeError" do
- expect do
+ expect {
instance.get_key_filename(33)
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
@@ -89,11 +89,11 @@ describe Chef::Mixin::OpenSSLHelper do
context "When the dhparam.pem file does exist, but does not contain a valid dhparam key" do
it "Throws an OpenSSL::PKey::DHError exception" do
- expect do
+ expect {
@dhparam_file.puts("I_am_not_a_key_I_am_a_free_man")
@dhparam_file.close
instance.dhparam_pem_valid?(@dhparam_file.path)
- end.to raise_error(::OpenSSL::PKey::DHError)
+ }.to raise_error(::OpenSSL::PKey::DHError)
end
end
@@ -225,17 +225,17 @@ describe Chef::Mixin::OpenSSLHelper do
describe "#gen_dhparam" do
context "When given an invalid key length" do
it "Throws an ArgumentError" do
- expect do
+ expect {
instance.gen_dhparam(2046, 2)
- end.to raise_error(ArgumentError)
+ }.to raise_error(ArgumentError)
end
end
context "When given an invalid generator id" do
it "Throws a TypeError" do
- expect do
+ expect {
instance.gen_dhparam(2048, "bob")
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
@@ -249,9 +249,9 @@ describe Chef::Mixin::OpenSSLHelper do
describe "#gen_rsa_priv_key" do
context "When given an invalid key length" do
it "Throws an ArgumentError" do
- expect do
+ expect {
instance.gen_rsa_priv_key(4093)
- end.to raise_error(ArgumentError)
+ }.to raise_error(ArgumentError)
end
end
@@ -269,33 +269,33 @@ describe Chef::Mixin::OpenSSLHelper do
context "When given anything other than an RSA key object to encrypt" do
it "Raises a TypeError" do
- expect do
+ expect {
instance.encrypt_rsa_key("abcd", "efgh", "des3")
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
context "When given anything other than a string as the passphrase" do
it "Raises a TypeError" do
- expect do
+ expect {
instance.encrypt_rsa_key(@rsa_key, 1234, "des3")
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
context "When given anything other than a string as the cipher" do
it "Raises a TypeError" do
- expect do
+ expect {
instance.encrypt_rsa_key(@rsa_key, "1234", 1234)
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
context "When given an invalid cipher string" do
it "Raises an ArgumentError" do
- expect do
+ expect {
instance.encrypt_rsa_key(@rsa_key, "1234", "des3_bogus")
- end.to raise_error(ArgumentError)
+ }.to raise_error(ArgumentError)
end
end
@@ -311,15 +311,15 @@ describe Chef::Mixin::OpenSSLHelper do
describe "#gen_ec_priv_key" do
context "When given an invalid curve" do
it "Raises a TypeError" do
- expect do
+ expect {
instance.gen_ec_priv_key(2048)
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
it "Throws an ArgumentError" do
- expect do
+ expect {
instance.gen_ec_priv_key("primeFromTheFuture")
- end.to raise_error(ArgumentError)
+ }.to raise_error(ArgumentError)
end
end
@@ -337,33 +337,33 @@ describe Chef::Mixin::OpenSSLHelper do
context "When given anything other than an EC key object to encrypt" do
it "Raises a TypeError" do
- expect do
+ expect {
instance.encrypt_ec_key("abcd", "efgh", "des3")
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
context "When given anything other than a string as the passphrase" do
it "Raises a TypeError" do
- expect do
+ expect {
instance.encrypt_ec_key(@ec_key, 1234, "des3")
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
context "When given anything other than a string as the cipher" do
it "Raises a TypeError" do
- expect do
+ expect {
instance.encrypt_ec_key(@ec_key, "1234", 1234)
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
context "When given an invalid cipher string" do
it "Raises an ArgumentError" do
- expect do
+ expect {
instance.encrypt_ec_key(@ec_key, "1234", "des3_bogus")
- end.to raise_error(ArgumentError)
+ }.to raise_error(ArgumentError)
end
end
@@ -385,17 +385,17 @@ describe Chef::Mixin::OpenSSLHelper do
context "When given anything other than an RSA/EC key object" do
it "Raises a TypeError" do
- expect do
+ expect {
instance.gen_x509_request(@subject, "abc")
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
context "When given anything other than an X509 Name object" do
it "Raises a TypeError" do
- expect do
+ expect {
instance.gen_x509_request("abc", @key)
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
@@ -419,35 +419,35 @@ describe Chef::Mixin::OpenSSLHelper do
describe "#gen_x509_extensions" do
context "When given anything other than an Ruby Hash object" do
it "Raises a TypeError" do
- expect do
+ expect {
instance.gen_x509_extensions("abc")
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
context "When a misformatted ruby Hash is given" do
it "Raises a TypeError" do
- expect do
+ expect {
instance.gen_x509_extensions("pouet" => "plop")
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
it "Raises a ArgumentError" do
- expect do
+ expect {
instance.gen_x509_extensions("pouet" => { "values" => [ "keyCertSign" ], "wrong_key" => true })
- end.to raise_error(ArgumentError)
+ }.to raise_error(ArgumentError)
end
it "Raises a TypeError" do
- expect do
+ expect {
instance.gen_x509_extensions("keyUsage" => { "values" => "keyCertSign", "critical" => true })
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
it "Raises a TypeError" do
- expect do
+ expect {
instance.gen_x509_extensions("keyUsage" => { "values" => [ "keyCertSign" ], "critical" => "yes" })
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
@@ -496,33 +496,33 @@ describe Chef::Mixin::OpenSSLHelper do
context "When the request given is anything other then a Ruby OpenSSL::X509::Request" do
it "Raises a TypeError" do
- expect do
+ expect {
@instance.gen_x509_cert("abc", @x509_extension, @info_without_issuer, @rsa_key)
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
context "When the extension given is anything other then a Ruby Array" do
it "Raises a TypeError" do
- expect do
+ expect {
@instance.gen_x509_cert(@rsa_request, "abc", @info_without_issuer, @rsa_key)
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
context "When the info given is anything other then a Ruby Hash" do
it "Raises a TypeError" do
- expect do
+ expect {
@instance.gen_x509_cert(@rsa_request, @x509_extension, "abc", @rsa_key)
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
context "When the key given is anything other then a Ruby OpenSSL::Pkey::EC or OpenSSL::Pkey::RSA object" do
it "Raises a TypeError" do
- expect do
+ expect {
@instance.gen_x509_cert(@rsa_request, @x509_extension, @info_without_issuer, "abc")
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
@@ -550,9 +550,9 @@ describe Chef::Mixin::OpenSSLHelper do
context "When the CRL given is anything other then a Ruby OpenSSL::X509::CRL object" do
it "Raises a TypeError" do
- expect do
+ expect {
instance.get_next_crl_number("abc")
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
@@ -572,17 +572,17 @@ describe Chef::Mixin::OpenSSLHelper do
context "When the CRL given is anything other then a Ruby OpenSSL::X509::CRL object" do
it "Raises a TypeError" do
- expect do
+ expect {
instance.serial_revoked?("abc", "C7BCB6602A2E4251EF4E2827A228CB52BC0CEA2F")
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
context "When the serial given is anything other then a Ruby String or Integer object" do
it "Raises a TypeError" do
- expect do
+ expect {
instance.serial_revoked?(@crl, [])
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
@@ -621,37 +621,37 @@ describe Chef::Mixin::OpenSSLHelper do
context "When the CA private key given is anything other then a Ruby OpenSSL::PKey::EC object or a OpenSSL::PKey::RSA object" do
it "Raises a TypeError" do
- expect do
+ expect {
instance.gen_x509_crl("abc", @info)
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
context "When the info given is anything other then a Ruby Hash" do
it "Raises a TypeError" do
- expect do
+ expect {
instance.gen_x509_crl(@ca_key, "abc")
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
context "When a misformatted info Ruby Hash is given" do
it "Raises a ArgumentError" do
- expect do
+ expect {
instance.gen_x509_crl(@ca_key, "abc" => "def", "validity" => 8)
- end.to raise_error(ArgumentError)
+ }.to raise_error(ArgumentError)
end
it "Raises a TypeError" do
- expect do
+ expect {
instance.gen_x509_crl(@ca_key, "issuer" => "abc", "validity" => 8)
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
it "Raises a TypeError" do
- expect do
+ expect {
instance.gen_x509_crl(@ca_key, "issuer" => @ca_cert, "validity" => "abc")
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
@@ -693,45 +693,45 @@ describe Chef::Mixin::OpenSSLHelper do
context "When the CRL given is anything other then a Ruby OpenSSL::X509::CRL object" do
it "Raises a TypeError" do
- expect do
+ expect {
instance.renew_x509_crl("abc", @ca_key, @info)
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
context "When the CA private key given is anything other then a Ruby OpenSSL::PKey::EC object or a OpenSSL::PKey::RSA object" do
it "Raises a TypeError" do
- expect do
+ expect {
instance.renew_x509_crl(@crl, "abc", @info)
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
context "When the info given is anything other then a Ruby Hash" do
it "Raises a TypeError" do
- expect do
+ expect {
instance.renew_x509_crl(@crl, @ca_key, "abc")
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
context "When a misformatted info Ruby Hash is given" do
it "Raises a ArgumentError" do
- expect do
+ expect {
instance.renew_x509_crl(@crl, @ca_key, "abc" => "def", "validity" => 8)
- end.to raise_error(ArgumentError)
+ }.to raise_error(ArgumentError)
end
it "Raises a TypeError" do
- expect do
+ expect {
instance.renew_x509_crl(@crl, @ca_key, "issuer" => "abc", "validity" => 8)
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
it "Raises a TypeError" do
- expect do
+ expect {
instance.renew_x509_crl(@crl, @ca_key, "issuer" => @ca_cert, "validity" => "abc")
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
@@ -775,73 +775,73 @@ describe Chef::Mixin::OpenSSLHelper do
context "When the revoke_info given is anything other then a Ruby Hash" do
it "Raises a TypeError" do
- expect do
+ expect {
instance.revoke_x509_crl("abc", @crl, @ca_key, @info)
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
context "When the CRL given is anything other then a Ruby OpenSSL::X509::CRL object" do
it "Raises a TypeError" do
- expect do
+ expect {
instance.revoke_x509_crl(@revoke_info, "abc", @ca_key, @info)
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
context "When the CA private key given is anything other then a Ruby OpenSSL::PKey::EC object or a OpenSSL::PKey::RSA object" do
it "Raises a TypeError" do
- expect do
+ expect {
instance.revoke_x509_crl(@revoke_info, @crl, "abc", @info)
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
context "When the info given is anything other then a Ruby Hash" do
it "Raises a TypeError" do
- expect do
+ expect {
instance.revoke_x509_crl(@revoke_info, @crl, @ca_key, "abc")
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
context "When a misformatted revoke_info Ruby Hash is given" do
it "Raises a ArgumentError" do
- expect do
+ expect {
instance.revoke_x509_crl({ "abc" => "def", "ghi" => "jkl" }, @crl, @ca_key, @info)
- end.to raise_error(ArgumentError)
+ }.to raise_error(ArgumentError)
end
it "Raises a TypeError" do
- expect do
+ expect {
instance.revoke_x509_crl({ "serial" => [], "reason" => 0 }, @crl, @ca_key, @info)
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
it "Raises a TypeError" do
- expect do
+ expect {
instance.revoke_x509_crl({ "serial" => 1, "reason" => "abc" }, @crl, @ca_key, @info)
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
context "When a misformatted info Ruby Hash is given" do
it "Raises a ArgumentError" do
- expect do
+ expect {
instance.revoke_x509_crl(@revoke_info, @crl, @ca_key, "abc" => "def", "validity" => 8)
- end.to raise_error(ArgumentError)
+ }.to raise_error(ArgumentError)
end
it "Raises a TypeError" do
- expect do
+ expect {
instance.revoke_x509_crl(@revoke_info, @crl, @ca_key, "issuer" => "abc", "validity" => 8)
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
it "Raises a TypeError" do
- expect do
+ expect {
instance.revoke_x509_crl(@revoke_info, @crl, @ca_key, "issuer" => @ca_cert, "validity" => "abc")
- end.to raise_error(TypeError)
+ }.to raise_error(TypeError)
end
end
diff --git a/spec/unit/mixin/params_validate_spec.rb b/spec/unit/mixin/params_validate_spec.rb
index 489742cb7d..3e7a5969f1 100644
--- a/spec/unit/mixin/params_validate_spec.rb
+++ b/spec/unit/mixin/params_validate_spec.rb
@@ -56,7 +56,7 @@ describe Chef::Mixin::ParamsValidate do
end
it "should allow you to check what kind_of? thing an argument is with kind_of" do
- expect do
+ expect {
@vo.validate(
{ one: "string" },
{
@@ -65,9 +65,9 @@ describe Chef::Mixin::ParamsValidate do
},
}
)
- end.not_to raise_error
+ }.not_to raise_error
- expect do
+ expect {
@vo.validate(
{ one: "string" },
{
@@ -76,11 +76,11 @@ describe Chef::Mixin::ParamsValidate do
},
}
)
- end.to raise_error(ArgumentError)
+ }.to raise_error(ArgumentError)
end
it "should allow you to specify an argument is required with required" do
- expect do
+ expect {
@vo.validate(
{ one: "string" },
{
@@ -89,9 +89,9 @@ describe Chef::Mixin::ParamsValidate do
},
}
)
- end.not_to raise_error
+ }.not_to raise_error
- expect do
+ expect {
@vo.validate(
{ two: "string" },
{
@@ -100,9 +100,9 @@ describe Chef::Mixin::ParamsValidate do
},
}
)
- end.to raise_error(ArgumentError)
+ }.to raise_error(ArgumentError)
- expect do
+ expect {
@vo.validate(
{ two: "string" },
{
@@ -111,11 +111,11 @@ describe Chef::Mixin::ParamsValidate do
},
}
)
- end.not_to raise_error
+ }.not_to raise_error
end
it "should allow you to specify whether an object has a method with respond_to" do
- expect do
+ expect {
@vo.validate(
{ one: @vo },
{
@@ -124,9 +124,9 @@ describe Chef::Mixin::ParamsValidate do
},
}
)
- end.not_to raise_error
+ }.not_to raise_error
- expect do
+ expect {
@vo.validate(
{ one: @vo },
{
@@ -135,11 +135,11 @@ describe Chef::Mixin::ParamsValidate do
},
}
)
- end.to raise_error(ArgumentError)
+ }.to raise_error(ArgumentError)
end
it "should allow you to specify whether an object has all the given methods with respond_to and an array" do
- expect do
+ expect {
@vo.validate(
{ one: @vo },
{
@@ -148,9 +148,9 @@ describe Chef::Mixin::ParamsValidate do
},
}
)
- end.not_to raise_error
+ }.not_to raise_error
- expect do
+ expect {
@vo.validate(
{ one: @vo },
{
@@ -159,7 +159,7 @@ describe Chef::Mixin::ParamsValidate do
},
}
)
- end.to raise_error(ArgumentError)
+ }.to raise_error(ArgumentError)
end
it "should let you set a default value with default => value" do
@@ -173,7 +173,7 @@ describe Chef::Mixin::ParamsValidate do
end
it "should let you check regular expressions" do
- expect do
+ expect {
@vo.validate(
{ one: "is good" },
{
@@ -182,9 +182,9 @@ describe Chef::Mixin::ParamsValidate do
},
}
)
- end.not_to raise_error
+ }.not_to raise_error
- expect do
+ expect {
@vo.validate(
{ one: "is good" },
{
@@ -193,11 +193,11 @@ describe Chef::Mixin::ParamsValidate do
},
}
)
- end.to raise_error(ArgumentError)
+ }.to raise_error(ArgumentError)
end
it "should let you specify your own callbacks" do
- expect do
+ expect {
@vo.validate(
{ one: "is good" },
{
@@ -210,9 +210,9 @@ describe Chef::Mixin::ParamsValidate do
},
}
)
- end.not_to raise_error
+ }.not_to raise_error
- expect do
+ expect {
@vo.validate(
{ one: "is bad" },
{
@@ -225,12 +225,12 @@ describe Chef::Mixin::ParamsValidate do
},
}
)
- end.to raise_error(ArgumentError)
+ }.to raise_error(ArgumentError)
end
it "should let you combine checks" do
args = { one: "is good", two: "is bad" }
- expect do
+ expect {
@vo.validate(
args,
{
@@ -252,9 +252,9 @@ describe Chef::Mixin::ParamsValidate do
three: { default: "neato mosquito" },
}
)
- end.not_to raise_error
+ }.not_to raise_error
expect(args[:three]).to eq("neato mosquito")
- expect do
+ expect {
@vo.validate(
args,
{
@@ -276,11 +276,11 @@ describe Chef::Mixin::ParamsValidate do
three: { default: "neato mosquito" },
}
)
- end.to raise_error(ArgumentError)
+ }.to raise_error(ArgumentError)
end
it "should raise an ArgumentError if the validation map has an unknown check" do
- expect do
+ expect {
@vo.validate(
{ one: "two" },
{
@@ -289,17 +289,17 @@ describe Chef::Mixin::ParamsValidate do
},
}
)
- end.to raise_error(ArgumentError)
+ }.to raise_error(ArgumentError)
end
it "should accept keys that are strings in the options" do
- expect do
+ expect {
@vo.validate({ "one" => "two" }, { one: { regex: /^two$/ } })
- end.not_to raise_error
+ }.not_to raise_error
end
it "should allow an array to kind_of" do
- expect do
+ expect {
@vo.validate(
{ one: "string" },
{
@@ -308,8 +308,8 @@ describe Chef::Mixin::ParamsValidate do
},
}
)
- end.not_to raise_error
- expect do
+ }.not_to raise_error
+ expect {
@vo.validate(
{ one: ["string"] },
{
@@ -318,8 +318,8 @@ describe Chef::Mixin::ParamsValidate do
},
}
)
- end.not_to raise_error
- expect do
+ }.not_to raise_error
+ expect {
@vo.validate(
{ one: {} },
{
@@ -328,29 +328,29 @@ describe Chef::Mixin::ParamsValidate do
},
}
)
- end.to raise_error(ArgumentError)
+ }.to raise_error(ArgumentError)
end
it "asserts that a value returns false from a predicate method" do
- expect do
+ expect {
@vo.validate({ not_blank: "should pass" },
{ not_blank: { cannot_be: %i{nil empty} } })
- end.not_to raise_error
- expect do
+ }.not_to raise_error
+ expect {
@vo.validate({ not_blank: "" },
{ not_blank: { cannot_be: %i{nil empty} } })
- end.to raise_error(Chef::Exceptions::ValidationFailed)
+ }.to raise_error(Chef::Exceptions::ValidationFailed)
end
it "allows a custom validation message" do
- expect do
+ expect {
@vo.validate({ not_blank: "should pass" },
{ not_blank: { cannot_be: %i{nil empty}, validation_message: "my validation message" } })
- end.not_to raise_error
- expect do
+ }.not_to raise_error
+ expect {
@vo.validate({ not_blank: "" },
{ not_blank: { cannot_be: %i{nil empty}, validation_message: "my validation message" } })
- end.to raise_error(Chef::Exceptions::ValidationFailed, "my validation message")
+ }.to raise_error(Chef::Exceptions::ValidationFailed, "my validation message")
end
it "should set and return a value, then return the same value" do
@@ -366,15 +366,15 @@ describe Chef::Mixin::ParamsValidate do
end
it "should raise an ArgumentError when argument is nil and required is true" do
- expect do
+ expect {
@vo.set_or_return(:test, nil, { required: true })
- end.to raise_error(ArgumentError)
+ }.to raise_error(ArgumentError)
end
it "should not raise an error when argument is nil and required is false" do
- expect do
+ expect {
@vo.set_or_return(:test, nil, { required: false })
- end.not_to raise_error
+ }.not_to raise_error
end
it "should set and return @name, then return @name for foo when argument is nil" do
@@ -391,9 +391,9 @@ describe Chef::Mixin::ParamsValidate do
it "should raise an error when delayed evaluated attribute is not valid" do
value = Chef::DelayedEvaluator.new { "test" }
@vo.set_or_return(:test, value, { kind_of: Numeric })
- expect do
+ expect {
@vo.set_or_return(:test, nil, { kind_of: Numeric })
- end.to raise_error(Chef::Exceptions::ValidationFailed)
+ }.to raise_error(Chef::Exceptions::ValidationFailed)
end
it "should create DelayedEvaluator instance when #lazy is used" do