Commit 25bde28d13cdffda8efa4ecae00985085e6aa565
1 parent
bb164ebf
Exists in
master
and in
4 other branches
Fixed tests. removed delegate to id
Showing
6 changed files
with
27 additions
and
13 deletions
Show diff stats
app/models/key.rb
... | ... | @@ -14,7 +14,7 @@ class Key < ActiveRecord::Base |
14 | 14 | before_save :set_identifier |
15 | 15 | after_save :update_repository |
16 | 16 | after_destroy :repository_delete_key |
17 | - delegate :id, :name, :email, :to => :user, :prefix => true | |
17 | + delegate :name, :email, :to => :user, :prefix => true | |
18 | 18 | |
19 | 19 | def set_identifier |
20 | 20 | if is_deploy_key | ... | ... |
app/models/project.rb
app/models/users_project.rb
... | ... | @@ -16,7 +16,7 @@ class UsersProject < ActiveRecord::Base |
16 | 16 | validates_presence_of :user_id |
17 | 17 | validates_presence_of :project_id |
18 | 18 | |
19 | - delegate :id, :name, :email, :to => :user, :prefix => true | |
19 | + delegate :name, :email, :to => :user, :prefix => true | |
20 | 20 | |
21 | 21 | def self.bulk_import(project, user_ids, project_access, repo_access) |
22 | 22 | UsersProject.transaction do | ... | ... |
app/workers/post_receive.rb
... | ... | @@ -5,6 +5,9 @@ class PostReceive |
5 | 5 | project = Project.find_by_path(reponame) |
6 | 6 | return false if project.nil? |
7 | 7 | |
8 | + # Ignore push from non-gitlab users | |
9 | + return false unless Key.find_by_identifier(author_key_id) | |
10 | + | |
8 | 11 | project.observe_push(oldrev, newrev, ref, author_key_id) |
9 | 12 | project.execute_web_hooks(oldrev, newrev, ref, author_key_id) |
10 | 13 | end | ... | ... |
spec/models/project_hooks_spec.rb
... | ... | @@ -2,17 +2,21 @@ require 'spec_helper' |
2 | 2 | |
3 | 3 | describe Project, "Hooks" do |
4 | 4 | let(:project) { Factory :project } |
5 | + before do | |
6 | + @key = Factory :key, :user => project.owner | |
7 | + @key_id = @key.identifier | |
8 | + end | |
5 | 9 | |
6 | 10 | describe "Post Receive Event" do |
7 | 11 | it "should create push event" do |
8 | 12 | oldrev, newrev, ref = '00000000000000000000000000000000', 'newrev', 'refs/heads/master' |
9 | - project.observe_push(oldrev, newrev, ref) | |
13 | + project.observe_push(oldrev, newrev, ref, @key_id) | |
10 | 14 | event = Event.last |
11 | 15 | |
12 | 16 | event.should_not be_nil |
13 | 17 | event.project.should == project |
14 | 18 | event.action.should == Event::Pushed |
15 | - event.data == project.web_hook_data(oldrev, newrev, ref) | |
19 | + event.data == project.web_hook_data(oldrev, newrev, ref, @key_id) | |
16 | 20 | end |
17 | 21 | end |
18 | 22 | |
... | ... | @@ -20,7 +24,7 @@ describe Project, "Hooks" do |
20 | 24 | context "with no web hooks" do |
21 | 25 | it "raises no errors" do |
22 | 26 | lambda { |
23 | - project.execute_web_hooks('oldrev', 'newrev', 'ref') | |
27 | + project.execute_web_hooks('oldrev', 'newrev', 'ref', @key_id) | |
24 | 28 | }.should_not raise_error |
25 | 29 | end |
26 | 30 | end |
... | ... | @@ -36,7 +40,7 @@ describe Project, "Hooks" do |
36 | 40 | @webhook.should_receive(:execute).once |
37 | 41 | @webhook_2.should_receive(:execute).once |
38 | 42 | |
39 | - project.execute_web_hooks('oldrev', 'newrev', 'refs/heads/master') | |
43 | + project.execute_web_hooks('oldrev', 'newrev', 'refs/heads/master', @key_id) | |
40 | 44 | end |
41 | 45 | end |
42 | 46 | |
... | ... | @@ -48,12 +52,12 @@ describe Project, "Hooks" do |
48 | 52 | |
49 | 53 | it "when pushing a branch for the first time" do |
50 | 54 | @webhook.should_not_receive(:execute) |
51 | - project.execute_web_hooks('00000000000000000000000000000000', 'newrev', 'refs/heads/master') | |
55 | + project.execute_web_hooks('00000000000000000000000000000000', 'newrev', 'refs/heads/master', @key_id) | |
52 | 56 | end |
53 | 57 | |
54 | 58 | it "when pushing tags" do |
55 | 59 | @webhook.should_not_receive(:execute) |
56 | - project.execute_web_hooks('oldrev', 'newrev', 'refs/tags/v1.0.0') | |
60 | + project.execute_web_hooks('oldrev', 'newrev', 'refs/tags/v1.0.0', @key_id) | |
57 | 61 | end |
58 | 62 | end |
59 | 63 | |
... | ... | @@ -69,7 +73,7 @@ describe Project, "Hooks" do |
69 | 73 | # Fill nil/empty attributes |
70 | 74 | project.description = "This is a description" |
71 | 75 | |
72 | - @data = project.web_hook_data(@oldrev, @newrev, @ref) | |
76 | + @data = project.web_hook_data(@oldrev, @newrev, @ref, @key_id) | |
73 | 77 | end |
74 | 78 | |
75 | 79 | subject { @data } |
... | ... | @@ -77,6 +81,8 @@ describe Project, "Hooks" do |
77 | 81 | it { should include(before: @oldrev) } |
78 | 82 | it { should include(after: @newrev) } |
79 | 83 | it { should include(ref: @ref) } |
84 | + it { should include(user_id: project.owner.id) } | |
85 | + it { should include(user_name: project.owner.name) } | |
80 | 86 | |
81 | 87 | context "with repository data" do |
82 | 88 | subject { @data[:repository] } | ... | ... |
spec/workers/post_receive_spec.rb
... | ... | @@ -10,17 +10,22 @@ describe PostReceive do |
10 | 10 | |
11 | 11 | context "web hooks" do |
12 | 12 | let(:project) { Factory :project } |
13 | + before do | |
14 | + @key = Factory :key, :user => project.owner | |
15 | + @key_id = @key.identifier | |
16 | + end | |
13 | 17 | |
14 | 18 | it "it retrieves the correct project" do |
15 | 19 | Project.should_receive(:find_by_path).with(project.path) |
16 | - PostReceive.perform(project.path, 'sha-old', 'sha-new', 'refs/heads/master') | |
20 | + Key.should_receive(:find_by_identifier).with(project.path) | |
21 | + PostReceive.perform(project.path, 'sha-old', 'sha-new', 'refs/heads/master', @key_id) | |
17 | 22 | end |
18 | 23 | |
19 | 24 | it "asks the project to execute web hooks" do |
20 | 25 | Project.stub(find_by_path: project) |
21 | - project.should_receive(:execute_web_hooks).with('sha-old', 'sha-new', 'refs/heads/master') | |
26 | + project.should_receive(:execute_web_hooks).with('sha-old', 'sha-new', 'refs/heads/master', @key_id) | |
22 | 27 | |
23 | - PostReceive.perform(project.path, 'sha-old', 'sha-new', 'refs/heads/master') | |
28 | + PostReceive.perform(project.path, 'sha-old', 'sha-new', 'refs/heads/master', @key_id) | |
24 | 29 | end |
25 | 30 | end |
26 | 31 | end | ... | ... |