summaryrefslogtreecommitdiff
path: root/spec/ruby/core/process/euid_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/process/euid_spec.rb')
-rw-r--r--spec/ruby/core/process/euid_spec.rb45
1 files changed, 21 insertions, 24 deletions
diff --git a/spec/ruby/core/process/euid_spec.rb b/spec/ruby/core/process/euid_spec.rb
index 1855ef66f5..da76f06e59 100644
--- a/spec/ruby/core/process/euid_spec.rb
+++ b/spec/ruby/core/process/euid_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Process.euid" do
it "returns the effective user ID for this process" do
- Process.euid.should be_kind_of(Fixnum)
+ Process.euid.should.is_a?(Integer)
end
it "also goes by Process::UID.eid" do
@@ -18,40 +18,37 @@ describe "Process.euid=" do
platform_is_not :windows do
it "raises TypeError if not passed an Integer" do
- lambda { Process.euid = Object.new }.should raise_error(TypeError)
+ -> { Process.euid = Object.new }.should.raise(TypeError)
+ end
+
+ it "sets the effective user id to its own uid if given the username corresponding to its own uid" do
+ raise unless Process.uid == Process.euid
+
+ require "etc"
+ user = Etc.getpwuid(Process.uid).name
+
+ Process.euid = user
+ Process.euid.should == Process.uid
end
as_user do
it "raises Errno::ERPERM if run by a non superuser trying to set the superuser id" do
- lambda { (Process.euid = 0)}.should raise_error(Errno::EPERM)
+ -> { Process.euid = 0 }.should.raise(Errno::EPERM)
end
it "raises Errno::ERPERM if run by a non superuser trying to set the superuser id from username" do
- lambda { Process.euid = "root" }.should raise_error(Errno::EPERM)
+ -> { Process.euid = "root" }.should.raise(Errno::EPERM)
end
end
as_superuser do
describe "if run by a superuser" do
- with_feature :fork do
- it "sets the effective user id for the current process if run by a superuser" do
- read, write = IO.pipe
- pid = Process.fork do
- begin
- read.close
- Process.euid = 1
- write << Process.euid
- write.close
- rescue Exception => e
- write << e << e.backtrace
- end
- Process.exit!
- end
- write.close
- euid = read.gets
- euid.should == "1"
- Process.wait pid
- end
+ it "sets the effective user id for the current process if run by a superuser" do
+ code = <<-RUBY
+ Process.euid = 1
+ puts Process.euid
+ RUBY
+ ruby_exe(code).should == "1\n"
end
end
end