Permalink
Browse files

When there's a password and no 'profile' parameter, just call the app…

…. [issue #13]
  • Loading branch information...
1 parent 8cdb958 commit b7467c8d9756586635e4a34a4b5704aa119d65ad @jmoses jmoses committed Dec 5, 2011
@@ -17,7 +17,9 @@ def act
def self.for_env(env, profiler, middleware)
request = Rack::Request.new(env)
klass =
- if !profiler.password_valid?(request.GET['profile'])
+ if profiler.should_check_password? && ! request.GET.key?('profile')
+ CallAppDirectly
+ elsif !profiler.password_valid?(request.GET['profile'])
ReturnPasswordError
else
case request.path_info
@@ -58,7 +58,11 @@ def self.clear_data
def password_valid?(password)
@password.nil? || password == @password
end
-
+
+ def should_check_password?
+ ! @password.nil?
+ end
+
def start(mode = nil)
ensure_mode_is_changeable(mode) if mode
PerfTools::CpuProfiler.stop
@@ -325,6 +325,18 @@ def setup
end
context "when a profile password is required" do
+ should "call the app directly when 'profile' is not a request parameter" do
+ env = Rack::MockRequest.env_for('/', :params => {})
+ app = lambda do |env|
+ request = Rack::Request.new(env)
+ assert_equal( {}, request.GET)
+ [200, {}, ["HI"]]
+ end
+ status, headers, body = Rack::PerftoolsProfiler.new(app, :default_printer => 'pdf', :password => "secret_password").call(env)
+ assert_equal 200, status
+ assert_equal ["HI"], body
+ end
+
should "error if password does not match" do
app = @app.clone
env = Rack::MockRequest.env_for('/', :params => {'profile' => 'true'})

0 comments on commit b7467c8

Please sign in to comment.