diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /spec/services/audit_event_service_spec.rb | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'spec/services/audit_event_service_spec.rb')
-rw-r--r-- | spec/services/audit_event_service_spec.rb | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/spec/services/audit_event_service_spec.rb b/spec/services/audit_event_service_spec.rb index 3317fcf8444..997f506c269 100644 --- a/spec/services/audit_event_service_spec.rb +++ b/spec/services/audit_event_service_spec.rb @@ -3,17 +3,13 @@ require 'spec_helper' RSpec.describe AuditEventService do - let(:project) { create(:project) } - let(:user) { create(:user, :with_sign_ins) } - let(:project_member) { create(:project_member, user: user) } + let_it_be(:project) { create(:project) } + let_it_be(:user) { create(:user, :with_sign_ins) } + let_it_be(:project_member) { create(:project_member, user: user) } let(:service) { described_class.new(user, project, { action: :destroy }) } let(:logger) { instance_double(Gitlab::AuditJsonLogger) } describe '#security_event' do - before do - stub_licensed_features(admin_audit_log: false) - end - it 'creates an event and logs to a file' do expect(service).to receive(:file_logger).and_return(logger) expect(logger).to receive(:info).with(author_id: user.id, @@ -78,6 +74,31 @@ RSpec.describe AuditEventService do audit_service.for_authentication.security_event end + + context 'with IP address', :request_store do + using RSpec::Parameterized::TableSyntax + + where(:from_caller, :from_context, :from_author_sign_in, :output) do + '192.168.0.1' | '192.168.0.2' | '192.168.0.3' | '192.168.0.1' + nil | '192.168.0.2' | '192.168.0.3' | '192.168.0.2' + nil | nil | '192.168.0.3' | '192.168.0.3' + end + + with_them do + let(:user) { create(:user, current_sign_in_ip: from_author_sign_in) } + let(:audit_service) { described_class.new(user, user, with: 'standard', ip_address: from_caller) } + + before do + allow(Gitlab::RequestContext.instance).to receive(:client_ip).and_return(from_context) + end + + specify do + expect(AuthenticationEvent).to receive(:new).with(hash_including(ip_address: output)) + + audit_service.for_authentication.security_event + end + end + end end end |