2012-09-20 14:44:44 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::API do
|
|
|
|
include ApiHelpers
|
|
|
|
|
2012-11-06 03:31:55 +00:00
|
|
|
let(:user) { create(:user) }
|
2012-09-20 14:44:44 +00:00
|
|
|
|
|
|
|
describe "POST /session" do
|
|
|
|
context "when valid password" do
|
|
|
|
it "should return private token" do
|
|
|
|
post api("/session"), email: user.email, password: '123456'
|
|
|
|
response.status.should == 201
|
|
|
|
|
|
|
|
json_response['email'].should == user.email
|
|
|
|
json_response['private_token'].should == user.private_token
|
2013-03-18 20:11:28 +00:00
|
|
|
json_response['is_admin'].should == user.is_admin?
|
|
|
|
json_response['can_create_team'].should == user.can_create_team?
|
|
|
|
json_response['can_create_project'].should == user.can_create_project?
|
|
|
|
json_response['can_create_group'].should == user.can_create_group?
|
2012-09-20 14:44:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when invalid password" do
|
|
|
|
it "should return authentication error" do
|
|
|
|
post api("/session"), email: user.email, password: '123'
|
2012-09-20 15:38:08 +00:00
|
|
|
response.status.should == 401
|
2012-09-20 14:44:44 +00:00
|
|
|
|
|
|
|
json_response['email'].should be_nil
|
|
|
|
json_response['private_token'].should be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when empty password" do
|
|
|
|
it "should return authentication error" do
|
|
|
|
post api("/session"), email: user.email
|
2012-09-20 15:38:08 +00:00
|
|
|
response.status.should == 401
|
2012-09-20 14:44:44 +00:00
|
|
|
|
|
|
|
json_response['email'].should be_nil
|
|
|
|
json_response['private_token'].should be_nil
|
|
|
|
end
|
|
|
|
end
|
2013-02-27 11:58:06 +00:00
|
|
|
|
|
|
|
context "when empty name" do
|
|
|
|
it "should return authentication error" do
|
|
|
|
post api("/session"), password: user.password
|
|
|
|
response.status.should == 401
|
|
|
|
|
|
|
|
json_response['email'].should be_nil
|
|
|
|
json_response['private_token'].should be_nil
|
|
|
|
end
|
|
|
|
end
|
2012-09-20 14:44:44 +00:00
|
|
|
end
|
|
|
|
end
|