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:
parent
ac5deefad9
commit
a91d64a560
2 changed files with 36 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue