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

ruby-changes:49644

From: mame <ko1@a...>
Date: Wed, 10 Jan 2018 22:30:30 +0900 (JST)
Subject: [ruby-changes:49644] mame:r61760 (trunk): spec/: skip some specs so that no failure occurs in root privilege

mame	2018-01-10 22:30:25 +0900 (Wed, 10 Jan 2018)

  New Revision: 61760

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61760

  Log:
    spec/: skip some specs so that no failure occurs in root privilege
    
    Follow up of r61757,  This change makes `sudo make test-spec` pass on my
    machine.

  Modified files:
    trunk/spec/ruby/core/dir/mkdir_spec.rb
    trunk/spec/ruby/core/dir/shared/delete.rb
    trunk/spec/ruby/core/file/chmod_spec.rb
    trunk/spec/ruby/core/file/open_spec.rb
    trunk/spec/ruby/core/file/owned_spec.rb
    trunk/spec/ruby/core/file/stat/owned_spec.rb
    trunk/spec/ruby/core/kernel/shared/require.rb
    trunk/spec/ruby/core/process/initgroups_spec.rb
    trunk/spec/ruby/library/socket/socket/bind_spec.rb
    trunk/spec/ruby/shared/file/writable.rb
Index: spec/ruby/core/process/initgroups_spec.rb
===================================================================
--- spec/ruby/core/process/initgroups_spec.rb	(revision 61759)
+++ spec/ruby/core/process/initgroups_spec.rb	(revision 61760)
@@ -2,18 +2,20 @@ require File.expand_path('../../../spec_ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/process/initgroups_spec.rb#L2
 
 describe "Process.initgroups" do
   platform_is_not :windows do
-    it "initializes the supplemental group access list" do
-      name = `id -un`.strip
-      groups = Process.groups
-      gid = groups.max.to_i + 1
-      augmented_groups = `id -G`.scan(/\d+/).map {|i| i.to_i} << gid
-      if Process.uid == 0
-        Process.groups = []
-        Process.initgroups(name, gid).sort.should == augmented_groups.sort
-        Process.groups.sort.should == augmented_groups.sort
-        Process.groups = groups
-      else
-        lambda { Process.initgroups(name, gid) }.should raise_error(Errno::EPERM)
+    as_user do
+      it "initializes the supplemental group access list" do
+        name = `id -un`.strip
+        groups = Process.groups
+        gid = groups.max.to_i + 1
+        augmented_groups = `id -G`.scan(/\d+/).map {|i| i.to_i} << gid
+        if Process.uid == 0
+          Process.groups = []
+          Process.initgroups(name, gid).sort.should == augmented_groups.sort
+          Process.groups.sort.should == augmented_groups.sort
+          Process.groups = groups
+        else
+          lambda { Process.initgroups(name, gid) }.should raise_error(Errno::EPERM)
+        end
       end
     end
   end
Index: spec/ruby/core/kernel/shared/require.rb
===================================================================
--- spec/ruby/core/kernel/shared/require.rb	(revision 61759)
+++ spec/ruby/core/kernel/shared/require.rb	(revision 61760)
@@ -27,21 +27,23 @@ describe :kernel_require_basic, shared: https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/shared/require.rb#L27
 
     # Can't make a file unreadable on these platforms
     platform_is_not :windows, :cygwin do
-      describe "with an unreadable file" do
-        before :each do
-          @path = tmp("unreadable_file.rb")
-          touch @path
-          File.chmod 0000, @path
-        end
+      as_user do
+        describe "with an unreadable file" do
+          before :each do
+            @path = tmp("unreadable_file.rb")
+            touch @path
+            File.chmod 0000, @path
+          end
 
-        after :each do
-          File.chmod 0666, @path
-          rm_r @path
-        end
+          after :each do
+            File.chmod 0666, @path
+            rm_r @path
+          end
 
-        it "raises a LoadError" do
-          File.exist?(@path).should be_true
-          lambda { @object.send(@method, @path) }.should raise_error(LoadError)
+          it "raises a LoadError" do
+            File.exist?(@path).should be_true
+            lambda { @object.send(@method, @path) }.should raise_error(LoadError)
+          end
         end
       end
     end
Index: spec/ruby/core/dir/mkdir_spec.rb
===================================================================
--- spec/ruby/core/dir/mkdir_spec.rb	(revision 61759)
+++ spec/ruby/core/dir/mkdir_spec.rb	(revision 61760)
@@ -66,20 +66,22 @@ end https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/dir/mkdir_spec.rb#L66
 # The permissions flag are not supported on Windows as stated in documentation:
 # The permissions may be modified by the value of File.umask, and are ignored on NT.
 platform_is_not :windows do
-  describe "Dir.mkdir" do
-    before :each do
-      @dir = tmp "noperms"
-    end
+  as_user do
+    describe "Dir.mkdir" do
+      before :each do
+        @dir = tmp "noperms"
+      end
 
-    after :each do
-      File.chmod 0777, @dir
-      rm_r @dir
-    end
+      after :each do
+        File.chmod 0777, @dir
+        rm_r @dir
+      end
 
-    it "raises a SystemCallError when lacking adequate permissions in the parent dir" do
-      Dir.mkdir @dir, 0000
+      it "raises a SystemCallError when lacking adequate permissions in the parent dir" do
+        Dir.mkdir @dir, 0000
 
-      lambda { Dir.mkdir "#{@dir}/subdir" }.should raise_error(SystemCallError)
+        lambda { Dir.mkdir "#{@dir}/subdir" }.should raise_error(SystemCallError)
+      end
     end
   end
 end
Index: spec/ruby/core/dir/shared/delete.rb
===================================================================
--- spec/ruby/core/dir/shared/delete.rb	(revision 61759)
+++ spec/ruby/core/dir/shared/delete.rb	(revision 61760)
@@ -49,13 +49,15 @@ describe :dir_delete, shared: true do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/dir/shared/delete.rb#L49
 
   # this won't work on Windows, since chmod(0000) does not remove all permissions
   platform_is_not :windows do
-    it "raises an Errno::EACCES if lacking adequate permissions to remove the directory" do
-      parent = DirSpecs.mock_rmdir("noperm")
-      child = DirSpecs.mock_rmdir("noperm", "child")
-      File.chmod(0000, parent)
-      lambda do
-        Dir.send @method, child
-      end.should raise_error(Errno::EACCES)
+    as_user do
+      it "raises an Errno::EACCES if lacking adequate permissions to remove the directory" do
+        parent = DirSpecs.mock_rmdir("noperm")
+        child = DirSpecs.mock_rmdir("noperm", "child")
+        File.chmod(0000, parent)
+        lambda do
+          Dir.send @method, child
+        end.should raise_error(Errno::EACCES)
+      end
     end
   end
 end
Index: spec/ruby/core/file/chmod_spec.rb
===================================================================
--- spec/ruby/core/file/chmod_spec.rb	(revision 61759)
+++ spec/ruby/core/file/chmod_spec.rb	(revision 61760)
@@ -71,37 +71,39 @@ describe "File#chmod" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/file/chmod_spec.rb#L71
   end
 
   platform_is_not :windows do
-    it "with '0222' makes file writable but not readable or executable" do
-      @file.chmod(0222)
-      File.readable?(@filename).should == false
-      File.writable?(@filename).should == true
-      File.executable?(@filename).should == false
-    end
-
-    it "with '0444' makes file readable but not writable or executable" do
-      @file.chmod(0444)
-      File.readable?(@filename).should == true
-      File.writable?(@filename).should == false
-      File.executable?(@filename).should == false
-    end
-
-    it "with '0666' makes file readable and writable but not executable" do
-      @file.chmod(0666)
-      File.readable?(@filename).should == true
-      File.writable?(@filename).should == true
-      File.executable?(@filename).should == false
-    end
-
-    it "with '0111' makes file executable but not readable or writable" do
-      @file.chmod(0111)
-      File.readable?(@filename).should == false
-      File.writable?(@filename).should == false
-      File.executable?(@filename).should == true
-    end
-
-    it "modifies the permission bits of the files specified" do
-      @file.chmod(0755)
-      File.stat(@filename).mode.should == 33261
+    as_user do
+      it "with '0222' makes file writable but not readable or executable" do
+        @file.chmod(0222)
+        File.readable?(@filename).should == false
+        File.writable?(@filename).should == true
+        File.executable?(@filename).should == false
+      end
+
+      it "with '0444' makes file readable but not writable or executable" do
+        @file.chmod(0444)
+        File.readable?(@filename).should == true
+        File.writable?(@filename).should == false
+        File.executable?(@filename).should == false
+      end
+
+      it "with '0666' makes file readable and writable but not executable" do
+        @file.chmod(0666)
+        File.readable?(@filename).should == true
+        File.writable?(@filename).should == true
+        File.executable?(@filename).should == false
+      end
+
+      it "with '0111' makes file executable but not readable or writable" do
+        @file.chmod(0111)
+        File.readable?(@filename).should == false
+        File.writable?(@filename).should == false
+        File.executable?(@filename).should == true
+      end
+
+      it "modifies the permission bits of the files specified" do
+        @file.chmod(0755)
+        File.stat(@filename).mode.should == 33261
+      end
     end
   end
 end
@@ -204,18 +206,20 @@ describe "File.chmod" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/file/chmod_spec.rb#L206
   end
 
   platform_is_not :windows do
-    it "with '0222' makes file writable but not readable or executable" do
-      File.chmod(0222, @file)
-      File.readable?(@file).should == false
-      File.writable?(@file).should == true
-      File.executable?(@file).should == false
-    end
-
-    it "with '0444' makes file readable but not writable or executable" do
-      File.chmod(0444, @file)
-      File.readable?(@file).should == true
-      File.writable?(@file).should == false
-      File.executable?(@file).should == false
+    as_user do
+      it "with '0222' makes file writable but not readable or executable" do
+        File.chmod(0222, @file)
+        File.readable?(@file).should == false
+        File.writable?(@file).should == true
+        File.executable?(@file).should == false
+      end
+
+      it "with '0444' makes file readable but not writable or executable" do
+        File.chmod(0444, @file)
+        File.readable?(@file).should == true
+        File.writable?(@file).should == false
+        File.executable?(@file).should == false
+      end
     end
 
     it "with '0666' makes file readable and writable but not executable" do
@@ -225,11 +229,13 @@ describe "File.chmod" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/file/chmod_spec.rb#L229
       File.executable?(@file).should == false
     end
 
-    it "with '0111' makes file executable but not readable or writable" do
-      File.chmod(0111, @file)
-      File.readable?(@file).should == false
-      File.writable?(@file).should == false
-      File.executable?(@file).should == true
+    as_user do
+      it "with '0111' makes file executable but not readable or writable" do
+        File.chmod(0111, @file)
+        File.readable?(@file).should == false
+        File.writable?(@file).should == false
+        File.executable?(@file).should == true
+      end
     end
 
     it "modifies the permission bits of the files specified" do
Index: spec/ruby/core/file/open_spec.rb
===================================================================
--- spec/ruby/core/file/open_spec.rb	(revision 61759)
+++ spec/ruby/core/file/open_spec.rb	(revision 61760)
@@ -147,11 +147,13 @@ describe "File.open" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/file/open_spec.rb#L147
   end
 
   platform_is_not :windows do
-    it "creates a new write-only file when invoked with 'w' and '0222'" do
-      rm_r @file
-      File.open(@file, 'w', 0222) {}
-      File.readable?(@file).should == false
-      File.writable?(@file).should == true
+    as_user do
+      it "creates a new write-only file when invoked with 'w' and '0222'" do
+        rm_r @file
+        File.open(@file, 'w', 0222) {}
+        File.readable?(@file).should == false
+        File.writable?(@file).should == true
+      end
     end
   end
 
@@ -464,17 +466,21 @@ describe "File.open" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/file/open_spec.rb#L466
   end
 
   platform_is_not :windows do
-    it "raises an Errno::EACCES when opening non-permitted file" do
-      @fh = File.open(@file, "w")
-      @fh.chmod(000)
-      lambda { fh1 = File.open(@file); fh1.close }.should raise_error(Errno::EACCES)
+    as_user do
+      it "raises an Errno::EACCES when opening non-permitted file" do
+        @fh = File.open(@file, "w")
+        @fh.chmod(000)
+        lambda { fh1 = File.open(@file); fh1.close }.should raise_error(Errno::EACCES)
+      end
     end
   end
 
-  it "raises an Errno::EACCES when opening read-only file" do
-    @fh = File.open(@file, "w")
-    @fh.chmod(0444)
-    lambda { File.open(@file, "w") }.should raise_error(Errno::EACCES)
+  as_user do
+    it "raises an Errno::EACCES when opening read-only file" do
+      @fh = File.open(@file, "w")
+      @fh.chmod(0444)
+      lambda { File.open(@file, "w") }.should raise_error(Errno::EACCES)
+    end
   end
 
   it "opens a file for binary read" do
Index: spec/ruby/core/file/owned_spec.rb
===================================================================
--- spec/ruby/core/file/owned_spec.rb	(revision 61759)
+++ spec/ruby/core/file/owned_spec.rb	(revision 61760)
@@ -24,9 +24,11 @@ describe "File.owned?" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/file/owned_spec.rb#L24
   end
 
   platform_is_not :windows do
-    it "returns false when the file is not owned by the user" do
-      system_file = '/etc/passwd'
-      File.owned?(system_file).should == false
+    as_user do
+      it "returns false when the file is not owned by the user" do
+        system_file = '/etc/passwd'
+        File.owned?(system_file).should == false
+      end
     end
   end
 
Index: spec/ruby/core/file/stat/owned_spec.rb
===================================================================
--- spec/ruby/core/file/stat/owned_spec.rb	(revision 61759)
+++ spec/ruby/core/file/stat/owned_spec.rb	(revision 61760)
@@ -22,10 +22,12 @@ describe "File::Stat#owned?" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/file/stat/owned_spec.rb#L22
   end
 
   platform_is_not :windows do
-    it "returns false if the file is not owned by the user" do
-      system_file = '/etc/passwd'
-      st = File.stat(system_file)
-      st.owned?.should == false
+    as_user do
+      it "returns false if the file is not owned by the user" do
+        system_file = '/etc/passwd'
+        st = File.stat(system_file)
+        st.owned?.should == false
+      end
     end
   end
 end
Index: spec/ruby/library/socket/socket/bind_spec.rb
===================================================================
--- spec/ruby/library/socket/socket/bind_spec.rb	(revision 61759)
+++ spec/ruby/library/socket/socket/bind_spec.rb	(revision 61760)
@@ -34,9 +34,11 @@ describe "Socket#bind on SOCK_DGRAM sock https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/socket/socket/bind_spec.rb#L34
   end
 
   platform_is_not :windows, :cygwin do
-    it "raises Errno::EACCES when the current user does not have permission to bind" do
-      sockaddr1 = Socket.pack_sockaddr_in(1, "127.0.0.1")
-      lambda { @sock.bind(sockaddr1) }.should raise_error(Errno::EACCES)
+    as_user do
+      it "raises Errno::EACCES when the current user does not have permission to bind" do
+        sockaddr1 = Socket.pack_sockaddr_in(1, "127.0.0.1")
+        lambda { @sock.bind(sockaddr1) }.should raise_error(Errno::EACCES)
+      end
     end
   end
 end
@@ -73,9 +75,11 @@ describe "Socket#bind on SOCK_STREAM soc https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/socket/socket/bind_spec.rb#L75
   end
 
   platform_is_not :windows, :cygwin do
-    it "raises Errno::EACCES when the current user does not have permission to bind" do
-      sockaddr1 = Socket.pack_sockaddr_in(1, "127.0.0.1")
-      lambda { @sock.bind(sockaddr1) }.should raise_error(Errno::EACCES)
+    as_user do
+      it "raises Errno::EACCES when the current user does not have permission to bind" do
+        sockaddr1 = Socket.pack_sockaddr_in(1, "127.0.0.1")
+        lambda { @sock.bind(sockaddr1) }.should raise_error(Errno::EACCES)
+      end
     end
   end
 end
Index: spec/ruby/shared/file/writable.rb
===================================================================
--- spec/ruby/shared/file/writable.rb	(revision 61759)
+++ spec/ruby/shared/file/writable.rb	(revision 61760)
@@ -9,7 +9,9 @@ describe :file_writable, shared: true do https://github.com/ruby/ruby/blob/trunk/spec/ruby/shared/file/writable.rb#L9
 
   it "returns true if named file is writable by the effective user id of the process, otherwise false" do
     platform_is_not :windows do
-      @object.send(@method, "/etc/passwd").should == false
+      as_user do
+        @object.send(@method, "/etc/passwd").should == false
+      end
     end
     File.open(@file,'w') { @object.send(@method, @file).should == true }
   end

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

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