From d5299cb2c1149ff187b3b1da4d70a04253d82027 Mon Sep 17 00:00:00 2001 From: mokha Date: Mon, 14 May 2018 18:38:39 -0600 Subject: test mutual tls connection. --- test/net/client_test.rb | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/net/client_test.rb b/test/net/client_test.rb index 8b9ee57..c6226c5 100644 --- a/test/net/client_test.rb +++ b/test/net/client_test.rb @@ -39,8 +39,8 @@ class ClientTest < Minitest::Test def test_get_with_headers headers = { 'Accept' => 'application/vnd.haveibeenpwned.v2+json' } WebMock.stub_request(:get, 'https://haveibeenpwned.com/api/breaches') - .with(headers: headers) - .to_return(status: 201, body: {}.to_json) + .with(headers: headers) + .to_return(status: 201, body: {}.to_json) uri = URI.parse('https://haveibeenpwned.com/api/breaches') @@ -53,8 +53,8 @@ class ClientTest < Minitest::Test uri = URI.parse('https://haveibeenpwned.com/api/breaches') body = { 'hello' => 'world' } WebMock.stub_request(:get, uri.to_s) - .with(body: body.to_json) - .to_return(status: 201, body: {}.to_json) + .with(body: body.to_json) + .to_return(status: 201, body: {}.to_json) response = subject.get(uri, body: body) @@ -103,4 +103,25 @@ class ClientTest < Minitest::Test assert_equal 'Congratulations!', JSON.parse(@response.body)['Message'] end end + + def test_client_tls + private_key = OpenSSL::PKey::RSA.new(2048) + 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) + 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 -- cgit v1.2.3