Skip to content

Commit

Permalink
fix 407 support rack prior to 2.0 for basic auth
Browse files Browse the repository at this point in the history
  • Loading branch information
danmayer committed Oct 9, 2020
1 parent 78f1591 commit 8824171
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/coverband/reporters/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def init_web
def check_auth
return true unless Coverband.configuration.password

auth_header = request.get_header("HTTP_AUTHORIZATION")
# support rack 1.6.x and rack 2.0 (get_header)
auth_header = request.respond_to?(:get_header) ? request.get_header("HTTP_AUTHORIZATION") : request.env["HTTP_AUTHORIZATION"]
return unless auth_header

Coverband.configuration.password == Base64.decode64(auth_header.split[1]).split(":")[1]
Expand Down
2 changes: 1 addition & 1 deletion lib/coverband/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
# use format '4.2.1.rc.1' ~> 4.2.1.rc to prerelease versions like v4.2.1.rc.2 and v4.2.1.rc.3
###
module Coverband
VERSION = "5.0.2"
VERSION = "5.0.3"
end
34 changes: 34 additions & 0 deletions test/coverband/reporters/web_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,38 @@ def teardown
end
end
end

module Coverband
class AuthWebTest < Minitest::Test
include Rack::Test::Methods

def setup
super
@store = Coverband.configuration.store
Coverband.configure do |config|
config.password = "test_pass"
end
end

def app
Coverband::Reporters::Web.new
end

def teardown
super
end

test "renders index with basic auth" do
basic_authorize "anything", "test_pass"
get "/"
assert last_response.ok?
assert_match "Coverband Home", last_response.body
end

test "renders 401 auth error when not provided" do
get "/"
assert_equal 401, last_response.status
end
end
end
end

0 comments on commit 8824171

Please sign in to comment.