API: return 401 for invalid session
This commit is contained in:
parent
3dd940d4cb
commit
b08d33f6a9
2 changed files with 4 additions and 5 deletions
|
@ -8,14 +8,13 @@ module Gitlab
|
||||||
post "/session" do
|
post "/session" do
|
||||||
resource = User.find_for_database_authentication(email: params[:email])
|
resource = User.find_for_database_authentication(email: params[:email])
|
||||||
|
|
||||||
return forbidden! unless resource
|
return unauthorized! unless resource
|
||||||
|
|
||||||
if resource.valid_password?(params[:password])
|
if resource.valid_password?(params[:password])
|
||||||
present resource, with: Entities::UserLogin
|
present resource, with: Entities::UserLogin
|
||||||
else
|
else
|
||||||
forbidden!
|
unauthorized!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ describe Gitlab::API do
|
||||||
context "when invalid password" do
|
context "when invalid password" do
|
||||||
it "should return authentication error" do
|
it "should return authentication error" do
|
||||||
post api("/session"), email: user.email, password: '123'
|
post api("/session"), email: user.email, password: '123'
|
||||||
response.status.should == 403
|
response.status.should == 401
|
||||||
|
|
||||||
json_response['email'].should be_nil
|
json_response['email'].should be_nil
|
||||||
json_response['private_token'].should be_nil
|
json_response['private_token'].should be_nil
|
||||||
|
@ -29,7 +29,7 @@ describe Gitlab::API do
|
||||||
context "when empty password" do
|
context "when empty password" do
|
||||||
it "should return authentication error" do
|
it "should return authentication error" do
|
||||||
post api("/session"), email: user.email
|
post api("/session"), email: user.email
|
||||||
response.status.should == 403
|
response.status.should == 401
|
||||||
|
|
||||||
json_response['email'].should be_nil
|
json_response['email'].should be_nil
|
||||||
json_response['private_token'].should be_nil
|
json_response['private_token'].should be_nil
|
||||||
|
|
Loading…
Reference in a new issue