@@ -195,7 +195,13 class ApplicationController < ActionController::Base | |||
|
195 | 195 | url = url_for(:controller => params[:controller], :action => params[:action], :id => params[:id], :project_id => params[:project_id]) |
|
196 | 196 | end |
|
197 | 197 | respond_to do |format| |
|
198 | format.html { redirect_to :controller => "account", :action => "login", :back_url => url } | |
|
198 | format.html { | |
|
199 | if request.xhr? | |
|
200 | head :unauthorized | |
|
201 | else | |
|
202 | redirect_to :controller => "account", :action => "login", :back_url => url | |
|
203 | end | |
|
204 | } | |
|
199 | 205 | format.atom { redirect_to :controller => "account", :action => "login", :back_url => url } |
|
200 | 206 | format.xml { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' } |
|
201 | 207 | format.js { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' } |
@@ -136,4 +136,20 class WelcomeControllerTest < ActionController::TestCase | |||
|
136 | 136 | assert_equal [0, 100], @controller.api_offset_and_limit({:page => 1, :limit => 100}) |
|
137 | 137 | assert_equal [200, 100], @controller.api_offset_and_limit({:page => 3, :limit => 100}) |
|
138 | 138 | end |
|
139 | ||
|
140 | def test_unhautorized_exception_with_anonymous_should_redirect_to_login | |
|
141 | WelcomeController.any_instance.stubs(:index).raises(::Unauthorized) | |
|
142 | ||
|
143 | get :index | |
|
144 | assert_response 302 | |
|
145 | assert_redirected_to('/login?back_url='+CGI.escape('http://test.host/')) | |
|
146 | end | |
|
147 | ||
|
148 | def test_unhautorized_exception_with_anonymous_and_xmlhttprequest_should_respond_with_401_to_anonymous | |
|
149 | WelcomeController.any_instance.stubs(:index).raises(::Unauthorized) | |
|
150 | ||
|
151 | @request.env["HTTP_X_REQUESTED_WITH"] = "XMLHttpRequest" | |
|
152 | get :index | |
|
153 | assert_response 401 | |
|
154 | end | |
|
139 | 155 | end |
General Comments 0
You need to be logged in to leave comments.
Login now