Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-02-18 12:45:46 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-02-18 12:45:46 +0300
commita7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch)
tree7452bd5c3545c2fa67a28aa013835fb4fa071baf /spec/lib/gitlab/audit
parentee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff)
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
Diffstat (limited to 'spec/lib/gitlab/audit')
-rw-r--r--spec/lib/gitlab/audit/ci_runner_token_author_spec.rb83
-rw-r--r--spec/lib/gitlab/audit/null_author_spec.rb40
2 files changed, 120 insertions, 3 deletions
diff --git a/spec/lib/gitlab/audit/ci_runner_token_author_spec.rb b/spec/lib/gitlab/audit/ci_runner_token_author_spec.rb
new file mode 100644
index 00000000000..f55e1b44936
--- /dev/null
+++ b/spec/lib/gitlab/audit/ci_runner_token_author_spec.rb
@@ -0,0 +1,83 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::Audit::CiRunnerTokenAuthor do
+ describe '.initialize' do
+ subject { described_class.new(audit_event) }
+
+ let(:details) { }
+ let(:audit_event) { instance_double(AuditEvent, details: details, entity_type: 'Project', entity_path: 'd/e') }
+
+ context 'with runner_authentication_token' do
+ let(:details) do
+ { runner_authentication_token: 'abc1234567' }
+ end
+
+ it 'returns CiRunnerTokenAuthor with expected attributes' do
+ is_expected.to have_attributes(id: -1, name: 'Authentication token: abc1234567')
+ end
+ end
+
+ context 'with runner_registration_token' do
+ let(:details) do
+ { runner_registration_token: 'abc1234567' }
+ end
+
+ it 'returns CiRunnerTokenAuthor with expected attributes' do
+ is_expected.to have_attributes(id: -1, name: 'Registration token: abc1234567')
+ end
+ end
+
+ context 'with runner token missing' do
+ let(:details) do
+ {}
+ end
+
+ it 'raises ArgumentError' do
+ expect { subject }.to raise_error ArgumentError, 'Runner token missing'
+ end
+ end
+ end
+
+ describe '#full_path' do
+ subject { author.full_path }
+
+ let(:author) { described_class.new(audit_event) }
+
+ context 'with instance registration token' do
+ let(:audit_event) { instance_double(AuditEvent, details: { runner_registration_token: 'abc1234567' }, entity_type: 'User', entity_path: nil) }
+
+ it 'returns correct url' do
+ is_expected.to eq('/admin/runners')
+ end
+ end
+
+ context 'with group registration token' do
+ let(:audit_event) { instance_double(AuditEvent, details: { runner_registration_token: 'abc1234567' }, entity_type: 'Group', entity_path: 'a/b') }
+
+ it 'returns correct url' do
+ expect(::Gitlab::Routing.url_helpers).to receive(:group_settings_ci_cd_path)
+ .once
+ .with('a/b', { anchor: 'js-runners-settings' })
+ .and_return('/path/to/group/runners')
+
+ is_expected.to eq('/path/to/group/runners')
+ end
+ end
+
+ context 'with project registration token' do
+ let(:audit_event) { instance_double(AuditEvent, details: { runner_registration_token: 'abc1234567' }, entity_type: 'Project', entity_path: project.full_path) }
+ let(:project) { create(:project) }
+
+ it 'returns correct url' do
+ expect(::Gitlab::Routing.url_helpers).to receive(:project_settings_ci_cd_path)
+ .once
+ .with(project, { anchor: 'js-runners-settings' })
+ .and_return('/path/to/project/runners')
+
+ is_expected.to eq('/path/to/project/runners')
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/audit/null_author_spec.rb b/spec/lib/gitlab/audit/null_author_spec.rb
index eb80e5faa89..7203a0cd816 100644
--- a/spec/lib/gitlab/audit/null_author_spec.rb
+++ b/spec/lib/gitlab/audit/null_author_spec.rb
@@ -6,13 +6,47 @@ RSpec.describe Gitlab::Audit::NullAuthor do
subject { described_class }
describe '.for' do
+ let(:audit_event) { instance_double(AuditEvent) }
+
it 'returns an DeletedAuthor' do
- expect(subject.for(666, 'Old Hat')).to be_a(Gitlab::Audit::DeletedAuthor)
+ allow(audit_event).to receive(:[]).with(:author_name).and_return('Old Hat')
+ allow(audit_event).to receive(:details).and_return({})
+ allow(audit_event).to receive(:target_type)
+
+ expect(subject.for(666, audit_event)).to be_a(Gitlab::Audit::DeletedAuthor)
end
it 'returns an UnauthenticatedAuthor when id equals -1', :aggregate_failures do
- expect(subject.for(-1, 'Frank')).to be_a(Gitlab::Audit::UnauthenticatedAuthor)
- expect(subject.for(-1, 'Frank')).to have_attributes(id: -1, name: 'Frank')
+ allow(audit_event).to receive(:[]).with(:author_name).and_return('Frank')
+ allow(audit_event).to receive(:details).and_return({})
+ allow(audit_event).to receive(:target_type)
+
+ expect(subject.for(-1, audit_event)).to be_a(Gitlab::Audit::UnauthenticatedAuthor)
+ expect(subject.for(-1, audit_event)).to have_attributes(id: -1, name: 'Frank')
+ end
+
+ it 'returns a CiRunnerTokenAuthor when details contain runner registration token', :aggregate_failures do
+ allow(audit_event).to receive(:[]).with(:author_name).and_return('cde456')
+ allow(audit_event).to receive(:entity_type).and_return('User')
+ allow(audit_event).to receive(:entity_path).and_return('/a/b')
+ allow(audit_event).to receive(:target_type).and_return(::Ci::Runner.name)
+ allow(audit_event).to receive(:details)
+ .and_return({ runner_registration_token: 'cde456', author_name: 'cde456', entity_type: 'User', entity_path: '/a/b' })
+
+ expect(subject.for(-1, audit_event)).to be_a(Gitlab::Audit::CiRunnerTokenAuthor)
+ expect(subject.for(-1, audit_event)).to have_attributes(id: -1, name: 'Registration token: cde456')
+ end
+
+ it 'returns a CiRunnerTokenAuthor when details contain runner authentication token', :aggregate_failures do
+ allow(audit_event).to receive(:[]).with(:author_name).and_return('cde456')
+ allow(audit_event).to receive(:entity_type).and_return('User')
+ allow(audit_event).to receive(:entity_path).and_return('/a/b')
+ allow(audit_event).to receive(:target_type).and_return(::Ci::Runner.name)
+ allow(audit_event).to receive(:details)
+ .and_return({ runner_authentication_token: 'cde456', author_name: 'cde456', entity_type: 'User', entity_path: '/a/b' })
+
+ expect(subject.for(-1, audit_event)).to be_a(Gitlab::Audit::CiRunnerTokenAuthor)
+ expect(subject.for(-1, audit_event)).to have_attributes(id: -1, name: 'Authentication token: cde456')
end
end