diff --git a/History.md b/History.md index 3469361..8da92c7 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,11 @@ +## main + +* Breaking changes: + * Digest authentication support, deprecated in 2.0.0, has been + removed (Jeremy Evans #307) + * requiring rack/mock_session, deprecated in 2.0.0, has been removed + (Jeremy Evans #307) + ## 2.0.0 / 2022-06-24 * Breaking changes: diff --git a/lib/rack/mock_session.rb b/lib/rack/mock_session.rb deleted file mode 100644 index 5918f52..0000000 --- a/lib/rack/mock_session.rb +++ /dev/null @@ -1,2 +0,0 @@ -warn("requiring rack/mock_session is deprecated, require rack/test and use Rack::Test::Session", uplevel: 1) -require_relative 'test' diff --git a/lib/rack/test.rb b/lib/rack/test.rb index d7849c3..f0a5c27 100644 --- a/lib/rack/test.rb +++ b/lib/rack/test.rb @@ -98,8 +98,6 @@ def self.new(app, default_host = DEFAULT_HOST) # :nodoc: # If a block is given, #last_response is also yielded to the block. def initialize(app, default_host = DEFAULT_HOST) @env = {} - @digest_username = nil - @digest_password = nil @app = app @after_request = [] @default_host = default_host @@ -204,21 +202,6 @@ def basic_authorize(username, password) alias authorize basic_authorize - # Set the username and password for HTTP Digest authorization, to be - # included in subsequent requests in the HTTP_AUTHORIZATION header. - # This method is deprecated and will be removed in rack-test 2.1 - # - # Example: - # digest_authorize "bryan", "secret" - def digest_authorize(username, password) - warn 'digest authentication support will be removed in rack-test 2.1', uplevel: 1 - _digest_authorize(username, password) - end - def _digest_authorize(username, password) # :nodoc: - @digest_username = username - @digest_password = password - end - # Rack::Test will not follow any redirects automatically. This method # will follow the redirect returned (including setting the Referer header # on the new request) in the last response. If the last response was not @@ -363,43 +346,9 @@ def process_request(uri, env) @after_request.each(&:call) @last_response.finish - if retry_with_digest_auth?(env) - auth_env = env.merge('HTTP_AUTHORIZATION' => digest_auth_header, - 'rack-test.digest_auth_retry' => true) - auth_env.delete('rack.request') - process_request(uri, auth_env) - else - yield last_response if block_given? - - last_response - end - end + yield @last_response if block_given? - def digest_auth_header - require_relative 'test/mock_digest_request' - - challenge = last_response['WWW-Authenticate'].split(' ', 2).last - params = Rack::Auth::Digest::Params.parse(challenge) - - params.merge!('username' => @digest_username, - 'nc' => '00000001', - 'cnonce' => 'nonsensenonce', - 'uri' => last_request.fullpath, - 'method' => last_request.env['REQUEST_METHOD']) - - params['response'] = MockDigestRequest_.new(params).response(@digest_password) - - "Digest #{params}" - end - - def retry_with_digest_auth?(env) - last_response.status == 401 && - digest_auth_configured? && - !env['rack-test.digest_auth_retry'] - end - - def digest_auth_configured? - @digest_username + @last_response end end diff --git a/lib/rack/test/methods.rb b/lib/rack/test/methods.rb index 4392a33..65cbfc6 100644 --- a/lib/rack/test/methods.rb +++ b/lib/rack/test/methods.rb @@ -61,11 +61,6 @@ def with_session(name) @_rack_test_current_session = session end - def digest_authorize(username, password) # :nodoc: - warn 'digest authentication support will be removed in rack-test 2.1', uplevel: 1 - current_session._digest_authorize(username, password) - end - def_delegators(:current_session, :request, :get, diff --git a/lib/rack/test/mock_digest_request.rb b/lib/rack/test/mock_digest_request.rb deleted file mode 100644 index 8f2a043..0000000 --- a/lib/rack/test/mock_digest_request.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -# :nocov: -require 'rack/auth/digest' unless defined?(Rack::Auth::Digest) -# :nocov: - -module Rack - module Test - class MockDigestRequest_ # :nodoc: - def initialize(params) - @params = params - end - - def method_missing(sym) - if @params.key? k = sym.to_s - return @params[k] - end - - super - end - - def method - @params['method'] - end - - def response(password) - Rack::Auth::Digest::MD5.new(nil).send :digest, self, password - end - end - MockDigestRequest = MockDigestRequest_ - # :nocov: - deprecate_constant :MockDigestRequest if respond_to?(:deprecate_constant, true) - # :nocov: - end -end diff --git a/spec/rack/test/digest_auth_spec.rb b/spec/rack/test/digest_auth_spec.rb deleted file mode 100644 index 66429b5..0000000 --- a/spec/rack/test/digest_auth_spec.rb +++ /dev/null @@ -1,54 +0,0 @@ -# frozen-string-literal: true - -require_relative '../../spec_helper' -require_relative '../../../lib/rack/test/mock_digest_request' - -describe 'Rack::Test::Session digest authentication' do - app = Rack::Auth::Digest::MD5.new(Rack::Test::FakeApp.new.freeze) do |username| - { 'alice' => 'correct-password' }[username] - end - app.realm = 'WallysWorld' - app.opaque = 'this-should-be-secret' - define_method(:app) { app } - - deprecated 'incorrectly authenticates GETs' do - digest_authorize 'foo', 'bar' - get '/' - last_response.status.must_equal 401 - last_response['WWW-Authenticate'].must_match(/\ADigest /) - last_response.body.must_be_empty - end - - deprecated 'correctly authenticates GETs' do - digest_authorize 'alice', 'correct-password' - get('/').must_be :ok? - end - - deprecated 'correctly authenticates GETs with params' do - digest_authorize 'alice', 'correct-password' - get('/', 'foo' => 'bar').must_be :ok? - end - - deprecated 'correctly authenticates POSTs' do - digest_authorize 'alice', 'correct-password' - post('/').must_be :ok? - end - - deprecated 'returns a re-challenge if authenticating incorrectly' do - digest_authorize 'alice', 'incorrect-password' - get '/' - last_response.status.must_equal 401 - last_response['WWW-Authenticate'].must_match(/\ADigest /) - last_response.body.must_be_empty - end -end - -describe 'Rack::Test::MockDigestRequest' do - deprecated '#method_missing will return values based on params if they are present' do - Rack::Test::MockDigestRequest.new('foo' => 'bar').foo.must_equal 'bar' - end - - deprecated '#method_missing will raise NoMethodError if param is not present' do - proc{Rack::Test::MockDigestRequest.new({}).foo}.must_raise NoMethodError - end -end diff --git a/spec/rack/test_spec.rb b/spec/rack/test_spec.rb index 244cfe5..60932f8 100644 --- a/spec/rack/test_spec.rb +++ b/spec/rack/test_spec.rb @@ -7,10 +7,6 @@ Rack::MockSession.must_be_same_as Rack::Test::Session end - deprecated 'allows requiring rack/mock_session' do - require 'rack/mock_session' - end - it 'supports being initialized with a Rack::MockSession app' do Rack::Test::Session.new(Rack::MockSession.new(app)).request('/').must_be :ok? end @@ -408,52 +404,6 @@ def closed? end end -describe 'Rack::Test::Session#digest_authorize' do - challenge_data = 'realm="test-realm", qop="auth", nonce="nonsensenonce", opaque="morenonsense"'.freeze - basic_headers = { 'content-type' => 'text/html', 'content-length' => '13' }.freeze - digest_challenge = "Digest #{challenge_data}".freeze - auth_challenge_headers = { 'WWW-Authenticate' => digest_challenge }.freeze - cookie_headers = { 'Set-Cookie' => 'digest_auth_session=OZEnmjeekUSW%3D%3D; path=/; HttpOnly' }.freeze - - digest_app = lambda do |_env| - [401, basic_headers.merge(auth_challenge_headers).merge(cookie_headers), ''] - end - - define_method(:app){digest_app} - - def request - digest_authorize('test-name', 'test-password') - super('/') - last_request - end - - deprecated 'is defined directly on the session' do - current_session.digest_authorize('test-name', 'test-password') - get('/') - last_request.env['rack-test.digest_auth_retry'].must_equal true - end - - deprecated 'retries digest requests' do - request.env['rack-test.digest_auth_retry'].must_equal true - end - - deprecated 'sends a digest auth header' do - request.env['HTTP_AUTHORIZATION'].must_include 'Digest realm' - end - - deprecated 'includes the response based on the username,password and nonce' do - request.env['HTTP_AUTHORIZATION'].must_include 'response="d773034bdc162b31c50c62764016bd31"' - end - - deprecated 'includes the challenge headers' do - request.env['HTTP_AUTHORIZATION'].must_include challenge_data - end - - deprecated 'includes the username' do - request.env['HTTP_AUTHORIZATION'].must_include 'username="test-name"' - end -end - describe 'Rack::Test::Session#follow_redirect!' do it 'follows redirects' do get '/redirect'