FIX: enforce second factor with subfolders (#30992)

fix an improper redirect when enforcing second factor under a subfolder
install
This commit is contained in:
Jeff Wong 2025-01-24 11:50:52 -08:00 committed by GitHub
parent 59a6775848
commit 4c1c4ba8d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -893,7 +893,7 @@ class ApplicationController < ActionController::Base
redirect_path = path("/u/#{current_user.encoded_username}/preferences/second-factor")
if !request.fullpath.start_with?(redirect_path)
redirect_to path(redirect_path)
redirect_to redirect_path
nil
end
end

View File

@ -142,6 +142,15 @@ RSpec.describe ApplicationController do
expect(response).to redirect_to("/u/#{admin.username}/preferences/second-factor")
end
it "should properly redirect admins when enforce_second_factor is 'all' in subfolder" do
set_subfolder "/forum"
SiteSetting.enforce_second_factor = "all"
sign_in(admin)
get "/"
expect(response).to redirect_to("/forum/u/#{admin.username}/preferences/second-factor")
end
it "should redirect users when enforce_second_factor is 'all'" do
SiteSetting.enforce_second_factor = "all"
sign_in(user)