This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
Hongli Lai (Phusion) (author)
Sat May 10 03:29:52 -0700 2008
| d11f5360 » | Hongli Lai (Phusion) | 2008-02-28 | 1 | require 'net/http' | |
| 2 | require 'uri' | ||||
| 3 | require 'resolv' | ||||
| d2e2c6e5 » | Hongli Lai (Phusion) | 2008-03-11 | 4 | require 'socket' | |
| b7b9aef5 » | Hongli Lai (Phusion) | 2008-02-29 | 5 | require 'timeout' | |
| d11f5360 » | Hongli Lai (Phusion) | 2008-02-28 | 6 | require 'support/config' | |
| e543369d » | Hongli Lai (Phusion) | 2008-03-01 | 7 | require 'support/multipart' | |
| d11f5360 » | Hongli Lai (Phusion) | 2008-02-28 | 8 | require 'support/apache2_config_writer' | |
| 9d714c0d » | Hongli Lai (Phusion) | 2008-03-01 | 9 | require 'passenger/platform_info' | |
| d11f5360 » | Hongli Lai (Phusion) | 2008-02-28 | 10 | ||
| 11 | include PlatformInfo | ||||
| 12 | |||||
| dcf64f0d » | Hongli Lai (Phusion) | 2008-03-22 | 13 | # TODO: test the 'RailsUserSwitching' and 'RailsDefaultUser' option. | |
| b153603a » | Hongli Lai (Phusion) | 2008-04-13 | 14 | # TODO: test custom page caching directory | |
| dcf64f0d » | Hongli Lai (Phusion) | 2008-03-22 | 15 | ||
| ccb41dad » | Hongli Lai (Phusion) | 2008-02-29 | 16 | shared_examples_for "MyCook(tm) beta" do | |
| 17 | it "should be possible to fetch static assets" do | ||||
| 18 | get('/images/rails.png').should == public_file('images/rails.png') | ||||
| 19 | end | ||||
| 20 | |||||
| b7b9aef5 » | Hongli Lai (Phusion) | 2008-02-29 | 21 | it "should support page caching on non-index URIs" do | |
| 22 | get('/welcome/cached').should =~ %r{This is the cached version of /welcome/cached} | ||||
| 23 | end | ||||
| 24 | |||||
| 25 | it "should support page caching on index URIs" do | ||||
| 26 | get('/uploads').should =~ %r{This is the cached version of /uploads} | ||||
| ccb41dad » | Hongli Lai (Phusion) | 2008-02-29 | 27 | end | |
| 28 | |||||
| e543369d » | Hongli Lai (Phusion) | 2008-03-01 | 29 | it "should not use page caching if the HTTP request is not GET" do | |
| 30 | post('/welcome/cached').should =~ %r{This content should never be displayed} | ||||
| 31 | end | ||||
| 32 | |||||
| ccb41dad » | Hongli Lai (Phusion) | 2008-02-29 | 33 | it "should not be interfered by Rails's default .htaccess dispatcher rules" do | |
| 34 | # Already being tested by all the other tests. | ||||
| 35 | end | ||||
| 36 | |||||
| 37 | it "should be possible to GET a regular Rails page" do | ||||
| 38 | get('/').should =~ /Welcome to MyCook/ | ||||
| 39 | end | ||||
| 40 | |||||
| 41 | it "should be possible to pass GET parameters to a Rails page" do | ||||
| 42 | result = get('/welcome/parameters_test?hello=world&recipe[name]=Green+Bananas') | ||||
| 43 | result.should =~ %r{<hello>world</hello>} | ||||
| 44 | result.should =~ %r{<recipe>} | ||||
| 45 | result.should =~ %r{<name>Green Bananas</name>} | ||||
| 46 | end | ||||
| 47 | |||||
| 48 | it "should be possible to POST to a Rails page" do | ||||
| 49 | result = post('/recipes', { | ||||
| 50 | 'recipe[name]' => 'Banana Pancakes', | ||||
| 51 | 'recipe[instructions]' => 'Call 0900-BANANAPANCAKES' | ||||
| 52 | }) | ||||
| 53 | result.should =~ %r{HTTP method: post} | ||||
| 54 | result.should =~ %r{Name: Banana Pancakes} | ||||
| 55 | result.should =~ %r{Instructions: Call 0900-BANANAPANCAKES} | ||||
| 56 | end | ||||
| 57 | |||||
| e543369d » | Hongli Lai (Phusion) | 2008-03-01 | 58 | it "should be possible to upload a file" do | |
| 59 | rails_png = File.open("#{@app_root}/public/images/rails.png", 'rb') | ||||
| 60 | params = { | ||||
| 61 | 'upload[name1]' => 'Kotonoha', | ||||
| 62 | 'upload[name2]' => 'Sekai', | ||||
| 63 | 'upload[data]' => rails_png | ||||
| 64 | } | ||||
| 65 | begin | ||||
| 66 | response = post('/uploads', params) | ||||
| 67 | rails_png.rewind | ||||
| 68 | response.should == | ||||
| 69 | "name 1 = Kotonoha\n" << | ||||
| 70 | "name 2 = Sekai\n" << | ||||
| 71 | "data = " << rails_png.read | ||||
| 72 | ensure | ||||
| 73 | rails_png.close | ||||
| 74 | end | ||||
| 75 | end | ||||
| ccb41dad » | Hongli Lai (Phusion) | 2008-02-29 | 76 | ||
| 77 | it "should properly handle custom headers" do | ||||
| 78 | response = get_response('/welcome/headers_test') | ||||
| 79 | response["X-Foo"].should == "Bar" | ||||
| 80 | end | ||||
| 9b857632 » | Hongli Lai (Phusion) | 2008-02-29 | 81 | ||
| 82 | it "should support restarting via restart.txt" do | ||||
| 83 | begin | ||||
| 84 | controller = "#{@app_root}/app/controllers/test_controller.rb" | ||||
| 85 | restart_file = "#{@app_root}/tmp/restart.txt" | ||||
| 86 | |||||
| 87 | File.open(controller, 'w') do |f| | ||||
| 88 | f.write %q{ | ||||
| 89 | class TestController < ApplicationController | ||||
| 90 | layout nil | ||||
| 91 | def index | ||||
| 92 | render :text => "foo" | ||||
| 93 | end | ||||
| 94 | end | ||||
| 95 | } | ||||
| 96 | end | ||||
| 97 | File.open(restart_file, 'w') do end | ||||
| 98 | get('/test').should == "foo" | ||||
| 99 | |||||
| 100 | File.open(controller, 'w') do |f| | ||||
| 101 | f.write %q{ | ||||
| 102 | class TestController < ApplicationController | ||||
| 103 | layout nil | ||||
| 104 | def index | ||||
| 105 | render :text => "bar" | ||||
| 106 | end | ||||
| 107 | end | ||||
| 108 | } | ||||
| 109 | end | ||||
| ab0db05c » | Hongli Lai (Phusion) | 2008-03-19 | 110 | ||
| b98113a5 » | Hongli Lai (Phusion) | 2008-03-09 | 111 | File.open(restart_file, 'w') do end | |
| 9b857632 » | Hongli Lai (Phusion) | 2008-02-29 | 112 | get('/test').should == 'bar' | |
| 113 | ensure | ||||
| 114 | File.unlink(controller) rescue nil | ||||
| 115 | File.unlink(restart_file) rescue nil | ||||
| 116 | end | ||||
| 117 | end | ||||
| 7d789e4c » | Hongli Lai (Phusion) | 2008-03-01 | 118 | ||
| 3799330e » | Hongli Lai (Phusion) | 2008-03-03 | 119 | it "should not make the web server crash if the app crashes" do | |
| 120 | post('/welcome/terminate') | ||||
| 8afe6327 » | Hongli Lai (Phusion) | 2008-03-21 | 121 | sleep(0.25) # Give the app the time to terminate itself. | |
| 3799330e » | Hongli Lai (Phusion) | 2008-03-03 | 122 | get('/').should =~ /Welcome to MyCook/ | |
| 123 | end | ||||
| 124 | |||||
| 7d789e4c » | Hongli Lai (Phusion) | 2008-03-01 | 125 | if Process.uid == 0 | |
| 126 | it "should be running as unprivileged user" do | ||||
| 127 | post('/welcome/touch') | ||||
| 128 | begin | ||||
| 129 | stat = File.stat("#{@app_root}/public/touch.txt") | ||||
| 130 | stat.uid.should_not == 0 | ||||
| 131 | stat.gid.should_not == 0 | ||||
| 132 | ensure | ||||
| 133 | File.unlink("#{@app_root}/public/touch.txt") rescue nil | ||||
| 134 | end | ||||
| 135 | end | ||||
| 136 | end | ||||
| ccb41dad » | Hongli Lai (Phusion) | 2008-02-29 | 137 | end | |
| 138 | |||||
| d11f5360 » | Hongli Lai (Phusion) | 2008-02-28 | 139 | describe "mod_passenger running in Apache 2" do | |
| 140 | before :all do | ||||
| 141 | check_hosts_configuration | ||||
| 142 | Apache2ConfigWriter.new.write | ||||
| 143 | start_apache | ||||
| 144 | end | ||||
| 145 | |||||
| 146 | after :all do | ||||
| 147 | stop_apache | ||||
| 148 | end | ||||
| 149 | |||||
| b7b9aef5 » | Hongli Lai (Phusion) | 2008-02-29 | 150 | describe ": MyCook(tm) beta running on root URI" do | |
| 151 | before :each do | ||||
| 152 | @server = "http://mycook.passenger.test:64506" | ||||
| 153 | @app_root = "stub/mycook" | ||||
| 154 | end | ||||
| 155 | |||||
| 156 | it_should_behave_like "MyCook(tm) beta" | ||||
| d11f5360 » | Hongli Lai (Phusion) | 2008-02-28 | 157 | end | |
| 158 | |||||
| 9b857632 » | Hongli Lai (Phusion) | 2008-02-29 | 159 | describe ": MyCook(tm) beta running in a sub-URI" do | |
| 160 | before :each do | ||||
| 161 | @server = "http://zsfa.passenger.test:64506/mycook" | ||||
| 162 | @app_root = "stub/mycook" | ||||
| 0439348e » | Hongli Lai (Phusion) | 2008-02-29 | 163 | File.unlink("stub/zsfa/mycook") rescue nil | |
| 164 | File.symlink("../mycook/public", "stub/zsfa/mycook") | ||||
| 165 | end | ||||
| 166 | |||||
| 167 | after :each do | ||||
| 168 | File.unlink("stub/zsfa/mycook") rescue nil | ||||
| 5e6157fc » | Hongli Lai (Phusion) | 2008-02-29 | 169 | end | |
| 170 | |||||
| 171 | it_should_behave_like "MyCook(tm) beta" | ||||
| 172 | end | ||||
| 173 | |||||
| 174 | describe ": railsapp running in a sub-URI" do | ||||
| 175 | before :each do | ||||
| 176 | @server = "http://zsfa.passenger.test:64506/foo" | ||||
| 177 | @app_root = "stub/railsapp" | ||||
| 0439348e » | Hongli Lai (Phusion) | 2008-02-29 | 178 | File.unlink("stub/zsfa/foo") rescue nil | |
| 179 | File.symlink("../railsapp/public", "stub/zsfa/foo") | ||||
| 180 | end | ||||
| 181 | |||||
| 182 | after :each do | ||||
| 183 | File.unlink("stub/zsfa/foo") rescue nil | ||||
| 9b857632 » | Hongli Lai (Phusion) | 2008-02-29 | 184 | end | |
| 185 | |||||
| 5e6157fc » | Hongli Lai (Phusion) | 2008-02-29 | 186 | it "should respond to /foo/new" do | |
| 187 | get('/foo/new').should == 'hello world' | ||||
| 188 | end | ||||
| 189 | |||||
| 190 | it "should not interfere with the ZSFA website" do | ||||
| 191 | @server = "http://zsfa.passenger.test:64506" | ||||
| 192 | get('/').should =~ /Zed, you rock\!/ | ||||
| 193 | end | ||||
| 9b857632 » | Hongli Lai (Phusion) | 2008-02-29 | 194 | end | |
| ccb41dad » | Hongli Lai (Phusion) | 2008-02-29 | 195 | ||
| 758b5e25 » | Hongli Lai (Phusion) | 2008-03-01 | 196 | describe "configuration options" do | |
| b98113a5 » | Hongli Lai (Phusion) | 2008-03-09 | 197 | it "should ignore the Rails application if RailsAutoDetect is off" do | |
| 198 | @server = "http://norails.passenger.test:64506" | ||||
| 199 | get('/').should_not =~ /MyCook/ | ||||
| 200 | end | ||||
| 201 | |||||
| 202 | it "setting RailsAutoDetect for one virtual host should not interfere with others" do | ||||
| 203 | # Already covered by other tests. | ||||
| 204 | end | ||||
| 758b5e25 » | Hongli Lai (Phusion) | 2008-03-01 | 205 | end | |
| 206 | |||||
| 4ba0c56a » | Hongli Lai (Phusion) | 2008-03-08 | 207 | describe "error handling" do | |
| 208 | before :each do | ||||
| 209 | File.unlink("stub/zsfa/app-with-nonexistant-rails-version") rescue nil | ||||
| 210 | File.unlink("stub/zsfa/app-that-crashes-during-startup") rescue nil | ||||
| 211 | File.unlink("stub/zsfa/app-with-crashing-vendor-rails") rescue nil | ||||
| 212 | File.symlink("../broken-railsapp4/public", "stub/zsfa/app-with-nonexistant-rails-version") | ||||
| 213 | File.symlink("../broken-railsapp/public", "stub/zsfa/app-that-crashes-during-startup") | ||||
| 214 | File.symlink("../broken-railsapp5/public", "stub/zsfa/app-with-crashing-vendor-rails") | ||||
| 215 | @server = "http://zsfa.passenger.test:64506" | ||||
| 216 | @error_page_signature = /<meta name="generator" content="Phusion Passenger">/ | ||||
| 217 | end | ||||
| 218 | |||||
| 219 | after :each do | ||||
| 220 | File.unlink("stub/zsfa/app-with-nonexistant-rails-version") rescue nil | ||||
| 221 | File.unlink("stub/zsfa/app-that-crashes-during-startup") rescue nil | ||||
| 222 | File.unlink("stub/zsfa/app-with-crashing-vendor-rails") rescue nil | ||||
| 223 | end | ||||
| 224 | |||||
| 225 | it "should display an error page if the Rails application requires a nonexistant Rails version" do | ||||
| 226 | get("/app-with-nonexistant-rails-version/").should =~ @error_page_signature | ||||
| 227 | end | ||||
| 228 | |||||
| 229 | it "should display an error page if the Rails application crashes during startup" do | ||||
| 230 | get("/app-that-crashes-during-startup/").should =~ @error_page_signature | ||||
| 231 | end | ||||
| 232 | |||||
| 233 | it "should display an error page if the Rails application's vendor'ed Rails crashes" do | ||||
| 234 | get("/app-with-crashing-vendor-rails/").should =~ @error_page_signature | ||||
| 235 | end | ||||
| 236 | end | ||||
| 237 | |||||
| b7b9aef5 » | Hongli Lai (Phusion) | 2008-02-29 | 238 | ##### Helper methods ##### | |
| 239 | |||||
| 240 | def get(uri) | ||||
| 241 | return Net::HTTP.get(URI.parse("#{@server}#{uri}")) | ||||
| ccb41dad » | Hongli Lai (Phusion) | 2008-02-29 | 242 | end | |
| 243 | |||||
| b7b9aef5 » | Hongli Lai (Phusion) | 2008-02-29 | 244 | def get_response(uri) | |
| 245 | return Net::HTTP.get_response(URI.parse("#{@server}#{uri}")) | ||||
| d11f5360 » | Hongli Lai (Phusion) | 2008-02-28 | 246 | end | |
| 247 | |||||
| 7d789e4c » | Hongli Lai (Phusion) | 2008-03-01 | 248 | def post(uri, params = {}) | |
| e543369d » | Hongli Lai (Phusion) | 2008-03-01 | 249 | url = URI.parse("#{@server}#{uri}") | |
| 250 | if params.values.any? { |x| x.respond_to?(:read) } | ||||
| 251 | mp = Multipart::MultipartPost.new | ||||
| 252 | query, headers = mp.prepare_query(params) | ||||
| 253 | Net::HTTP.start(url.host, url.port) do |http| | ||||
| 254 | return http.post(url.path, query, headers).body | ||||
| 255 | end | ||||
| 256 | else | ||||
| 257 | return Net::HTTP.post_form(url, params).body | ||||
| 258 | end | ||||
| ccb41dad » | Hongli Lai (Phusion) | 2008-02-29 | 259 | end | |
| 93a878e8 » | Hongli Lai (Phusion) | 2008-02-29 | 260 | ||
| ccb41dad » | Hongli Lai (Phusion) | 2008-02-29 | 261 | def public_file(name) | |
| b7b9aef5 » | Hongli Lai (Phusion) | 2008-02-29 | 262 | return File.read("#{@app_root}/public/#{name}") | |
| d11f5360 » | Hongli Lai (Phusion) | 2008-02-28 | 263 | end | |
| 264 | |||||
| 265 | def check_hosts_configuration | ||||





