Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/devise/failure_app.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# frozen_string_literal: true

require "action_controller/metal"
require "action_controller/metal/default_headers"

module Devise
# Failure application that will be called every time :warden is thrown from
# any strategy or hook. It is responsible for redirecting the user to the sign
# in page based on current scope and mapping. If no scope is given, it
# redirects to the default_url.
class FailureApp < ActionController::Metal
include ActionController::DefaultHeaders
include ActionController::UrlFor
include ActionController::Redirecting

Expand Down
16 changes: 16 additions & 0 deletions test/failure_app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ def call_failure(env_params = {})
end

context 'When redirecting' do
test 'includes default response headers' do
swap ActionDispatch::Response, default_headers: { 'X-Custom-Header' => 'custom' } do
call_failure

assert_equal 'custom', @response.second['X-Custom-Header']
end
end

test 'returns to the default redirect location' do
call_failure
assert_equal 302, @response.first
Expand Down Expand Up @@ -260,6 +268,14 @@ def call_failure(env_params = {})
end

context 'For HTTP request' do
test 'explicit response headers override default response headers' do
swap ActionDispatch::Response, default_headers: { 'WWW-Authenticate' => 'default' } do
call_failure('formats' => Mime[:json])

assert_equal 'Basic realm="Application"', @response.second['WWW-Authenticate']
end
end

test 'return 401 status' do
call_failure('formats' => Mime[:json])
assert_equal 401, @response.first
Expand Down