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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61760 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2018-01-10 13:30:25 +00:00
parent 5d0103f973
commit 205f0dcf3a
10 changed files with 143 additions and 113 deletions

View File

@ -66,6 +66,7 @@ end
# The permissions flag are not supported on Windows as stated in documentation: # 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. # The permissions may be modified by the value of File.umask, and are ignored on NT.
platform_is_not :windows do platform_is_not :windows do
as_user do
describe "Dir.mkdir" do describe "Dir.mkdir" do
before :each do before :each do
@dir = tmp "noperms" @dir = tmp "noperms"
@ -82,4 +83,5 @@ platform_is_not :windows do
lambda { Dir.mkdir "#{@dir}/subdir" }.should raise_error(SystemCallError) lambda { Dir.mkdir "#{@dir}/subdir" }.should raise_error(SystemCallError)
end end
end end
end
end end

View File

@ -49,6 +49,7 @@ describe :dir_delete, shared: true do
# this won't work on Windows, since chmod(0000) does not remove all permissions # this won't work on Windows, since chmod(0000) does not remove all permissions
platform_is_not :windows do platform_is_not :windows do
as_user do
it "raises an Errno::EACCES if lacking adequate permissions to remove the directory" do it "raises an Errno::EACCES if lacking adequate permissions to remove the directory" do
parent = DirSpecs.mock_rmdir("noperm") parent = DirSpecs.mock_rmdir("noperm")
child = DirSpecs.mock_rmdir("noperm", "child") child = DirSpecs.mock_rmdir("noperm", "child")
@ -58,4 +59,5 @@ describe :dir_delete, shared: true do
end.should raise_error(Errno::EACCES) end.should raise_error(Errno::EACCES)
end end
end end
end
end end

View File

@ -71,6 +71,7 @@ describe "File#chmod" do
end end
platform_is_not :windows do platform_is_not :windows do
as_user do
it "with '0222' makes file writable but not readable or executable" do it "with '0222' makes file writable but not readable or executable" do
@file.chmod(0222) @file.chmod(0222)
File.readable?(@filename).should == false File.readable?(@filename).should == false
@ -104,6 +105,7 @@ describe "File#chmod" do
File.stat(@filename).mode.should == 33261 File.stat(@filename).mode.should == 33261
end end
end end
end
end end
describe "File.chmod" do describe "File.chmod" do
@ -204,6 +206,7 @@ describe "File.chmod" do
end end
platform_is_not :windows do platform_is_not :windows do
as_user do
it "with '0222' makes file writable but not readable or executable" do it "with '0222' makes file writable but not readable or executable" do
File.chmod(0222, @file) File.chmod(0222, @file)
File.readable?(@file).should == false File.readable?(@file).should == false
@ -217,6 +220,7 @@ describe "File.chmod" do
File.writable?(@file).should == false File.writable?(@file).should == false
File.executable?(@file).should == false File.executable?(@file).should == false
end end
end
it "with '0666' makes file readable and writable but not executable" do it "with '0666' makes file readable and writable but not executable" do
File.chmod(0666, @file) File.chmod(0666, @file)
@ -225,12 +229,14 @@ describe "File.chmod" do
File.executable?(@file).should == false File.executable?(@file).should == false
end end
as_user do
it "with '0111' makes file executable but not readable or writable" do it "with '0111' makes file executable but not readable or writable" do
File.chmod(0111, @file) File.chmod(0111, @file)
File.readable?(@file).should == false File.readable?(@file).should == false
File.writable?(@file).should == false File.writable?(@file).should == false
File.executable?(@file).should == true File.executable?(@file).should == true
end end
end
it "modifies the permission bits of the files specified" do it "modifies the permission bits of the files specified" do
File.stat(@file).mode.should == 33261 File.stat(@file).mode.should == 33261

View File

@ -147,6 +147,7 @@ describe "File.open" do
end end
platform_is_not :windows do platform_is_not :windows do
as_user do
it "creates a new write-only file when invoked with 'w' and '0222'" do it "creates a new write-only file when invoked with 'w' and '0222'" do
rm_r @file rm_r @file
File.open(@file, 'w', 0222) {} File.open(@file, 'w', 0222) {}
@ -154,6 +155,7 @@ describe "File.open" do
File.writable?(@file).should == true File.writable?(@file).should == true
end end
end end
end
it "opens the file when call with fd" do it "opens the file when call with fd" do
@fh = File.open(@file) @fh = File.open(@file)
@ -464,18 +466,22 @@ describe "File.open" do
end end
platform_is_not :windows do platform_is_not :windows do
as_user do
it "raises an Errno::EACCES when opening non-permitted file" do it "raises an Errno::EACCES when opening non-permitted file" do
@fh = File.open(@file, "w") @fh = File.open(@file, "w")
@fh.chmod(000) @fh.chmod(000)
lambda { fh1 = File.open(@file); fh1.close }.should raise_error(Errno::EACCES) lambda { fh1 = File.open(@file); fh1.close }.should raise_error(Errno::EACCES)
end end
end end
end
as_user do
it "raises an Errno::EACCES when opening read-only file" do it "raises an Errno::EACCES when opening read-only file" do
@fh = File.open(@file, "w") @fh = File.open(@file, "w")
@fh.chmod(0444) @fh.chmod(0444)
lambda { File.open(@file, "w") }.should raise_error(Errno::EACCES) lambda { File.open(@file, "w") }.should raise_error(Errno::EACCES)
end end
end
it "opens a file for binary read" do it "opens a file for binary read" do
@fh = File.open(@file, "rb") @fh = File.open(@file, "rb")

View File

@ -24,10 +24,12 @@ describe "File.owned?" do
end end
platform_is_not :windows do platform_is_not :windows do
as_user do
it "returns false when the file is not owned by the user" do it "returns false when the file is not owned by the user" do
system_file = '/etc/passwd' system_file = '/etc/passwd'
File.owned?(system_file).should == false File.owned?(system_file).should == false
end end
end end
end
end end

View File

@ -22,10 +22,12 @@ describe "File::Stat#owned?" do
end end
platform_is_not :windows do platform_is_not :windows do
as_user do
it "returns false if the file is not owned by the user" do it "returns false if the file is not owned by the user" do
system_file = '/etc/passwd' system_file = '/etc/passwd'
st = File.stat(system_file) st = File.stat(system_file)
st.owned?.should == false st.owned?.should == false
end end
end end
end
end end

View File

@ -27,6 +27,7 @@ describe :kernel_require_basic, shared: true do
# Can't make a file unreadable on these platforms # Can't make a file unreadable on these platforms
platform_is_not :windows, :cygwin do platform_is_not :windows, :cygwin do
as_user do
describe "with an unreadable file" do describe "with an unreadable file" do
before :each do before :each do
@path = tmp("unreadable_file.rb") @path = tmp("unreadable_file.rb")
@ -45,6 +46,7 @@ describe :kernel_require_basic, shared: true do
end end
end end
end end
end
it "calls #to_str on non-String objects" do it "calls #to_str on non-String objects" do
path = File.expand_path "load_fixture.rb", CODE_LOADING_DIR path = File.expand_path "load_fixture.rb", CODE_LOADING_DIR

View File

@ -2,6 +2,7 @@ require File.expand_path('../../../spec_helper', __FILE__)
describe "Process.initgroups" do describe "Process.initgroups" do
platform_is_not :windows do platform_is_not :windows do
as_user do
it "initializes the supplemental group access list" do it "initializes the supplemental group access list" do
name = `id -un`.strip name = `id -un`.strip
groups = Process.groups groups = Process.groups
@ -17,4 +18,5 @@ describe "Process.initgroups" do
end end
end end
end end
end
end end

View File

@ -34,11 +34,13 @@ describe "Socket#bind on SOCK_DGRAM socket" do
end end
platform_is_not :windows, :cygwin do platform_is_not :windows, :cygwin do
as_user do
it "raises Errno::EACCES when the current user does not have permission to bind" 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") sockaddr1 = Socket.pack_sockaddr_in(1, "127.0.0.1")
lambda { @sock.bind(sockaddr1) }.should raise_error(Errno::EACCES) lambda { @sock.bind(sockaddr1) }.should raise_error(Errno::EACCES)
end end
end end
end
end end
describe "Socket#bind on SOCK_STREAM socket" do describe "Socket#bind on SOCK_STREAM socket" do
@ -73,9 +75,11 @@ describe "Socket#bind on SOCK_STREAM socket" do
end end
platform_is_not :windows, :cygwin do platform_is_not :windows, :cygwin do
as_user do
it "raises Errno::EACCES when the current user does not have permission to bind" 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") sockaddr1 = Socket.pack_sockaddr_in(1, "127.0.0.1")
lambda { @sock.bind(sockaddr1) }.should raise_error(Errno::EACCES) lambda { @sock.bind(sockaddr1) }.should raise_error(Errno::EACCES)
end end
end end
end
end end

View File

@ -9,8 +9,10 @@ describe :file_writable, shared: true do
it "returns true if named file is writable by the effective user id of the process, otherwise false" do it "returns true if named file is writable by the effective user id of the process, otherwise false" do
platform_is_not :windows do platform_is_not :windows do
as_user do
@object.send(@method, "/etc/passwd").should == false @object.send(@method, "/etc/passwd").should == false
end end
end
File.open(@file,'w') { @object.send(@method, @file).should == true } File.open(@file,'w') { @object.send(@method, @file).should == true }
end end