forked from External/greenlight
		
	Add check to make sure ldap username isn't blank (#1252)
Co-authored-by: Jesus Federico <jesus@123it.ca>
This commit is contained in:
		@@ -139,7 +139,9 @@ class SessionsController < ApplicationController
 | 
				
			|||||||
    ldap_config[:base] = ENV['LDAP_BASE']
 | 
					    ldap_config[:base] = ENV['LDAP_BASE']
 | 
				
			||||||
    ldap_config[:uid] = ENV['LDAP_UID']
 | 
					    ldap_config[:uid] = ENV['LDAP_UID']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return redirect_to(ldap_signin_path, alert: I18n.t("invalid_credentials")) unless session_params[:password].present?
 | 
					    if params[:session][:username].blank? || session_params[:password].blank?
 | 
				
			||||||
 | 
					      return redirect_to(ldap_signin_path, alert: I18n.t("invalid_credentials"))
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    result = send_ldap_request(params[:session], ldap_config)
 | 
					    result = send_ldap_request(params[:session], ldap_config)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -522,7 +522,7 @@ describe SessionsController, type: :controller do
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
      post :ldap, params: {
 | 
					      post :ldap, params: {
 | 
				
			||||||
        session: {
 | 
					        session: {
 | 
				
			||||||
          user: "test",
 | 
					          username: "test",
 | 
				
			||||||
          password: 'password',
 | 
					          password: 'password',
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@@ -544,7 +544,7 @@ describe SessionsController, type: :controller do
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
      post :ldap, params: {
 | 
					      post :ldap, params: {
 | 
				
			||||||
        session: {
 | 
					        session: {
 | 
				
			||||||
          user: "test",
 | 
					          username: "test",
 | 
				
			||||||
          password: 'password',
 | 
					          password: 'password',
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@@ -567,7 +567,7 @@ describe SessionsController, type: :controller do
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
      post :ldap, params: {
 | 
					      post :ldap, params: {
 | 
				
			||||||
        session: {
 | 
					        session: {
 | 
				
			||||||
          user: "test",
 | 
					          username: "test",
 | 
				
			||||||
          password: 'password',
 | 
					          password: 'password',
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@@ -583,7 +583,7 @@ describe SessionsController, type: :controller do
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
      post :ldap, params: {
 | 
					      post :ldap, params: {
 | 
				
			||||||
        session: {
 | 
					        session: {
 | 
				
			||||||
          user: "test",
 | 
					          username: "test",
 | 
				
			||||||
          password: 'passwor',
 | 
					          password: 'passwor',
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@@ -597,7 +597,7 @@ describe SessionsController, type: :controller do
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
      post :ldap, params: {
 | 
					      post :ldap, params: {
 | 
				
			||||||
        session: {
 | 
					        session: {
 | 
				
			||||||
          user: "test",
 | 
					          username: "test",
 | 
				
			||||||
          password: '',
 | 
					          password: '',
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@@ -605,5 +605,19 @@ describe SessionsController, type: :controller do
 | 
				
			|||||||
      expect(response).to redirect_to(ldap_signin_path)
 | 
					      expect(response).to redirect_to(ldap_signin_path)
 | 
				
			||||||
      expect(flash[:alert]).to eq(I18n.t("invalid_credentials"))
 | 
					      expect(flash[:alert]).to eq(I18n.t("invalid_credentials"))
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it "redirects to signin if no username provided" do
 | 
				
			||||||
 | 
					      allow_any_instance_of(Net::LDAP).to receive(:bind_as).and_return(false)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      post :ldap, params: {
 | 
				
			||||||
 | 
					        session: {
 | 
				
			||||||
 | 
					          username: "",
 | 
				
			||||||
 | 
					          password: 'test',
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      expect(response).to redirect_to(ldap_signin_path)
 | 
				
			||||||
 | 
					      expect(flash[:alert]).to eq(I18n.t("invalid_credentials"))
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user