Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/rubygems/commands/install_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ def execute

load_hooks

if ENV["GEM_HOST_API_KEY"]
Gem::RemoteFetcher.fetcher.headers[:authorization] = ENV["GEM_HOST_API_KEY"]
end

exit_code = install_gems

show_installed
Expand Down
20 changes: 20 additions & 0 deletions test/rubygems/test_gem_commands_install_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def teardown
Gem::Command.build_args = @orig_args
File.unlink @gemdeps if File.file? @gemdeps
File.unlink "#{@gemdeps}.lock" if File.file? "#{@gemdeps}.lock"

if defined? Gem::RemoteFetcher
Gem::RemoteFetcher.fetcher = nil
end
end

def test_execute_exclude_prerelease
Expand Down Expand Up @@ -760,6 +764,22 @@ def test_execute_remote
assert_match "1 gem installed", @ui.output
end

def test_execute_remote_gem_host_api_key
Gem::RemoteFetcher.fetcher = @fetcher = Gem::FakeFetcher.new
@a1, @a1_gem = util_gem "a", "1"
util_setup_spec_fetcher @a1
@fetcher.data["http://gems.example.com/gems/a-1.gem"] = Gem.read_binary(@a1_gem)

ENV["GEM_HOST_API_KEY"] = "temporary_secret_key"
@cmd.options[:args] = %w[a]
use_ui @stub_ui do
@cmd.execute
end

assert_match "1 gem installed", @ui.output
assert_equal "temporary_secret_key", @fetcher.headers[:authorization]
end

def test_execute_with_invalid_gem_file
FileUtils.touch("a.gem")

Expand Down
2 changes: 2 additions & 0 deletions test/rubygems/utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@

class Gem::FakeFetcher
attr_reader :data
attr_reader :headers
attr_reader :last_request
attr_accessor :paths

def initialize
@data = {}
@headers = {}
@paths = []
end

Expand Down