summaryrefslogtreecommitdiff
blob: 6688fa9aa01a5df6aa2bea9d73c2b67610c9179e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
diff -Naur jruby-1.2.0.orig/test/externals/ruby_test/lib/test/helper.rb jruby-1.2.0/test/externals/ruby_test/lib/test/helper.rb
--- jruby-1.2.0.orig/test/externals/ruby_test/lib/test/helper.rb	2009-03-16 15:16:02.000000000 +0000
+++ jruby-1.2.0/test/externals/ruby_test/lib/test/helper.rb	2009-04-18 00:34:02.198853097 +0100
@@ -235,31 +235,34 @@
       # Get the user of the current process.
       #
       def get_user
-         user = ENV['USERNAME'] || ENV['USER']
          if WINDOWS
-            if user.nil?
-               buf = 0.chr * MAX_PATH
-               if GetUserName.call(buf, buf.length) == 0
-                  raise "Unable to get user name"
-               end
-               user = buf.unpack("A*")
+            buf = 0.chr * MAX_PATH
+            if GetUserName.call(buf, buf.length) != 0
+	       buf.unpack("A*")
+	    elsif user = ENV['USERNAME'] || ENV['USER']
+	       user
+	    else
+               raise "Unable to get user name"
             end
          else
-            user ||= Etc.getpwuid(Process.uid).name
+            Etc.getpwuid(Process.uid).name
          end
-         user
       end
 
-      # Returns the home directory of the current process owner.
-      # 
+      # Returns the home directory of the current process owner
+      # according to the HOME/USERPROFILE variable.
       def get_home
-         home = ENV['HOME'] || ENV['USERPROFILE']
+         ENV['HOME'] || ENV['USERPROFILE'] || get_real_home
+      end
+      
+      # Returns the home directory of the current process owner
+      # according to the system.
+      def get_real_home
          if WINDOWS
-            home ||= "C:\\Documents and Settings\\" + get_user
+            "C:\\Documents and Settings\\" + get_user
          else
-            home ||= Etc.getpwuid(Process.uid).dir
+            Etc.getpwuid(Process.uid).dir
          end
-         home
       end
       
       # Returns the current umask of the process.
diff -Naur jruby-1.2.0.orig/test/externals/ruby_test/test/core/File/class/tc_expand_path.rb jruby-1.2.0/test/externals/ruby_test/test/core/File/class/tc_expand_path.rb
--- jruby-1.2.0.orig/test/externals/ruby_test/test/core/File/class/tc_expand_path.rb	2009-03-16 15:15:49.000000000 +0000
+++ jruby-1.2.0/test/externals/ruby_test/test/core/File/class/tc_expand_path.rb	2009-04-18 00:20:58.966617568 +0100
@@ -12,6 +12,7 @@
    def setup
       @user = get_user
       @home = get_home
+      @real_home = get_real_home
       @pwd  = Dir.pwd
       ENV['HOME'] = ENV['USERPROFILE'] if WINDOWS
    end
@@ -88,17 +89,21 @@
    end
 
    def test_expand_path_with_tilde
-      assert_equal(@home, File.expand_path("~#{@user}"))
-      assert_equal(File.join(@home, 'bin'), File.expand_path("~#{@user}/bin"))
+      { "~" => @home, "~#{@user}" => @real_home }.each do |tilde,path|
+         assert_equal(path, File.expand_path(tilde))
+         assert_equal(File.join(path, 'bin'), File.expand_path("#{tilde}/bin"))
+      end
    end
 
    # Second argument ignored if tilde is present and it's at position 0.
    def test_expand_path_with_tilde_and_dir
-      assert_equal(@home, File.expand_path("~#{@user}", '.'))
-      assert_equal(@home, File.expand_path("~#{@user}", '..'))
-      assert_equal(@home, File.expand_path("~#{@user}", '/tmp'))
-      assert_equal(@home, File.expand_path("~#{@user}", '../tmp'))
-      assert_equal(File.join(@home, 'bin'), File.expand_path("~#{@user}/bin", '/tmp'))
+      { "~" => @home, "~#{@user}" => @real_home }.each do |tilde,path|
+         assert_equal(path, File.expand_path(tilde, '.'))
+         assert_equal(path, File.expand_path(tilde, '..'))
+         assert_equal(path, File.expand_path(tilde, '/tmp'))
+         assert_equal(path, File.expand_path(tilde, '../tmp'))
+         assert_equal(File.join(path, 'bin'), File.expand_path("#{tilde}/bin", '/tmp'))
+      end
    end
 
    def test_expand_path_returns_tainted_string
@@ -120,5 +126,6 @@
       @pwd  = nil
       @user = nil
       @home = nil
+      @real_home = nil
    end
 end
diff -Naur jruby-1.2.0.orig/test/externals/ruby_test/test/core/ProcessGID/class/tc_rid.rb jruby-1.2.0/test/externals/ruby_test/test/core/ProcessGID/class/tc_rid.rb
--- jruby-1.2.0.orig/test/externals/ruby_test/test/core/ProcessGID/class/tc_rid.rb	2009-03-16 15:16:00.000000000 +0000
+++ jruby-1.2.0/test/externals/ruby_test/test/core/ProcessGID/class/tc_rid.rb	2009-04-18 21:24:02.653686353 +0100
@@ -12,7 +12,7 @@
 
    def setup
       unless WINDOWS
-         @gid = Etc.getpwnam(Etc.getlogin).gid
+         @gid = `id -g`.to_i
       end
    end
 
diff -Naur jruby-1.2.0.orig/test/externals/ruby_test/test/core/ProcessUID/class/tc_rid.rb jruby-1.2.0/test/externals/ruby_test/test/core/ProcessUID/class/tc_rid.rb
--- jruby-1.2.0.orig/test/externals/ruby_test/test/core/ProcessUID/class/tc_rid.rb	2009-03-16 15:15:50.000000000 +0000
+++ jruby-1.2.0/test/externals/ruby_test/test/core/ProcessUID/class/tc_rid.rb	2009-04-18 21:30:26.748686198 +0100
@@ -12,7 +12,7 @@
 
    def setup
       unless WINDOWS
-         @uid = Etc.getpwnam(Etc.getlogin).uid
+         @uid = `id -u`.to_i
       end
    end