1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Add auth token support to App::Status

This commit is contained in:
Evan Phoenix 2011-12-06 16:22:02 -08:00
parent ac5deefad9
commit a91d64a560
2 changed files with 36 additions and 0 deletions

View file

@ -4,9 +4,21 @@ module Puma
def initialize(server, cli)
@server = server
@cli = cli
@auth_token = nil
end
attr_accessor :auth_token
def authenticate(env)
return true unless @auth_token
env['QUERY_STRING'].to_s.split(/&;/).include?("token=#{@auth_token}")
end
def call(env)
unless authenticate(env)
return [403, {}, ["Invalid auth token"]]
end
case env['PATH_INFO']
when "/stop"
@server.stop

View file

@ -24,6 +24,30 @@ class TestAppStatus < Test::Unit::TestCase
def setup
@server = FakeServer.new
@app = Puma::App::Status.new(@server, @server)
@app.auth_token = nil
end
def test_bad_token
@app.auth_token = "abcdef"
env = { 'PATH_INFO' => "/whatever" }
status, header, body = @app.call env
assert_equal 403, status
end
def test_good_token
@app.auth_token = "abcdef"
env = {
'PATH_INFO' => "/whatever",
'QUERY_STRING' => "token=abcdef"
}
status, header, body = @app.call env
assert_equal 404, status
end
def test_unsupported