Update puppetlabs/stdlib module
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / validate_x509_rsa_key_pair_spec.rb
old mode 100755 (executable)
new mode 100644 (file)
index eb63310..937c189
@@ -1,9 +1,8 @@
 require 'spec_helper'
 
 describe 'validate_x509_rsa_key_pair' do
-
   let(:valid_cert) do
-  <<EOS
+    <<DOC
 -----BEGIN CERTIFICATE-----
 MIIC9jCCAeCgAwIBAgIRAK11n3X7aypJ7FPM8UFyAeowCwYJKoZIhvcNAQELMBIx
 EDAOBgNVBAoTB0FjbWUgQ28wHhcNMTUxMTIzMjIzOTU4WhcNMTYxMTIyMjIzOTU4
@@ -22,11 +21,11 @@ IeAvBZHr4/kVXWnfo6kzCLcku1f8yE/yDEFClZe9XV1Lk/s+3YfXVtNnMJJ1giZI
 QVOe6CkmuQq+4AtIeW8aLkvlfp632jag1F77a1y+L268koKkj0hBMrtcErVQaxmq
 xym0+soR4Tk4pTIGckeFglrLxkP2JpM/yTwSEAVlmG9vgTliYKyR0uMl
 -----END CERTIFICATE-----
-EOS
+DOC
   end
 
   let(:valid_key) do
-  <<EOS
+    <<DOC
 -----BEGIN RSA PRIVATE KEY-----
 MIIEogIBAAKCAQEAz9bY/piKahD10AiJSfbI2A8NG5UwRz0r9T/WfvNVdhgrsGFg
 NQjvpUoZnNJpQIHBbgMOiXqfATFjJl5FjEkSf7GUHohlGVls9MX2JmVvknzsiitd
@@ -54,11 +53,11 @@ c7pZAoGATd9NckT0XtXLEsF3IraDivq8dP6bccX2DNfS8UeEvRRrRwpFpSRrmuGb
 jbG4yzoIX4RjQfj/z48hwhJB+cKiN9WwcPsFXtHe7v3F6BRwK0JUfrCiXad8/SGZ
 KAf7Dfqi608zBdnPWHacre2Y35gPHB00nFQOLS6u46aBNSq07YA=
 -----END RSA PRIVATE KEY-----
-EOS
+DOC
   end
 
   let(:another_valid_key) do
-  <<EOS
+    <<DOC
 -----BEGIN RSA PRIVATE KEY-----
 MIIEpAIBAAKCAQEAoISxYJBTPAeAzFnm+lE/ljLlmGal2Xr3vwZKkvJiuKA/m4QJ
 0ZNdtkBSDOVuG2dXVv6W4sChRtsCdvuVe7bjTYvlU8TWM3VEJDL9l9cRXScxxlKQ
@@ -86,15 +85,16 @@ B2ZXgoUCgYAGa13P0ggUf5BMJpBd8S08jKRyvZb1CDXcUCuGtk2yEx45ern9U5WY
 zJ13E5z9MKKO8nkGBqrRfjJa8Xhxk4HKNFuzHEet5lvNE7IKCF4YQRb0ZBhnb/78
 +4ZKjFki1RrWRNSw9TdvrK6qaDKgTtCTtfRVXAYQXUgq7lSFOTtL3A==
 -----END RSA PRIVATE KEY-----
-EOS
+DOC
   end
+  # rubocop:enable Layout/IndentHeredoc
 
   let(:valid_cert_but_indented) do
-    valid_cert.gsub(/^/, '  ')
+    valid_cert.gsub(%r{^}, '  ')
   end
 
   let(:valid_key_but_indented) do
-    valid_key.gsub(/^/, '  ')
+    valid_key.gsub(%r{^}, '  ')
   end
 
   let(:malformed_cert) do
@@ -113,58 +113,58 @@ EOS
     'bar'
   end
 
-  context 'function signature validation' do
+  context 'with function signature validation' do
     it { is_expected.not_to eq(nil) }
-    it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
-    it { is_expected.to run.with_params(0, 1, 2, 3).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
+    it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+    it { is_expected.to run.with_params(0, 1, 2, 3).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
   end
 
-  context 'valid input' do
+  context 'with valid input' do
     describe 'valid certificate and key' do
       it { is_expected.to run.with_params(valid_cert, valid_key) }
     end
   end
 
-  context 'bad input' do
+  context 'with bad input' do
     describe 'valid certificate, valid but indented key' do
-      it { is_expected.to run.with_params(valid_cert, valid_key_but_indented).and_raise_error(Puppet::ParseError, /Not a valid RSA key/) }
+      it { is_expected.to run.with_params(valid_cert, valid_key_but_indented).and_raise_error(Puppet::ParseError, %r{Not a valid RSA key}) }
     end
 
     describe 'valid certificate, malformed key' do
-      it { is_expected.to run.with_params(valid_cert, malformed_key).and_raise_error(Puppet::ParseError, /Not a valid RSA key/) }
+      it { is_expected.to run.with_params(valid_cert, malformed_key).and_raise_error(Puppet::ParseError, %r{Not a valid RSA key}) }
     end
 
     describe 'valid certificate, bad key' do
-      it { is_expected.to run.with_params(valid_cert, bad_key).and_raise_error(Puppet::ParseError, /Not a valid RSA key/) }
+      it { is_expected.to run.with_params(valid_cert, bad_key).and_raise_error(Puppet::ParseError, %r{Not a valid RSA key}) }
     end
 
     describe 'valid but indented certificate, valid key' do
-      it { is_expected.to run.with_params(valid_cert_but_indented, valid_key).and_raise_error(Puppet::ParseError, /Not a valid x509 certificate/) }
+      it { is_expected.to run.with_params(valid_cert_but_indented, valid_key).and_raise_error(Puppet::ParseError, %r{Not a valid x509 certificate}) }
     end
 
     describe 'malformed certificate, valid key' do
-      it { is_expected.to run.with_params(malformed_cert, valid_key).and_raise_error(Puppet::ParseError, /Not a valid x509 certificate/) }
+      it { is_expected.to run.with_params(malformed_cert, valid_key).and_raise_error(Puppet::ParseError, %r{Not a valid x509 certificate}) }
     end
 
     describe 'bad certificate, valid key' do
-      it { is_expected.to run.with_params(bad_cert, valid_key).and_raise_error(Puppet::ParseError, /Not a valid x509 certificate/) }
+      it { is_expected.to run.with_params(bad_cert, valid_key).and_raise_error(Puppet::ParseError, %r{Not a valid x509 certificate}) }
     end
 
     describe 'validate certificate and key; certficate not signed by key' do
-      it { is_expected.to run.with_params(valid_cert, another_valid_key).and_raise_error(Puppet::ParseError, /Certificate signature does not match supplied key/) }
+      it { is_expected.to run.with_params(valid_cert, another_valid_key).and_raise_error(Puppet::ParseError, %r{Certificate signature does not match supplied key}) }
     end
 
     describe 'valid cert and key but arguments in wrong order' do
-      it { is_expected.to run.with_params(valid_key, valid_cert).and_raise_error(Puppet::ParseError, /Not a valid x509 certificate/) }
+      it { is_expected.to run.with_params(valid_key, valid_cert).and_raise_error(Puppet::ParseError, %r{Not a valid x509 certificate}) }
     end
 
     describe 'non-string arguments' do
-      it { is_expected.to run.with_params({}, {}).and_raise_error(Puppet::ParseError, /is not a string/) }
-      it { is_expected.to run.with_params(1, 1).and_raise_error(Puppet::ParseError, /is not a string/) }
-      it { is_expected.to run.with_params(true, true).and_raise_error(Puppet::ParseError, /is not a string/) }
-      it { is_expected.to run.with_params("foo", {}).and_raise_error(Puppet::ParseError, /is not a string/) }
-      it { is_expected.to run.with_params(1, "bar").and_raise_error(Puppet::ParseError, /is not a string/) }
-      it { is_expected.to run.with_params("baz", true).and_raise_error(Puppet::ParseError, /is not a string/) }
+      it { is_expected.to run.with_params({}, {}).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+      it { is_expected.to run.with_params(1, 1).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+      it { is_expected.to run.with_params(true, true).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+      it { is_expected.to run.with_params('foo', {}).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+      it { is_expected.to run.with_params(1, 'bar').and_raise_error(Puppet::ParseError, %r{is not a string}) }
+      it { is_expected.to run.with_params('baz', true).and_raise_error(Puppet::ParseError, %r{is not a string}) }
     end
   end
 
@@ -175,6 +175,6 @@ EOS
     end_pos = middle + (chars_to_truncate / 2)
 
     string[start_pos...end_pos] = ''
-    return string
+    string
   end
 end