summaryrefslogtreecommitdiff
path: root/spec/bundler/bundler/fetcher_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/bundler/bundler/fetcher_spec.rb')
-rw-r--r--spec/bundler/bundler/fetcher_spec.rb45
1 files changed, 43 insertions, 2 deletions
diff --git a/spec/bundler/bundler/fetcher_spec.rb b/spec/bundler/bundler/fetcher_spec.rb
index 585768343f..f9e52e09c0 100644
--- a/spec/bundler/bundler/fetcher_spec.rb
+++ b/spec/bundler/bundler/fetcher_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require "spec_helper"
+
require "bundler/fetcher"
RSpec.describe Bundler::Fetcher do
@@ -85,11 +85,52 @@ RSpec.describe Bundler::Fetcher do
end
end
end
+
+ context "when no ssl configuration is set" do
+ it "no cert" do
+ expect(fetcher.send(:connection).cert).to be_nil
+ expect(fetcher.send(:connection).key).to be_nil
+ end
+ end
+
+ context "when bunder ssl ssl configuration is set" do
+ before do
+ allow(Bundler.settings).to receive(:[]).and_return(nil)
+ allow(Bundler.settings).to receive(:[]).with(:ssl_client_cert).and_return("/cert")
+ expect(File).to receive(:read).with("/cert").and_return("")
+ expect(OpenSSL::X509::Certificate).to receive(:new).and_return("cert")
+ expect(OpenSSL::PKey::RSA).to receive(:new).and_return("key")
+ end
+ it "use bundler configuration" do
+ expect(fetcher.send(:connection).cert).to eq("cert")
+ expect(fetcher.send(:connection).key).to eq("key")
+ end
+ end
+
+ context "when gem ssl configuration is set" do
+ before do
+ allow(Bundler.rubygems.configuration).to receive_messages(
+ :http_proxy => nil,
+ :ssl_client_cert => "cert",
+ :ssl_ca_cert => "ca"
+ )
+ expect(File).to receive(:read).and_return("")
+ expect(OpenSSL::X509::Certificate).to receive(:new).and_return("cert")
+ expect(OpenSSL::PKey::RSA).to receive(:new).and_return("key")
+ store = double("ca store")
+ expect(store).to receive(:add_file)
+ expect(OpenSSL::X509::Store).to receive(:new).and_return(store)
+ end
+ it "use gem configuration" do
+ expect(fetcher.send(:connection).cert).to eq("cert")
+ expect(fetcher.send(:connection).key).to eq("key")
+ end
+ end
end
describe "#user_agent" do
it "builds user_agent with current ruby version and Bundler settings" do
- allow(Bundler.settings).to receive(:all).and_return(%w(foo bar))
+ allow(Bundler.settings).to receive(:all).and_return(%w[foo bar])
expect(fetcher.user_agent).to match(%r{bundler/(\d.)})
expect(fetcher.user_agent).to match(%r{rubygems/(\d.)})
expect(fetcher.user_agent).to match(%r{ruby/(\d.)})