/
application_spawner_spec.rb
42 lines (34 loc) · 1.14 KB
/
application_spawner_spec.rb
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
require 'support/config'
require 'support/test_helper'
require 'phusion_passenger/rack/application_spawner'
describe PhusionPassenger::Rack::ApplicationSpawner do
include TestHelper
before :each do
@stub = setup_stub('rack')
end
after :each do
@stub.destroy
end
it "can spawn our stub application" do
spawn(@stub.app_root).close
end
it "propagates exceptions in application startup" do
File.prepend("#{@stub.app_root}/config.ru", "raise StandardError, 'foo'\n")
spawn = lambda { spawn(@stub.app_root) }
spawn.should raise_error(StandardError)
end
it "lowers privilege to the owner of config.ru" do
system("chown", "-R", CONFIG['normal_user_1'], @stub.app_root)
File.prepend("#{@stub.app_root}/config.ru", %q{
File.new('touch.txt', 'w').close
})
spawn(@stub.app_root).close
config_ru_owner = File.stat("#{@stub.app_root}/config.ru").uid
touch_txt_owner = File.stat("#{@stub.app_root}/touch.txt").uid
config_ru_owner.should == touch_txt_owner
end if Process.euid == 0
def spawn(app_root)
PhusionPassenger::Rack::ApplicationSpawner.spawn_application(app_root,
"lowest_user" => CONFIG['lowest_user'])
end
end