We got nominated! Help us out and vote for GitHub as Best Bootstrapped Startup of 2008. (You can vote once a day.) [ hide ]

public
Description: Phusion Passenger (mod_rails)
Homepage: http://www.modrails.com/
Clone URL: git://github.com/FooBarWidget/passenger.git
Click here to lend your support to: passenger and make a donation at www.pledgie.com !
Add ability to run integration tests as root. Add test for checking 
privilege lowering.
Hongli Lai (Phusion) (author)
Sat Mar 01 05:20:21 -0800 2008
commit  7d789e4c70bea393becbcb5cc872be7adc420a55
tree    f000af8a400353146c2fb2c7163be9b41a2d431c
parent  9d714c0d0302870d9c57269bfdd68d38dcfcd764
...
19
20
21
 
22
23
24
...
19
20
21
22
23
24
25
0
@@ -19,6 +19,7 @@ test/stub/railsapp/app/controllers/bar_controller.rb
0
 test/stub/railsapp/log/*
0
 test/stub/railsapp2/log/*
0
 test/stub/apache2/*.log
0
+test/stub/apache2/*.pid
0
 test/stub/apache2/httpd.conf
0
 test/stub/mycook/log
0
 test/stub/zsfa/mycook
...
90
91
92
 
 
 
 
 
 
 
 
 
 
 
 
 
93
94
95
...
161
162
163
164
 
165
166
167
...
210
211
212
 
213
214
215
...
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
...
174
175
176
 
177
178
179
180
...
223
224
225
226
227
228
229
0
@@ -90,6 +90,19 @@ shared_examples_for "MyCook(tm) beta" do
0
       File.unlink(restart_file) rescue nil
0
     end
0
   end
0
+
0
+ if Process.uid == 0
0
+ it "should be running as unprivileged user" do
0
+ post('/welcome/touch')
0
+ begin
0
+ stat = File.stat("#{@app_root}/public/touch.txt")
0
+ stat.uid.should_not == 0
0
+ stat.gid.should_not == 0
0
+ ensure
0
+ File.unlink("#{@app_root}/public/touch.txt") rescue nil
0
+ end
0
+ end
0
+ end
0
 end
0
 
0
 describe "mod_passenger running in Apache 2" do
0
@@ -161,7 +174,7 @@ describe "mod_passenger running in Apache 2" do
0
     return Net::HTTP.get_response(URI.parse("#{@server}#{uri}"))
0
   end
0
   
0
- def post(uri, params)
0
+ def post(uri, params = {})
0
     return Net::HTTP.post_form(URI.parse("#{@server}#{uri}"), params).body
0
   end
0
   
0
@@ -210,6 +223,7 @@ describe "mod_passenger running in Apache 2" do
0
   end
0
   
0
   def stop_apache
0
+ File.chmod(0666, *Dir['stub/apache2/*.{log,lock,pid}']) rescue nil
0
     begin
0
       pid = File.read('stub/apache2/httpd.pid').strip.to_i
0
       Process.kill('SIGTERM', pid)
...
1
2
3
 
 
 
 
 
4
5
6
...
1
2
3
4
5
6
7
8
9
10
11
0
@@ -1,6 +1,11 @@
0
 ServerRoot "<%= @server_root %>"
0
 Listen 127.0.0.1:64506
0
 
0
+<% if running_as_root? %>
0
+ User <%= @normal_user %>
0
+ Group <%= @normal_group %>
0
+<% end %>
0
+
0
 <% if !has_builtin_module?('mod_log_config.c') %>
0
   LoadModule log_config_module "<%= @modules_dir %>/mod_log_config.so"
0
 <% end %>
...
10
11
12
 
 
 
 
 
 
13
...
10
11
12
13
14
15
16
17
18
19
0
@@ -10,4 +10,10 @@ class WelcomeController < ApplicationController
0
     headers["X-Foo"] = "Bar"
0
     render :nothing => true
0
   end
0
+
0
+ def touch
0
+ File.unlink('public/touch.txt') rescue nil
0
+ File.open('public/touch.txt', 'w') do end
0
+ render :nothing => true
0
+ end
0
 end
...
1
 
2
3
4
...
13
14
15
 
 
16
17
18
...
34
35
36
 
 
 
 
37
...
1
2
3
4
5
...
14
15
16
17
18
19
20
21
...
37
38
39
40
41
42
43
44
0
@@ -1,4 +1,5 @@
0
 require 'erb'
0
+require 'etc'
0
 require 'passenger/platform_info'
0
 
0
 class Apache2ConfigWriter
0
@@ -13,6 +14,8 @@ class Apache2ConfigWriter
0
       line.strip
0
     end
0
     @mod_passenger = File.expand_path(File.dirname(__FILE__) + "/../../ext/apache2/mod_passenger.so")
0
+ @normal_user = CONFIG['normal_user_1']
0
+ @normal_group = Etc.getgrgid(Etc.getpwnam(@normal_user).gid).name
0
   end
0
   
0
   def write
0
@@ -34,4 +37,8 @@ private
0
   def has_module?(name)
0
     return File.exist?("#{@modules_dir}/#{name}")
0
   end
0
+
0
+ def running_as_root?
0
+ return Process.uid == 0
0
+ end
0
 end

Comments

    No one has commented yet.