From 1c7b7362b11b348857c91413e409f708ce28954b Mon Sep 17 00:00:00 2001 From: Pedro Pombeiro <noreply@pedro.pombei.ro> Date: Fri, 4 Oct 2024 15:57:08 +0000 Subject: [PATCH] Hide partition prefix from runner short_sha --- app/models/ci/runner.rb | 4 +++- spec/models/ci/runner_spec.rb | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb index 9a291aa5c1759..4156413f80a40 100644 --- a/app/models/ci/runner.rb +++ b/app/models/ci/runner.rb @@ -411,8 +411,10 @@ def only_for?(project) def short_sha return unless token + # We want to show the first characters of the hash, so we need to bypass any fixed components of the token, + # such as CREATED_RUNNER_TOKEN_PREFIX or partition_id_prefix_in_16_bit_encode start_index = authenticated_user_registration_type? ? CREATED_RUNNER_TOKEN_PREFIX.length : 0 - token[start_index..start_index + RUNNER_SHORT_SHA_LENGTH] + token[start_index..start_index + RUNNER_SHORT_SHA_LENGTH].delete_prefix(partition_id_prefix_in_16_bit_encode) end def tag_list diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb index 4eaf37857bc8d..8567ed906d763 100644 --- a/spec/models/ci/runner_spec.rb +++ b/spec/models/ci/runner_spec.rb @@ -1697,6 +1697,7 @@ def does_db_update let(:runner) { create(:ci_runner) } specify { expect(runner.token).not_to start_with(described_class::CREATED_RUNNER_TOKEN_PREFIX) } + it { is_expected.not_to start_with('t1_') } it { is_expected.not_to start_with(described_class::CREATED_RUNNER_TOKEN_PREFIX) } end @@ -1704,6 +1705,7 @@ def does_db_update let(:runner) { create(:ci_runner, registration_type: :authenticated_user) } specify { expect(runner.token).to start_with(described_class::CREATED_RUNNER_TOKEN_PREFIX) } + it { is_expected.not_to start_with('t1_') } it { is_expected.not_to start_with(described_class::CREATED_RUNNER_TOKEN_PREFIX) } end end -- GitLab