summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormokha <mokha@cisco.com>2018-05-14 18:41:42 -0600
committermokha <mokha@cisco.com>2018-05-14 18:41:42 -0600
commit98c25e3240346fe91f8de46bb05f93894a484002 (patch)
tree5a85d4d730888b19f417352f8baff98cb2239b06
parentd5299cb2c1149ff187b3b1da4d70a04253d82027 (diff)
add test for client tls with passphrase.
-rw-r--r--test/net/client_test.rb26
-rw-r--r--test/test_helper.rb1
2 files changed, 27 insertions, 0 deletions
diff --git a/test/net/client_test.rb b/test/net/client_test.rb
index c6226c5..5743123 100644
--- a/test/net/client_test.rb
+++ b/test/net/client_test.rb
@@ -124,4 +124,30 @@ class ClientTest < Minitest::Test
end
assert(@called)
end
+
+ def test_client_tls_with_passphrase
+ private_key = OpenSSL::PKey::RSA.new(2048)
+ passphrase = SecureRandom.hex(16)
+ certificate = OpenSSL::X509::Certificate.new
+ certificate.not_after = certificate.not_before = Time.now
+ certificate.public_key = private_key.public_key
+ certificate.sign(private_key, OpenSSL::Digest::SHA256.new)
+
+ subject = Net::Hippie::Client.new(
+ certificate: certificate.to_pem,
+ key: private_key.export(OpenSSL::Cipher.new('AES-256-CBC'), passphrase),
+ passphrase: passphrase,
+ )
+ uri = URI.parse('https://haveibeenpwned.com/api/breaches')
+
+ @called = false
+ VCR.use_cassette('get_breaches') do
+ subject.get(uri) do |_request, response|
+ @called = true
+ refute_nil response
+ assert_equal '000webhost', JSON.parse(response.body)[0]['Title']
+ end
+ end
+ assert(@called)
+ end
end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 1ce00ef..19dd30f 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -1,5 +1,6 @@
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
require 'net/hippie'
+require 'securerandom'
require 'vcr'
require 'webmock'