netrc 0.7.4 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/changelog.txt +5 -0
  2. data/lib/netrc.rb +10 -6
  3. data/test/test_netrc.rb +31 -2
  4. metadata +4 -4
data/changelog.txt CHANGED
@@ -1,3 +1,8 @@
1
+ 0.7.5 06/25/12
2
+ ==============
3
+
4
+ * improved operating system detection
5
+
1
6
  0.7.4 06/04/12
2
7
  ==============
3
8
 
data/lib/netrc.rb CHANGED
@@ -1,19 +1,23 @@
1
+ require 'rbconfig'
2
+
1
3
  class Netrc
2
- VERSION = "0.7.4"
3
- CYGWIN = RUBY_PLATFORM =~ /cygwin/i
4
- WINDOWS = RUBY_PLATFORM =~ /win32|mingw32/i
4
+ VERSION = "0.7.5"
5
+
6
+ # see http://stackoverflow.com/questions/4871309/what-is-the-correct-way-to-detect-if-ruby-is-running-on-windows
7
+ WINDOWS = RbConfig::CONFIG["host_os"] =~ /mswin|mingw|cygwin/
8
+ CYGWIN = RbConfig::CONFIG["host_os"] =~ /cygwin/
5
9
 
6
10
  def self.default_path
7
- if WINDOWS
11
+ if WINDOWS && !CYGWIN
8
12
  File.join(ENV['USERPROFILE'].gsub("\\","/"), "_netrc")
9
13
  else
10
- File.join(ENV["HOME"], ".netrc")
14
+ File.join((ENV["HOME"] || "./"), ".netrc")
11
15
  end
12
16
  end
13
17
 
14
18
  def self.check_permissions(path)
15
19
  perm = File.stat(path).mode & 0777
16
- if perm != 0600 && !(CYGWIN) && !(WINDOWS)
20
+ if perm != 0600 && !(WINDOWS)
17
21
  raise Error, "Permission bits for '#{path}' should be 0600, but are "+perm.to_s(8)
18
22
  end
19
23
  end
data/test/test_netrc.rb CHANGED
@@ -3,8 +3,10 @@ require 'test/unit'
3
3
  require 'fileutils'
4
4
 
5
5
  require File.expand_path("#{File.dirname(__FILE__)}/../lib/netrc")
6
+ require "rbconfig"
6
7
 
7
8
  class TestNetrc < Test::Unit::TestCase
9
+
8
10
  def setup
9
11
  File.chmod(0600, "data/sample.netrc")
10
12
  File.chmod(0644, "data/permissive.netrc")
@@ -35,9 +37,23 @@ class TestNetrc < Test::Unit::TestCase
35
37
  end
36
38
 
37
39
  def test_permission_error
40
+ original_windows = Netrc::WINDOWS
41
+ Netrc.const_set(:WINDOWS, false)
42
+ Netrc.read("data/permissive.netrc")
43
+ rescue Netrc::Error
44
+ assert true, "Should raise an error if permissions are wrong on a non-windows system."
45
+ ensure
46
+ Netrc.const_set(:WINDOWS, original_windows)
47
+ end
48
+
49
+ def test_permission_error_windows
50
+ original_windows = Netrc::WINDOWS
51
+ Netrc.const_set(:WINDOWS, true)
38
52
  Netrc.read("data/permissive.netrc")
39
- assert false, "Should raise an error if permissions are wrong."
40
53
  rescue Netrc::Error
54
+ assert false, "Should not raise an error if permissions are wrong on a non-windows system."
55
+ ensure
56
+ Netrc.const_set(:WINDOWS, original_windows)
41
57
  end
42
58
 
43
59
  def test_round_trip
@@ -98,7 +114,9 @@ class TestNetrc < Test::Unit::TestCase
98
114
  FileUtils.rm_f("/tmp/created.netrc")
99
115
  n = Netrc.read("/tmp/created.netrc")
100
116
  n.save
101
- assert_equal(0600, File.stat("/tmp/created.netrc").mode & 0777)
117
+ unless Netrc::WINDOWS
118
+ assert_equal(0600, File.stat("/tmp/created.netrc").mode & 0777)
119
+ end
102
120
  end
103
121
 
104
122
  def test_encrypted_roundtrip
@@ -111,4 +129,15 @@ class TestNetrc < Test::Unit::TestCase
111
129
  assert_equal(["a", "b"], Netrc.read("/tmp/test.netrc.gpg")["m"])
112
130
  end
113
131
  end
132
+
133
+ def test_missing_environment
134
+ nil_home = nil
135
+ ENV["HOME"], nil_home = nil_home, ENV["HOME"]
136
+ n = Netrc.read
137
+ assert_equal(nil, n["x"])
138
+ ensure
139
+ ENV["HOME"], nil_home = nil_home, ENV["HOME"]
140
+ end
141
+
142
+
114
143
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netrc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.7.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-06-04 00:00:00.000000000 Z
13
+ date: 2012-06-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: turn
17
- requirement: &70101253021640 !ruby/object:Gem::Requirement
17
+ requirement: &70272465006100 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,7 +22,7 @@ dependencies:
22
22
  version: '0'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *70101253021640
25
+ version_requirements: *70272465006100
26
26
  description: This library can read and update netrc files, preserving formatting including
27
27
  comments and whitespace.
28
28
  email: geemus@gmail.com