diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 12:45:46 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 12:45:46 +0300 |
commit | a7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch) | |
tree | 7452bd5c3545c2fa67a28aa013835fb4fa071baf /spec/lib/gitlab/audit/ci_runner_token_author_spec.rb | |
parent | ee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff) |
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
Diffstat (limited to 'spec/lib/gitlab/audit/ci_runner_token_author_spec.rb')
-rw-r--r-- | spec/lib/gitlab/audit/ci_runner_token_author_spec.rb | 83 |
1 files changed, 83 insertions, 0 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 |