Permalink
Browse files

Merge branch 'wip.password-protect'

  • Loading branch information...
2 parents 9a3cebf + 150bb1f commit 9c0cd11023a4331b6078996b77be3008dc249c83 @ConradIrwin ConradIrwin committed Jul 22, 2011
Showing with 35 additions and 10 deletions.
  1. +14 −10 lib/rack/perftools_profiler/action.rb
  2. +21 −0 test/single_request_profiling_test.rb
@@ -17,18 +17,22 @@ def act
def self.for_env(env, profiler, middleware)
request = Rack::Request.new(env)
klass =
- case request.path_info
- when %r{/__start__$}
- StartProfiling
- when %r{/__stop__$}
- StopProfiling
- when %r{/__data__$}
- ReturnData
+ if ENV["PROFILE_PASSWORD"] && request.GET['profile'] != ENV["PROFILE_PASSWORD"]
+ CallAppDirectly
else
- if ProfileOnce.has_special_param?(request)
- ProfileOnce
+ case request.path_info
+ when %r{/__start__$}
+ StartProfiling
+ when %r{/__stop__$}
+ StopProfiling
+ when %r{/__data__$}
+ ReturnData
else
- CallAppDirectly
+ if ProfileOnce.has_special_param?(request)
+ ProfileOnce
+ else
+ CallAppDirectly
+ end
end
end
klass.new(env, profiler, middleware)
@@ -322,4 +322,25 @@ def setup
end
+ context "when a profile password is required" do
+ should "not profile unless the parameter matches" do
+ ENV["PROFILE_PASSWORD"] = 'secret_password'
+ app = @app.clone
+ env = Rack::MockRequest.env_for('/', :params => {'profile' => 'true'})
+ status, headers, body = Rack::PerftoolsProfiler.new(app, :default_printer => 'pdf').call(env)
+ assert_equal 200, status
+ assert_equal 'text/plain', headers['Content-Type']
+ assert_equal 'Oh hai der', RackResponseBody.new(body).to_s
+ ENV.delete 'PROFILE_PASSWORD'
+ end
+
+ should "profile if the parameter matches" do
+ ENV["PROFILE_PASSWORD"] = 'secret_password'
+ env = Rack::MockRequest.env_for('/', :params => 'profile=secret_password&printer=gif')
+ _, headers, _ = Rack::PerftoolsProfiler.new(@app, :default_printer => 'pdf').call(env)
+ assert_equal 'image/gif', headers['Content-Type']
+ ENV.delete 'PROFILE_PASSWORD'
+ end
+ end
+
end

0 comments on commit 9c0cd11

Please sign in to comment.