Commit 7c09d37c authored by Tan Le's avatar Tan Le Committed by James Lopez

Verify no audit event is logged when not licensed

If logging related features are not enabled, no audit event is
logged. The change in the shared_examples also extends this test for
other clients of `AuditEventService` in additions to Users services.
parent 0a8d441b
......@@ -13,6 +13,7 @@ describe Users::BlockService do
subject(:operation) { service.execute(user) }
describe 'audit events' do
context 'when licensed' do
before do
stub_licensed_features(admin_audit_log: true)
end
......@@ -41,5 +42,20 @@ describe Users::BlockService do
end
end
end
context 'when not licensed' do
before do
stub_licensed_features(
admin_audit_log: false,
audit_events: false,
extended_audit_events: false
)
end
it 'does not log any audit event' do
expect { operation }.not_to change(AuditEvent, :count)
end
end
end
end
end
......@@ -15,9 +15,10 @@ describe Users::CreateService do
subject(:service) { described_class.new(current_user, params) }
context 'audit events' do
describe '#execute' do
let(:operation) { service.execute }
context 'audit events' do
include_examples 'audit event logging' do
let(:fail_condition!) do
expect_any_instance_of(User)
......@@ -43,9 +44,10 @@ describe Users::CreateService do
context 'when audit is not required' do
let(:current_user) { nil }
it 'does not log audit event' do
it 'does not log any audit event' do
expect { operation }.not_to change(AuditEvent, :count)
end
end
end
end
end
......@@ -4,31 +4,37 @@ require 'spec_helper'
describe Users::DestroyService do
let(:current_user) { create(:admin) }
let(:user) { create(:user) }
subject(:service) { described_class.new(current_user) }
describe '#execute' do
let(:user) { create(:user) }
subject(:operation) { service.execute(user) }
it 'returns result' do
allow(user).to receive(:destroy).and_return(user)
expect(service.execute(user)).to eq(user)
expect(operation).to eq(user)
end
context 'when project is a mirror' do
let(:project) { create(:project, :mirror, mirror_user_id: user.id) }
it 'assigns mirror_user to a project owner' do
mirror_user = create(:user)
project = create(:project, :mirror, mirror_user_id: mirror_user.id)
new_mirror_user = project.team.owners.first
expect_any_instance_of(EE::NotificationService).to receive(:project_mirror_user_changed).with(new_mirror_user, mirror_user.name, project)
expect_any_instance_of(EE::NotificationService)
.to receive(:project_mirror_user_changed)
.with(new_mirror_user, user.name, project)
expect do
described_class.new(mirror_user).execute(mirror_user)
end.to change { project.reload.mirror_user }.from(mirror_user).to(new_mirror_user)
expect { operation }.to change { project.reload.mirror_user }
.from(user).to(new_mirror_user)
end
end
describe 'audit events' do
context 'when licensed' do
before do
stub_licensed_features(admin_audit_log: true)
end
......@@ -88,4 +94,21 @@ describe Users::DestroyService do
end
end
end
context 'when not licensed' do
before do
stub_licensed_features(
admin_audit_log: false,
audit_events: false,
extended_audit_events: false
)
end
it 'does not log any audit event' do
expect { service.execute(user) }
.not_to change { AuditEvent.count }
end
end
end
end
end
# frozen_string_literal: true
RSpec.shared_examples 'audit event logging' do
context 'when licensed' do
before do
stub_licensed_features(extended_audit_events: true)
end
......@@ -22,6 +23,21 @@ RSpec.shared_examples 'audit event logging' do
expect { operation }.not_to change(AuditEvent, :count)
end
end
context 'when not licensed' do
before do
stub_licensed_features(
admin_audit_log: false,
audit_events: false,
extended_audit_events: false
)
end
it 'does not log audit event' do
expect { operation }.not_to change(AuditEvent, :count)
end
end
end
RSpec.shared_examples 'logs the custom audit event' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment