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 ...@@ -13,6 +13,7 @@ describe Users::BlockService do
subject(:operation) { service.execute(user) } subject(:operation) { service.execute(user) }
describe 'audit events' do describe 'audit events' do
context 'when licensed' do
before do before do
stub_licensed_features(admin_audit_log: true) stub_licensed_features(admin_audit_log: true)
end end
...@@ -41,5 +42,20 @@ describe Users::BlockService do ...@@ -41,5 +42,20 @@ describe Users::BlockService do
end end
end 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
end end
...@@ -15,9 +15,10 @@ describe Users::CreateService do ...@@ -15,9 +15,10 @@ describe Users::CreateService do
subject(:service) { described_class.new(current_user, params) } subject(:service) { described_class.new(current_user, params) }
context 'audit events' do describe '#execute' do
let(:operation) { service.execute } let(:operation) { service.execute }
context 'audit events' do
include_examples 'audit event logging' do include_examples 'audit event logging' do
let(:fail_condition!) do let(:fail_condition!) do
expect_any_instance_of(User) expect_any_instance_of(User)
...@@ -43,9 +44,10 @@ describe Users::CreateService do ...@@ -43,9 +44,10 @@ describe Users::CreateService do
context 'when audit is not required' do context 'when audit is not required' do
let(:current_user) { nil } 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) expect { operation }.not_to change(AuditEvent, :count)
end end
end end
end end
end
end end
...@@ -4,31 +4,37 @@ require 'spec_helper' ...@@ -4,31 +4,37 @@ require 'spec_helper'
describe Users::DestroyService do describe Users::DestroyService do
let(:current_user) { create(:admin) } let(:current_user) { create(:admin) }
let(:user) { create(:user) }
subject(:service) { described_class.new(current_user) } subject(:service) { described_class.new(current_user) }
describe '#execute' do
let(:user) { create(:user) }
subject(:operation) { service.execute(user) }
it 'returns result' do it 'returns result' do
allow(user).to receive(:destroy).and_return(user) allow(user).to receive(:destroy).and_return(user)
expect(service.execute(user)).to eq(user) expect(operation).to eq(user)
end end
context 'when project is a mirror' do 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 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 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 expect { operation }.to change { project.reload.mirror_user }
described_class.new(mirror_user).execute(mirror_user) .from(user).to(new_mirror_user)
end.to change { project.reload.mirror_user }.from(mirror_user).to(new_mirror_user)
end end
end end
describe 'audit events' do describe 'audit events' do
context 'when licensed' do
before do before do
stub_licensed_features(admin_audit_log: true) stub_licensed_features(admin_audit_log: true)
end end
...@@ -88,4 +94,21 @@ describe Users::DestroyService do ...@@ -88,4 +94,21 @@ describe Users::DestroyService do
end end
end 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 end
# frozen_string_literal: true # frozen_string_literal: true
RSpec.shared_examples 'audit event logging' do RSpec.shared_examples 'audit event logging' do
context 'when licensed' do
before do before do
stub_licensed_features(extended_audit_events: true) stub_licensed_features(extended_audit_events: true)
end end
...@@ -22,6 +23,21 @@ RSpec.shared_examples 'audit event logging' do ...@@ -22,6 +23,21 @@ RSpec.shared_examples 'audit event logging' do
expect { operation }.not_to change(AuditEvent, :count) expect { operation }.not_to change(AuditEvent, :count)
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 audit event' do
expect { operation }.not_to change(AuditEvent, :count)
end
end
end end
RSpec.shared_examples 'logs the custom audit event' do 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