Skip to content
代码片段 群组 项目
提交 b217d2ee 编辑于 作者: Max Woolf's avatar Max Woolf
浏览文件

Forbid creating streaming destinations for subgroups

Subgroups should not be able to create
audit event streaming destinations as
this is only possible at the root level.

EE: true
Changelog: changed
上级 7acfccb2
No related branches found
No related tags found
无相关合并请求
...@@ -13,5 +13,13 @@ class ExternalAuditEventDestination < ApplicationRecord ...@@ -13,5 +13,13 @@ class ExternalAuditEventDestination < ApplicationRecord
validates :destination_url, public_url: true, presence: true validates :destination_url, public_url: true, presence: true
validates :destination_url, uniqueness: { scope: :namespace_id }, length: { maximum: 255 } validates :destination_url, uniqueness: { scope: :namespace_id }, length: { maximum: 255 }
has_secure_token :verification_token, length: 24 has_secure_token :verification_token, length: 24
validate :root_level_group?
private
def root_level_group?
errors.add(:group, 'must not be a subgroup') if group.subgroup?
end
end end
end end
...@@ -3,17 +3,35 @@ ...@@ -3,17 +3,35 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe AuditEvents::ExternalAuditEventDestination do RSpec.describe AuditEvents::ExternalAuditEventDestination do
subject { build(:external_audit_event_destination) } subject { create(:external_audit_event_destination) }
let_it_be(:group) { create(:group) }
describe 'Associations' do describe 'Associations' do
it { is_expected.to belong_to(:group) } it 'belongs to a group' do
expect(subject.group).not_to be_nil
end
end end
describe 'Validations' do describe 'Validations' do
it { is_expected.to validate_uniqueness_of(:destination_url).scoped_to(:namespace_id) }
it { is_expected.to validate_length_of(:destination_url).is_at_most(255) } it { is_expected.to validate_length_of(:destination_url).is_at_most(255) }
it { is_expected.to validate_presence_of(:destination_url) } it { is_expected.to validate_presence_of(:destination_url) }
it { is_expected.to have_db_column(:verification_token).of_type(:text) } it { is_expected.to have_db_column(:verification_token).of_type(:text) }
it 'must have a unique destination_url' do
create(:external_audit_event_destination, destination_url: 'https://example.com/1', group: group)
dup = build(:external_audit_event_destination, destination_url: 'https://example.com/1', group: group)
dup.save # rubocop:disable Rails/SaveBang
expect(dup.errors.full_messages).to include('Destination url has already been taken')
end
it 'must not have any parents' do
destination = build(:external_audit_event_destination, group: create(:group, :nested))
destination.save # rubocop:disable Rails/SaveBang
expect(destination.errors.full_messages).to include('Group must not be a subgroup')
end
end end
it_behaves_like 'includes Limitable concern' do it_behaves_like 'includes Limitable concern' do
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
RSpec.describe 'Create an external audit event destination' do RSpec.describe 'Create an external audit event destination' do
include GraphqlHelpers include GraphqlHelpers
let_it_be(:group) { create(:group, :nested) } let_it_be(:group) { create(:group) }
let_it_be(:owner) { create(:user) } let_it_be(:owner) { create(:user) }
let(:current_user) { owner } let(:current_user) { owner }
...@@ -80,6 +80,12 @@ ...@@ -80,6 +80,12 @@
it_behaves_like 'a mutation that does not create a destination' it_behaves_like 'a mutation that does not create a destination'
end end
context 'when group is a subgroup' do
let_it_be(:group) { create(:group, :nested) }
it_behaves_like 'a mutation that does not create a destination'
end
end end
context 'when current user is a group maintainer' do context 'when current user is a group maintainer' do
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册