2013-02-20 05:53:15 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe SystemHooksService do
|
2017-03-27 17:14:01 -04:00
|
|
|
let(:user) { create(:user) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2017-03-27 17:14:01 -04:00
|
|
|
let(:project_member) { create(:project_member) }
|
|
|
|
let(:key) { create(:key, user: user) }
|
|
|
|
let(:deploy_key) { create(:key) }
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:group_member) { create(:group_member) }
|
2013-02-20 05:53:15 -05:00
|
|
|
|
2013-10-08 04:06:38 -04:00
|
|
|
context 'event data' do
|
2016-01-07 12:54:35 -05:00
|
|
|
it { expect(event_data(user, :create)).to include(:event_name, :name, :created_at, :updated_at, :email, :user_id, :username) }
|
|
|
|
it { expect(event_data(user, :destroy)).to include(:event_name, :name, :created_at, :updated_at, :email, :user_id, :username) }
|
2015-05-05 11:13:11 -04:00
|
|
|
it { expect(event_data(project, :create)).to include(:event_name, :name, :created_at, :updated_at, :path, :project_id, :owner_name, :owner_email, :project_visibility) }
|
2016-08-08 09:31:35 -04:00
|
|
|
it { expect(event_data(project, :update)).to include(:event_name, :name, :created_at, :updated_at, :path, :project_id, :owner_name, :owner_email, :project_visibility) }
|
2015-05-05 11:13:11 -04:00
|
|
|
it { expect(event_data(project, :destroy)).to include(:event_name, :name, :created_at, :updated_at, :path, :project_id, :owner_name, :owner_email, :project_visibility) }
|
2016-01-13 04:12:30 -05:00
|
|
|
it { expect(event_data(project_member, :create)).to include(:event_name, :created_at, :updated_at, :project_name, :project_path, :project_path_with_namespace, :project_id, :user_name, :user_username, :user_email, :user_id, :access_level, :project_visibility) }
|
|
|
|
it { expect(event_data(project_member, :destroy)).to include(:event_name, :created_at, :updated_at, :project_name, :project_path, :project_path_with_namespace, :project_id, :user_name, :user_username, :user_email, :user_id, :access_level, :project_visibility) }
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(event_data(key, :create)).to include(:username, :key, :id) }
|
|
|
|
it { expect(event_data(key, :destroy)).to include(:username, :key, :id) }
|
2017-03-16 09:28:34 -04:00
|
|
|
it { expect(event_data(deploy_key, :create)).to include(:key, :id) }
|
|
|
|
it { expect(event_data(deploy_key, :destroy)).to include(:key, :id) }
|
2014-08-21 06:53:32 -04:00
|
|
|
|
2015-05-05 11:13:11 -04:00
|
|
|
it do
|
|
|
|
project.old_path_with_namespace = 'renamed_from_path'
|
|
|
|
expect(event_data(project, :rename)).to include(
|
2016-01-13 04:12:30 -05:00
|
|
|
:event_name, :name, :created_at, :updated_at, :path, :project_id,
|
|
|
|
:owner_name, :owner_email, :project_visibility,
|
2015-05-05 11:13:11 -04:00
|
|
|
:old_path_with_namespace
|
2016-01-13 04:12:30 -05:00
|
|
|
)
|
2015-05-05 11:13:11 -04:00
|
|
|
end
|
2018-03-05 08:41:54 -05:00
|
|
|
|
2015-05-05 11:13:11 -04:00
|
|
|
it do
|
|
|
|
project.old_path_with_namespace = 'transfered_from_path'
|
|
|
|
expect(event_data(project, :transfer)).to include(
|
2016-01-13 04:12:30 -05:00
|
|
|
:event_name, :name, :created_at, :updated_at, :path, :project_id,
|
|
|
|
:owner_name, :owner_email, :project_visibility,
|
2015-05-05 11:13:11 -04:00
|
|
|
:old_path_with_namespace
|
2016-01-13 04:12:30 -05:00
|
|
|
)
|
2015-05-05 11:13:11 -04:00
|
|
|
end
|
|
|
|
|
2014-08-21 06:53:32 -04:00
|
|
|
it do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(event_data(group, :create)).to include(
|
2016-01-13 04:12:30 -05:00
|
|
|
:event_name, :name, :created_at, :updated_at, :path, :group_id,
|
2015-05-05 11:13:11 -04:00
|
|
|
:owner_name, :owner_email
|
2014-08-21 06:53:32 -04:00
|
|
|
)
|
|
|
|
end
|
2018-03-05 08:41:54 -05:00
|
|
|
|
2014-08-21 06:53:32 -04:00
|
|
|
it do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(event_data(group, :destroy)).to include(
|
2016-01-13 04:12:30 -05:00
|
|
|
:event_name, :name, :created_at, :updated_at, :path, :group_id,
|
2015-05-05 11:13:11 -04:00
|
|
|
:owner_name, :owner_email
|
2014-08-21 06:53:32 -04:00
|
|
|
)
|
|
|
|
end
|
2018-03-05 08:41:54 -05:00
|
|
|
|
2014-08-21 06:53:32 -04:00
|
|
|
it do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(event_data(group_member, :create)).to include(
|
2016-01-13 04:12:30 -05:00
|
|
|
:event_name, :created_at, :updated_at, :group_name, :group_path,
|
2016-01-07 12:54:54 -05:00
|
|
|
:group_id, :user_id, :user_username, :user_name, :user_email, :group_access
|
2014-08-21 06:53:32 -04:00
|
|
|
)
|
|
|
|
end
|
2018-03-05 08:41:54 -05:00
|
|
|
|
2014-08-21 06:53:32 -04:00
|
|
|
it do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(event_data(group_member, :destroy)).to include(
|
2016-01-13 04:12:30 -05:00
|
|
|
:event_name, :created_at, :updated_at, :group_name, :group_path,
|
2016-01-07 12:54:54 -05:00
|
|
|
:group_id, :user_id, :user_username, :user_name, :user_email, :group_access
|
2014-08-21 06:53:32 -04:00
|
|
|
)
|
|
|
|
end
|
2017-10-27 10:09:11 -04:00
|
|
|
|
|
|
|
it 'includes the correct project visibility level' do
|
|
|
|
data = event_data(project, :create)
|
|
|
|
|
|
|
|
expect(data[:project_visibility]).to eq('private')
|
|
|
|
end
|
2017-11-03 07:26:52 -04:00
|
|
|
|
2018-03-05 16:37:37 -05:00
|
|
|
it 'handles nil datetime columns' do
|
2018-07-02 06:43:06 -04:00
|
|
|
user.update(created_at: nil, updated_at: nil)
|
2018-03-05 16:37:37 -05:00
|
|
|
data = event_data(user, :destroy)
|
|
|
|
|
|
|
|
expect(data[:created_at]).to be(nil)
|
|
|
|
expect(data[:updated_at]).to be(nil)
|
|
|
|
end
|
|
|
|
|
2017-11-03 07:26:52 -04:00
|
|
|
context 'group_rename' do
|
|
|
|
it 'contains old and new path' do
|
|
|
|
allow(group).to receive(:path_was).and_return('old-path')
|
|
|
|
|
|
|
|
data = event_data(group, :rename)
|
|
|
|
|
|
|
|
expect(data).to include(:event_name, :name, :created_at, :updated_at, :full_path, :path, :group_id, :old_path, :old_full_path)
|
|
|
|
expect(data[:path]).to eq(group.path)
|
|
|
|
expect(data[:full_path]).to eq(group.path)
|
|
|
|
expect(data[:old_path]).to eq(group.path_was)
|
|
|
|
expect(data[:old_full_path]).to eq(group.path_was)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains old and new full_path for subgroup' do
|
|
|
|
subgroup = create(:group, parent: group)
|
|
|
|
allow(subgroup).to receive(:path_was).and_return('old-path')
|
|
|
|
|
|
|
|
data = event_data(subgroup, :rename)
|
|
|
|
|
|
|
|
expect(data[:full_path]).to eq(subgroup.full_path)
|
|
|
|
expect(data[:old_path]).to eq('old-path')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user_rename' do
|
|
|
|
it 'contains old and new username' do
|
|
|
|
allow(user).to receive(:username_was).and_return('old-username')
|
|
|
|
|
|
|
|
data = event_data(user, :rename)
|
|
|
|
|
|
|
|
expect(data).to include(:event_name, :name, :created_at, :updated_at, :email, :user_id, :username, :old_username)
|
|
|
|
expect(data[:username]).to eq(user.username)
|
|
|
|
expect(data[:old_username]).to eq(user.username_was)
|
|
|
|
end
|
|
|
|
end
|
2018-01-15 00:10:48 -05:00
|
|
|
|
|
|
|
context 'user_failed_login' do
|
|
|
|
it 'contains state of user' do
|
|
|
|
user.ldap_block!
|
|
|
|
|
|
|
|
data = event_data(user, :failed_login)
|
|
|
|
|
|
|
|
expect(data).to include(:event_name, :name, :created_at, :updated_at, :email, :user_id, :username, :state)
|
|
|
|
expect(data[:username]).to eq(user.username)
|
|
|
|
expect(data[:state]).to eq('ldap_blocked')
|
|
|
|
end
|
|
|
|
end
|
2013-02-20 05:53:15 -05:00
|
|
|
end
|
|
|
|
|
2013-10-08 04:06:38 -04:00
|
|
|
context 'event names' do
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(event_name(user, :create)).to eq "user_create" }
|
|
|
|
it { expect(event_name(user, :destroy)).to eq "user_destroy" }
|
2017-11-03 07:26:52 -04:00
|
|
|
it { expect(event_name(user, :rename)).to eq 'user_rename' }
|
2018-01-15 00:10:48 -05:00
|
|
|
it { expect(event_name(user, :failed_login)).to eq 'user_failed_login' }
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(event_name(project, :create)).to eq "project_create" }
|
|
|
|
it { expect(event_name(project, :destroy)).to eq "project_destroy" }
|
2015-05-05 11:13:11 -04:00
|
|
|
it { expect(event_name(project, :rename)).to eq "project_rename" }
|
|
|
|
it { expect(event_name(project, :transfer)).to eq "project_transfer" }
|
2016-08-08 09:31:35 -04:00
|
|
|
it { expect(event_name(project, :update)).to eq "project_update" }
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(event_name(project_member, :create)).to eq "user_add_to_team" }
|
|
|
|
it { expect(event_name(project_member, :destroy)).to eq "user_remove_from_team" }
|
|
|
|
it { expect(event_name(key, :create)).to eq 'key_create' }
|
|
|
|
it { expect(event_name(key, :destroy)).to eq 'key_destroy' }
|
|
|
|
it { expect(event_name(group, :create)).to eq 'group_create' }
|
|
|
|
it { expect(event_name(group, :destroy)).to eq 'group_destroy' }
|
2017-11-03 07:26:52 -04:00
|
|
|
it { expect(event_name(group, :rename)).to eq 'group_rename' }
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(event_name(group_member, :create)).to eq 'user_add_to_group' }
|
|
|
|
it { expect(event_name(group_member, :destroy)).to eq 'user_remove_from_group' }
|
2013-10-08 04:06:38 -04:00
|
|
|
end
|
2013-02-20 05:53:15 -05:00
|
|
|
|
2013-10-08 04:06:38 -04:00
|
|
|
def event_data(*args)
|
2014-01-15 07:26:05 -05:00
|
|
|
SystemHooksService.new.send :build_event_data, *args
|
2013-10-08 04:06:38 -04:00
|
|
|
end
|
2013-02-20 05:53:15 -05:00
|
|
|
|
2013-10-08 04:06:38 -04:00
|
|
|
def event_name(*args)
|
2014-01-15 07:26:05 -05:00
|
|
|
SystemHooksService.new.send :build_event_name, *args
|
2013-02-20 05:53:15 -05:00
|
|
|
end
|
|
|
|
end
|