API: tests that check status codes for project branches and hooks
Status code 422 (Unprocessable Entity) returned if invalid url is given when creating or updating a project hook.
This commit is contained in:
parent
6df02adc7a
commit
c305eb31aa
2 changed files with 54 additions and 3 deletions
|
@ -156,9 +156,9 @@ module Gitlab
|
||||||
# DELETE /projects/:id/members/:user_id
|
# DELETE /projects/:id/members/:user_id
|
||||||
delete ":id/members/:user_id" do
|
delete ":id/members/:user_id" do
|
||||||
authorize! :admin_project, user_project
|
authorize! :admin_project, user_project
|
||||||
users_project = user_project.users_projects.find_by_user_id params[:user_id]
|
team_member = user_project.users_projects.find_by_user_id(params[:user_id])
|
||||||
unless users_project.nil?
|
unless team_member.nil?
|
||||||
users_project.destroy
|
team_member.destroy
|
||||||
else
|
else
|
||||||
{:message => "Access revoked", :id => params[:user_id].to_i}
|
{:message => "Access revoked", :id => params[:user_id].to_i}
|
||||||
end
|
end
|
||||||
|
@ -205,6 +205,9 @@ module Gitlab
|
||||||
if @hook.save
|
if @hook.save
|
||||||
present @hook, with: Entities::Hook
|
present @hook, with: Entities::Hook
|
||||||
else
|
else
|
||||||
|
if @hook.errors[:url].present?
|
||||||
|
error!("Invalid url given", 422)
|
||||||
|
end
|
||||||
not_found!
|
not_found!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -227,6 +230,9 @@ module Gitlab
|
||||||
if @hook.update_attributes attrs
|
if @hook.update_attributes attrs
|
||||||
present @hook, with: Entities::Hook
|
present @hook, with: Entities::Hook
|
||||||
else
|
else
|
||||||
|
if @hook.errors[:url].present?
|
||||||
|
error!("Invalid url given", 422)
|
||||||
|
end
|
||||||
not_found!
|
not_found!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -281,6 +287,7 @@ module Gitlab
|
||||||
# PUT /projects/:id/repository/branches/:branch/protect
|
# PUT /projects/:id/repository/branches/:branch/protect
|
||||||
put ":id/repository/branches/:branch/protect" do
|
put ":id/repository/branches/:branch/protect" do
|
||||||
@branch = user_project.repo.heads.find { |item| item.name == params[:branch] }
|
@branch = user_project.repo.heads.find { |item| item.name == params[:branch] }
|
||||||
|
not_found! unless @branch
|
||||||
protected = user_project.protected_branches.find_by_name(@branch.name)
|
protected = user_project.protected_branches.find_by_name(@branch.name)
|
||||||
|
|
||||||
unless protected
|
unless protected
|
||||||
|
@ -299,6 +306,7 @@ module Gitlab
|
||||||
# PUT /projects/:id/repository/branches/:branch/unprotect
|
# PUT /projects/:id/repository/branches/:branch/unprotect
|
||||||
put ":id/repository/branches/:branch/unprotect" do
|
put ":id/repository/branches/:branch/unprotect" do
|
||||||
@branch = user_project.repo.heads.find { |item| item.name == params[:branch] }
|
@branch = user_project.repo.heads.find { |item| item.name == params[:branch] }
|
||||||
|
not_found! unless @branch
|
||||||
protected = user_project.protected_branches.find_by_name(@branch.name)
|
protected = user_project.protected_branches.find_by_name(@branch.name)
|
||||||
|
|
||||||
if protected
|
if protected
|
||||||
|
|
|
@ -144,6 +144,17 @@ describe Gitlab::API do
|
||||||
json_response['commit']['id'].should == '621491c677087aa243f165eab467bfdfbee00be1'
|
json_response['commit']['id'].should == '621491c677087aa243f165eab467bfdfbee00be1'
|
||||||
json_response['protected'].should == true
|
json_response['protected'].should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should return a 404 error if branch not found" do
|
||||||
|
put api("/projects/#{project.id}/repository/branches/unknown/protect", user)
|
||||||
|
response.status.should == 404
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return success when protect branch again" do
|
||||||
|
put api("/projects/#{project.id}/repository/branches/new_design/protect", user)
|
||||||
|
put api("/projects/#{project.id}/repository/branches/new_design/protect", user)
|
||||||
|
response.status.should == 200
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "PUT /projects/:id/repository/branches/:branch/unprotect" do
|
describe "PUT /projects/:id/repository/branches/:branch/unprotect" do
|
||||||
|
@ -155,6 +166,17 @@ describe Gitlab::API do
|
||||||
json_response['commit']['id'].should == '621491c677087aa243f165eab467bfdfbee00be1'
|
json_response['commit']['id'].should == '621491c677087aa243f165eab467bfdfbee00be1'
|
||||||
json_response['protected'].should == false
|
json_response['protected'].should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should return success when unprotect branch" do
|
||||||
|
put api("/projects/#{project.id}/repository/branches/unknown/unprotect", user)
|
||||||
|
response.status.should == 404
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return success when unprotect branch again" do
|
||||||
|
put api("/projects/#{project.id}/repository/branches/new_design/unprotect", user)
|
||||||
|
put api("/projects/#{project.id}/repository/branches/new_design/unprotect", user)
|
||||||
|
response.status.should == 200
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET /projects/:id/members" do
|
describe "GET /projects/:id/members" do
|
||||||
|
@ -182,6 +204,11 @@ describe Gitlab::API do
|
||||||
json_response['email'].should == user.email
|
json_response['email'].should == user.email
|
||||||
json_response['access_level'].should == UsersProject::MASTER
|
json_response['access_level'].should == UsersProject::MASTER
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should return a 404 error if user id not found" do
|
||||||
|
get api("/projects/#{project.id}/members/1234", user)
|
||||||
|
response.status.should == 404
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "POST /projects/:id/members" do
|
describe "POST /projects/:id/members" do
|
||||||
|
@ -262,6 +289,12 @@ describe Gitlab::API do
|
||||||
delete api("/projects/#{project.id}/members/#{user3.id}", user)
|
delete api("/projects/#{project.id}/members/#{user3.id}", user)
|
||||||
}.to_not change { UsersProject.count }.by(1)
|
}.to_not change { UsersProject.count }.by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should return 200 if team member already removed" do
|
||||||
|
delete api("/projects/#{project.id}/members/#{user3.id}", user)
|
||||||
|
delete api("/projects/#{project.id}/members/#{user3.id}", user)
|
||||||
|
response.status.should == 200
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "DELETE /projects/:id/members/:user_id" do
|
describe "DELETE /projects/:id/members/:user_id" do
|
||||||
|
@ -313,6 +346,11 @@ describe Gitlab::API do
|
||||||
post api("/projects/#{project.id}/hooks", user)
|
post api("/projects/#{project.id}/hooks", user)
|
||||||
response.status.should == 400
|
response.status.should == 400
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should return a 422 error if url not valid" do
|
||||||
|
post api("/projects/#{project.id}/hooks", user), "url" => "ftp://example.com"
|
||||||
|
response.status.should == 422
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "PUT /projects/:id/hooks/:hook_id" do
|
describe "PUT /projects/:id/hooks/:hook_id" do
|
||||||
|
@ -332,6 +370,11 @@ describe Gitlab::API do
|
||||||
put api("/projects/#{project.id}/hooks/#{hook.id}", user)
|
put api("/projects/#{project.id}/hooks/#{hook.id}", user)
|
||||||
response.status.should == 400
|
response.status.should == 400
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should return a 422 error if url is not valid" do
|
||||||
|
put api("/projects/#{project.id}/hooks/#{hook.id}", user), url: 'ftp://example.com'
|
||||||
|
response.status.should == 422
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "DELETE /projects/:id/hooks" do
|
describe "DELETE /projects/:id/hooks" do
|
||||||
|
|
Loading…
Reference in a new issue