Skip to content

Commit

Permalink
Merge pull request rubygems#338 from zettabyte/credentials-file-permi…
Browse files Browse the repository at this point in the history
…ssions

Credentials file permissions
  • Loading branch information
evanphx committed Jun 15, 2012
2 parents 5077a89 + e9960c7 commit 8091e5d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rubygems/config_file.rb
Expand Up @@ -235,7 +235,8 @@ def rubygems_api_key=(api_key)

Gem.load_yaml

File.open(credentials_path, 'w') do |f|
permissions = 0600 & (~File.umask)
File.open(credentials_path, 'w', permissions) do |f|
f.write config.to_yaml
end

Expand Down
8 changes: 8 additions & 0 deletions test/rubygems/test_gem_config_file.rb
Expand Up @@ -309,6 +309,14 @@ def test_load_api_keys_from_config
:other => 'a5fdbb6ba150cbb83aad2bb2fede64c'}, @cfg.api_keys)
end

def test_save_credentials_file_with_strict_permissions
util_config_file
FileUtils.mkdir File.dirname(@cfg.credentials_path)
@cfg.rubygems_api_key = '701229f217cdf23b1344c7b4b54ca97'
mode = 0100600 & (~File.umask)
assert_equal mode, File.stat(@cfg.credentials_path).mode unless win_platform?
end

def util_config_file(args = @cfg_args)
@cfg = Gem::ConfigFile.new args
end
Expand Down

0 comments on commit 8091e5d

Please sign in to comment.