summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-02-20 02:45:07 -0800
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-02-20 02:45:07 -0800
commit25e4c512d4b31f42d36d661acab7a6c6c91e77a8 (patch)
tree934aa362725943766f0fcbfc1fda1be4b197c974
parentc56d32c73e22b705ca6623c98b7a264440873726 (diff)
parente9d3b9659525c23a1d8c3b755c792040a5b41148 (diff)
downloadgitlab-ce-25e4c512d4b31f42d36d661acab7a6c6c91e77a8.tar.gz
Merge pull request #3011 from Asquera/fix_access_to_nonvisible_hook
API: fixes visibility of project hook
-rw-r--r--lib/api/projects.rb1
-rw-r--r--spec/requests/api/projects_spec.rb42
2 files changed, 33 insertions, 10 deletions
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index d416121a78a..921aa237f26 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -155,6 +155,7 @@ module Gitlab
# Example Request:
# GET /projects/:id/hooks/:hook_id
get ":id/hooks/:hook_id" do
+ authorize! :admin_project, user_project
@hook = user_project.hooks.find(params[:hook_id])
present @hook, with: Entities::Hook
end
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index 16fd1b9307c..4ac1e7cc31c 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -196,22 +196,44 @@ describe Gitlab::API do
end
describe "GET /projects/:id/hooks" do
- it "should return project hooks" do
- get api("/projects/#{project.id}/hooks", user)
+ context "authorized user" do
+ it "should return project hooks" do
+ get api("/projects/#{project.id}/hooks", user)
+ response.status.should == 200
- response.status.should == 200
+ json_response.should be_an Array
+ json_response.count.should == 1
+ json_response.first['url'].should == "http://example.com"
+ end
+ end
- json_response.should be_an Array
- json_response.count.should == 1
- json_response.first['url'].should == "http://example.com"
+ context "unauthorized user" do
+ it "should not access project hooks" do
+ get api("/projects/#{project.id}/hooks", user3)
+ response.status.should == 403
+ end
end
end
describe "GET /projects/:id/hooks/:hook_id" do
- it "should return a project hook" do
- get api("/projects/#{project.id}/hooks/#{hook.id}", user)
- response.status.should == 200
- json_response['url'].should == hook.url
+ context "authorized user" do
+ it "should return a project hook" do
+ get api("/projects/#{project.id}/hooks/#{hook.id}", user)
+ response.status.should == 200
+ json_response['url'].should == hook.url
+ end
+
+ it "should return a 404 error if hook id is not available" do
+ get api("/projects/#{project.id}/hooks/1234", user)
+ response.status.should == 404
+ end
+ end
+
+ context "unauthorized user" do
+ it "should not access an existing hook" do
+ get api("/projects/#{project.id}/hooks/#{hook.id}", user3)
+ response.status.should == 403
+ end
end
end