summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Bostock <matt@mattbostock.com>2016-01-08 11:01:51 +0000
committerMatt Bostock <matt@mattbostock.com>2016-01-08 11:09:45 +0000
commit4acba73b0055f98a4702f99b77af28f83c433b78 (patch)
tree3be5a3ecbe43046f74c1a88c0dfb916f9b957eec
parent97320ab42121a10b76c642b8378c82a888148e4b (diff)
downloadpuppet-stdlib-4acba73b0055f98a4702f99b77af28f83c433b78.tar.gz
puppet-stdlib-4acba73b0055f98a4702f99b77af28f83c433b78.tar.bz2
Test certificate and key with a truncated middle
Test a valid certificate and valid key that have had 48 characters removed from their middle, to simulate a malformed certificate and key. Suggested by @DavidS in https://github.com/puppetlabs/puppetlabs-stdlib/pull/552
-rwxr-xr-xspec/functions/validate_x509_rsa_key_pair_spec.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/functions/validate_x509_rsa_key_pair_spec.rb b/spec/functions/validate_x509_rsa_key_pair_spec.rb
index 048d65e..bfa7e38 100755
--- a/spec/functions/validate_x509_rsa_key_pair_spec.rb
+++ b/spec/functions/validate_x509_rsa_key_pair_spec.rb
@@ -97,6 +97,14 @@ EOS
valid_key.gsub(/^/, ' ')
end
+ let(:malformed_cert) do
+ truncate_middle(valid_cert)
+ end
+
+ let(:malformed_key) do
+ truncate_middle(valid_key)
+ end
+
let(:bad_cert) do
'foo'
end
@@ -126,6 +134,14 @@ EOS
it { is_expected.to run.with_params(valid_cert, valid_key_but_indented).and_raise_error(Puppet::ParseError, /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/) }
+ 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/) }
+ 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/) }
end
@@ -151,4 +167,14 @@ EOS
it { is_expected.to run.with_params("baz", true).and_raise_error(Puppet::ParseError, /is not a string/) }
end
end
+
+ def truncate_middle(string)
+ chars_to_truncate = 48
+ middle = (string.length / 2).floor
+ start_pos = middle - (chars_to_truncate / 2)
+ end_pos = middle + (chars_to_truncate / 2)
+
+ string[start_pos...end_pos] = ''
+ return string
+ end
end