Skip to content

Commit

Permalink
Added allow_permissive_netrc_file config option
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Fedorov committed Jul 2, 2014
1 parent b02d378 commit 9fbb2c2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Readme.md
Expand Up @@ -18,6 +18,12 @@ Read the user's default netrc file (`$HOME/.netrc` on Unix;

n = Netrc.read

Configure netrc to allow permissive files (with permissions other than 0600):

Netrc.configure do |config|
config[:allow_permissive_netrc_file] = true
end

Look up a username and password:

user, pass = n["example.com"]
Expand Down
11 changes: 10 additions & 1 deletion lib/netrc.rb
Expand Up @@ -15,9 +15,18 @@ def self.default_path
end
end

def self.config
@config ||= {}
end

def self.configure
yield(self.config) if block_given?
self.config
end

def self.check_permissions(path)
perm = File.stat(path).mode & 0777
if perm != 0600 && !(WINDOWS)
if perm != 0600 && !(WINDOWS) && !(Netrc.config[:allow_permissive_netrc_file])
raise Error, "Permission bits for '#{path}' should be 0600, but are "+perm.to_s(8)
end
end
Expand Down
20 changes: 19 additions & 1 deletion test/test_netrc.rb
Expand Up @@ -62,12 +62,30 @@ def test_permission_error
original_windows = Netrc::WINDOWS
Netrc.const_set(:WINDOWS, false)
Netrc.read("data/permissive.netrc")
assert false, "Should raise an error if permissions are wrong on a non-windows system."
rescue Netrc::Error
assert true, "Should raise an error if permissions are wrong on a non-windows system."
assert true, ""
ensure
Netrc.const_set(:WINDOWS, original_windows)
end

def test_allow_permissive_netrc_file_option
Netrc.configure do |config|
config[:allow_permissive_netrc_file] = true
end
original_windows = Netrc::WINDOWS
Netrc.const_set(:WINDOWS, false)
Netrc.read("data/permissive.netrc")
assert true, ""
rescue Netrc::Error
assert false, "Should not raise an error if allow_permissive_netrc_file option is set to true"
ensure
Netrc.const_set(:WINDOWS, original_windows)
Netrc.configure do |config|
config[:allow_permissive_netrc_file] = false
end
end

def test_permission_error_windows
original_windows = Netrc::WINDOWS
Netrc.const_set(:WINDOWS, true)
Expand Down

0 comments on commit 9fbb2c2

Please sign in to comment.