[前][次][番号順一覧][スレッド一覧]

ruby-changes:28679

From: nagachika <ko1@a...>
Date: Tue, 14 May 2013 20:23:39 +0900 (JST)
Subject: [ruby-changes:28679] nagachika:r40731 (ruby_2_0_0): merge revision(s) 39491: [Backport #8403]

nagachika	2013-05-14 20:23:11 +0900 (Tue, 14 May 2013)

  New Revision: 40731

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40731

  Log:
    merge revision(s) 39491: [Backport #8403]
    
    * lib/rubygems/config_file.rb:  Lazily load .gem/credentials to only
      check permissions when necessary.  RubyGems bug #465
    
    * test/rubygems/test_gem_config_file.rb:  Test for the above.
    
    * test/rubygems/test_gem_commands_push_command.rb:  Remove duplicated
      test.

  Modified directories:
    branches/ruby_2_0_0/
  Modified files:
    branches/ruby_2_0_0/ChangeLog
    branches/ruby_2_0_0/lib/rubygems/config_file.rb
    branches/ruby_2_0_0/test/rubygems/test_gem_commands_push_command.rb
    branches/ruby_2_0_0/test/rubygems/test_gem_config_file.rb
    branches/ruby_2_0_0/version.h

Index: ruby_2_0_0/ChangeLog
===================================================================
--- ruby_2_0_0/ChangeLog	(revision 40730)
+++ ruby_2_0_0/ChangeLog	(revision 40731)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1
+Tue May 14 20:21:41 2013  Eric Hodel  <drbrain@s...>
+
+	* lib/rubygems/config_file.rb:  Lazily load .gem/credentials to only
+	  check permissions when necessary.  RubyGems bug #465
+	* test/rubygems/test_gem_config_file.rb:  Test for the above.
+
+	* test/rubygems/test_gem_commands_push_command.rb:  Remove duplicated
+	  test.
+
 Tue May 14 20:11:00 2013  CHIKANAGA Tomoyuki  <nagachika@r...>
 
 	* ext/dl/lib/dl/func.rb (DL::Function#call): check tainted when
Index: ruby_2_0_0/lib/rubygems/config_file.rb
===================================================================
--- ruby_2_0_0/lib/rubygems/config_file.rb	(revision 40730)
+++ ruby_2_0_0/lib/rubygems/config_file.rb	(revision 40731)
@@ -127,16 +127,6 @@ class Gem::ConfigFile https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/lib/rubygems/config_file.rb#L127
   attr_accessor :update_sources
 
   ##
-  # API key for RubyGems.org
-
-  attr_reader :rubygems_api_key
-
-  ##
-  # Hash of RubyGems.org and alternate API keys
-
-  attr_reader :api_keys
-
-  ##
   # True if we want to force specification of gem server when pushing a gem
 
   attr_accessor :disable_default_gem_server
@@ -221,13 +211,23 @@ class Gem::ConfigFile https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/lib/rubygems/config_file.rb#L211
     @ssl_verify_mode  = @hash[:ssl_verify_mode]  if @hash.key? :ssl_verify_mode
     @ssl_ca_cert      = @hash[:ssl_ca_cert]      if @hash.key? :ssl_ca_cert
 
-    load_api_keys
+    @api_keys         = nil
+    @rubygems_api_key = nil
 
     Gem.sources = @hash[:sources] if @hash.key? :sources
     handle_arguments arg_list
   end
 
   ##
+  # Hash of RubyGems.org and alternate API keys
+
+  def api_keys
+    load_api_keys unless @api_keys
+
+    @api_keys
+  end
+
+  ##
   # Checks the permissions of the credentials file.  If they are not 0600 an
   # error message is displayed and RubyGems aborts.
 
@@ -273,11 +273,24 @@ if you believe they were disclosed to a https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/lib/rubygems/config_file.rb#L273
                 end
 
     if @api_keys.key? :rubygems_api_key then
-      @rubygems_api_key = @api_keys[:rubygems_api_key]
-      @api_keys[:rubygems] = @api_keys.delete :rubygems_api_key unless @api_keys.key? :rubygems
+      @rubygems_api_key    = @api_keys[:rubygems_api_key]
+      @api_keys[:rubygems] = @api_keys.delete :rubygems_api_key unless
+        @api_keys.key? :rubygems
     end
   end
 
+  ##
+  # Returns the RubyGems.org API key
+
+  def rubygems_api_key
+    load_api_keys unless @rubygems_api_key
+
+    @rubygems_api_key
+  end
+
+  ##
+  # Sets the RubyGems.org API key to +api_key+
+
   def rubygems_api_key= api_key
     check_credentials_permissions
 
Index: ruby_2_0_0/version.h
===================================================================
--- ruby_2_0_0/version.h	(revision 40730)
+++ ruby_2_0_0/version.h	(revision 40731)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1
 #define RUBY_VERSION "2.0.0"
 #define RUBY_RELEASE_DATE "2013-05-14"
-#define RUBY_PATCHLEVEL 194
+#define RUBY_PATCHLEVEL 195
 
 #define RUBY_RELEASE_YEAR 2013
 #define RUBY_RELEASE_MONTH 5
Index: ruby_2_0_0/test/rubygems/test_gem_commands_push_command.rb
===================================================================
--- ruby_2_0_0/test/rubygems/test_gem_commands_push_command.rb	(revision 40730)
+++ ruby_2_0_0/test/rubygems/test_gem_commands_push_command.rb	(revision 40731)
@@ -18,7 +18,7 @@ class TestGemCommandsPushCommand < Gem:: https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/rubygems/test_gem_commands_push_command.rb#L18
       "ed244fbf2b1a52e012da8616c512fa47f9aa5250"
 
     @spec, @path = util_gem "freewill", "1.0.0"
-    @host = Gem.host
+    @host = 'https://rubygems.example'
     @api_key = Gem.configuration.rubygems_api_key
 
     @fetcher = Gem::FakeFetcher.new
@@ -61,6 +61,27 @@ class TestGemCommandsPushCommand < Gem:: https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/rubygems/test_gem_commands_push_command.rb#L61
     assert_match @response, @ui.output
   end
 
+  def test_execute_host
+    host = 'https://other.example'
+
+    open 'example', 'w' do |io| io.write 'hello' end
+
+    @response = "Successfully registered gem: freewill (1.0.0)"
+    @fetcher.data["#{host}/api/v1/gems"] = [@response, 200, 'OK']
+    @fetcher.data["#{Gem.host}/api/v1/gems"] =
+      ['fail', 500, 'Internal Server Error']
+
+    @cmd.options[:host] = host
+    @cmd.options[:args] = %w[example]
+
+    @cmd.execute
+
+    assert_equal Net::HTTP::Post, @fetcher.last_request.class
+    assert_equal 'hello', @fetcher.last_request.body
+    assert_equal "application/octet-stream",
+                 @fetcher.last_request["Content-Type"]
+  end
+
   def test_sending_when_default_host_disabled
     Gem.configuration.disable_default_gem_server = true
     response = "You must specify a gem server"
@@ -110,29 +131,13 @@ class TestGemCommandsPushCommand < Gem:: https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/rubygems/test_gem_commands_push_command.rb#L131
     send_battery
   end
 
-  def test_sending_gem_default
+  def test_sending_gem
     @response = "Successfully registered gem: freewill (1.0.0)"
     @fetcher.data["#{@host}/api/v1/gems"]  = [@response, 200, 'OK']
 
     send_battery
   end
 
-  def test_sending_gem_host
-    @response = "Successfully registered gem: freewill (1.0.0)"
-    @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, 'OK']
-    @cmd.options['host'] = "#{Gem.host}"
-
-    send_battery
-  end
-
-  def test_sending_gem_ENV
-    @response = "Successfully registered gem: freewill (1.0.0)"
-    @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, 'OK']
-    ENV["RUBYGEMS_HOST"] = "#{Gem.host}"
-
-    send_battery
-  end
-
   def test_raises_error_with_no_arguments
     def @cmd.sign_in(*); end
     assert_raises Gem::CommandLineError do
@@ -143,6 +148,7 @@ class TestGemCommandsPushCommand < Gem:: https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/rubygems/test_gem_commands_push_command.rb#L148
   def test_sending_gem_denied
     response = "You don't have permission to push to this gem"
     @fetcher.data["#{@host}/api/v1/gems"] = [response, 403, 'Forbidden']
+    @cmd.instance_variable_set :@host, @host
 
     assert_raises Gem::MockGemUi::TermError do
       use_ui @ui do
@@ -162,6 +168,7 @@ class TestGemCommandsPushCommand < Gem:: https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/rubygems/test_gem_commands_push_command.rb#L168
     Gem.configuration.load_api_keys
 
     @cmd.handle_options %w(-k other)
+    @cmd.instance_variable_set :@host, @host
     @cmd.send_gem(@path)
 
     assert_equal Gem.configuration.api_keys[:other],
Index: ruby_2_0_0/test/rubygems/test_gem_config_file.rb
===================================================================
--- ruby_2_0_0/test/rubygems/test_gem_config_file.rb	(revision 40730)
+++ ruby_2_0_0/test/rubygems/test_gem_config_file.rb	(revision 40731)
@@ -164,6 +164,21 @@ class TestGemConfigFile < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/rubygems/test_gem_config_file.rb#L164
     assert_equal 2048, @cfg.bulk_threshold
   end
 
+  def test_api_keys
+    assert_nil @cfg.instance_variable_get :@api_keys
+
+    temp_cred = File.join Gem.user_home, '.gem', 'credentials'
+    FileUtils.mkdir File.dirname(temp_cred)
+    File.open temp_cred, 'w', 0600 do |fp|
+      fp.puts ':rubygems_api_key: 701229f217cdf23b1344c7b4b54ca97'
+    end
+
+    util_config_file
+
+    assert_equal({:rubygems => '701229f217cdf23b1344c7b4b54ca97'},
+                 @cfg.api_keys)
+  end
+
   def test_check_credentials_permissions
     skip 'chmod not supported' if win_platform?
 

Property changes on: ruby_2_0_0
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r39491


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]