Commit 9df98212 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'pedropombeiro/349540/2-rename-runnerregistrationtokenauthor' into 'master'

Rename RunnerRegistrationTokenAuthor

See merge request gitlab-org/gitlab!79753
parents f9b9348c b26d226d
......@@ -2,7 +2,7 @@
module Gitlab
module Audit
class RunnerRegistrationTokenAuthor < Gitlab::Audit::NullAuthor
class CiRunnerTokenAuthor < Gitlab::Audit::NullAuthor
def initialize(token:, entity_type:, entity_path:)
super(id: -1, name: "Registration token: #{token}")
......
......@@ -14,12 +14,12 @@ module Gitlab
# @param [Integer] id
# @param [String] name
#
# @return [Gitlab::Audit::UnauthenticatedAuthor, Gitlab::Audit::DeletedAuthor, Gitlab::Audit::RunnerRegistrationTokenAuthor]
# @return [Gitlab::Audit::UnauthenticatedAuthor, Gitlab::Audit::DeletedAuthor, Gitlab::Audit::CiRunnerTokenAuthor]
def self.for(id, audit_event)
name = audit_event[:author_name] || audit_event.details[:author_name]
if audit_event.details.include?(:runner_registration_token)
::Gitlab::Audit::RunnerRegistrationTokenAuthor.new(
::Gitlab::Audit::CiRunnerTokenAuthor.new(
token: audit_event.details[:runner_registration_token],
entity_type: audit_event.entity_type || audit_event.details[:entity_type],
entity_path: audit_event.entity_path || audit_event.details[:entity_path]
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe Gitlab::Audit::RunnerRegistrationTokenAuthor do
RSpec.describe Gitlab::Audit::CiRunnerTokenAuthor do
describe '#initialize' do
it 'sets correct attributes' do
expect(described_class.new(token: 'abc1234567', entity_type: 'Project', entity_path: 'd/e'))
......
......@@ -23,14 +23,14 @@ RSpec.describe Gitlab::Audit::NullAuthor do
expect(subject.for(-1, audit_event)).to have_attributes(id: -1, name: 'Frank')
end
it 'returns an RunnerRegistrationTokenAuthor when details contain runner registration token', :aggregate_failures do
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(: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::RunnerRegistrationTokenAuthor)
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
end
......
......@@ -112,13 +112,13 @@ RSpec.describe AuditEvent do
context "when a runner_registration_token's present" do
let(:audit_event) { build(:project_audit_event, details: { target_id: 678, runner_registration_token: 'abc123' }) }
it 'returns a RunnerRegistrationTokenAuthor' do
expect(::Gitlab::Audit::RunnerRegistrationTokenAuthor).to receive(:new)
it 'returns a CiRunnerTokenAuthor' do
expect(::Gitlab::Audit::CiRunnerTokenAuthor).to receive(:new)
.with({ token: 'abc123', entity_type: 'Project', entity_path: audit_event.entity_path })
.and_call_original
.once
is_expected.to be_an_instance_of(::Gitlab::Audit::RunnerRegistrationTokenAuthor)
is_expected.to be_an_instance_of(::Gitlab::Audit::CiRunnerTokenAuthor)
end
it 'name consists of prefix and token' 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