Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Merge branch 'wip.password-protect'
Browse files Browse the repository at this point in the history
  • Loading branch information
ConradIrwin committed Jul 22, 2011
2 parents 9a3cebf + 150bb1f commit 9c0cd11
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lib/rack/perftools_profiler/action.rb
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions test/single_request_profiling_test.rb
Expand Up @@ -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.