]> git.openstreetmap.org Git - rails.git/commitdiff
SessionsController: strip username
authorSimon Legner <Simon.Legner@gmail.com>
Sun, 11 Feb 2024 20:20:27 +0000 (21:20 +0100)
committerSimon Legner <Simon.Legner@gmail.com>
Sun, 11 Feb 2024 20:53:03 +0000 (21:53 +0100)
app/controllers/sessions_controller.rb
test/controllers/sessions_controller_test.rb

index ba2858ce4392f8fda4745ad90f5f27af7c90f4dd..3c2084a5b82ee4cd39223d4a623abe4b4d82c715 100644 (file)
@@ -20,7 +20,7 @@ class SessionsController < ApplicationController
   def create
     session[:remember_me] ||= params[:remember_me]
     session[:referer] = safe_referer(params[:referer]) if params[:referer]
-    password_authentication(params[:username], params[:password])
+    password_authentication(params[:username].strip, params[:password])
   end
 
   def destroy
index a94a9a158c282bb791eb4670c308936693536650..4234bee70b7e599c4555ec5ea343c13b18ea77cb 100644 (file)
@@ -48,6 +48,14 @@ class SessionsControllerTest < ActionDispatch::IntegrationTest
     post login_path, :params => { :username => user.display_name, :password => "test" }
     assert_response :redirect
     assert_redirected_to root_path
+
+    post login_path, :params => { :username => " #{user.display_name}", :password => "test" }
+    assert_response :redirect
+    assert_redirected_to root_path
+
+    post login_path, :params => { :username => "#{user.display_name} ", :password => "test" }
+    assert_response :redirect
+    assert_redirected_to root_path
   end
 
   def test_logout_without_referer