Skip to content
Snippets Groups Projects
Commit df1fde30 authored by Ahmad Tolba's avatar Ahmad Tolba
Browse files

Merge branch 'john-mason-remove-feature-flags-14-7see' into '14-7-stable-ee'

Remove runners token prefix feature flags in 14-7-stable-ee

See merge request gitlab-org/gitlab!82121
parents de225f51 d57e7e19
No related branches found
No related tags found
No related merge requests found
# frozen_string_literal: true
module RunnersTokenPrefixable
extend ActiveSupport::Concern
# Prefix for runners_token which can be used to invalidate existing tokens.
# The value chosen here is GR (for Gitlab Runner) combined with the rotation
# date (20220225) decimal to hex encoded.
RUNNERS_TOKEN_PREFIX = 'GR1348941'
def runners_token_prefix
RUNNERS_TOKEN_PREFIX
end
end
Loading
Loading
@@ -19,14 +19,10 @@ class Group < Namespace
include BulkMemberAccessLoad
include ChronicDurationAttribute
include RunnerTokenExpirationInterval
include RunnersTokenPrefixable
 
extend ::Gitlab::Utils::Override
 
# Prefix for runners_token which can be used to invalidate existing tokens.
# The value chosen here is GR (for Gitlab Runner) combined with the rotation
# date (20220225) decimal to hex encoded.
RUNNERS_TOKEN_PREFIX = 'GR1348941'
def self.sti_name
'Group'
end
Loading
Loading
@@ -124,7 +120,7 @@ class Group < Namespace
 
add_authentication_token_field :runners_token,
encrypted: -> { Feature.enabled?(:groups_tokens_optional_encryption, default_enabled: true) ? :optional : :required },
prefix: ->(instance) { instance.runners_token_prefix }
prefix: RunnersTokenPrefixable::RUNNERS_TOKEN_PREFIX
 
after_create :post_create_hook
after_destroy :post_destroy_hook
Loading
Loading
@@ -678,10 +674,6 @@ class Group < Namespace
ensure_runners_token!
end
 
def runners_token_prefix
Feature.enabled?(:groups_runners_token_prefix, self, default_enabled: :yaml) ? RUNNERS_TOKEN_PREFIX : ''
end
override :format_runners_token
def format_runners_token(token)
"#{runners_token_prefix}#{token}"
Loading
Loading
Loading
Loading
@@ -38,6 +38,7 @@ class Project < ApplicationRecord
include GitlabRoutingHelper
include BulkMemberAccessLoad
include RunnerTokenExpirationInterval
include RunnersTokenPrefixable
 
extend Gitlab::Cache::RequestCache
extend Gitlab::Utils::Override
Loading
Loading
@@ -74,11 +75,6 @@ class Project < ApplicationRecord
 
GL_REPOSITORY_TYPES = [Gitlab::GlRepository::PROJECT, Gitlab::GlRepository::WIKI, Gitlab::GlRepository::DESIGN].freeze
 
# Prefix for runners_token which can be used to invalidate existing tokens.
# The value chosen here is GR (for Gitlab Runner) combined with the rotation
# date (20220225) decimal to hex encoded.
RUNNERS_TOKEN_PREFIX = 'GR1348941'
cache_markdown_field :description, pipeline: :description
 
default_value_for :packages_enabled, true
Loading
Loading
@@ -101,7 +97,7 @@ class Project < ApplicationRecord
 
add_authentication_token_field :runners_token,
encrypted: -> { Feature.enabled?(:projects_tokens_optional_encryption, default_enabled: true) ? :optional : :required },
prefix: ->(instance) { instance.runners_token_prefix }
prefix: RunnersTokenPrefixable::RUNNERS_TOKEN_PREFIX
 
before_validation :mark_remote_mirrors_for_removal, if: -> { RemoteMirror.table_exists? }
 
Loading
Loading
@@ -1847,10 +1843,6 @@ class Project < ApplicationRecord
ensure_runners_token!
end
 
def runners_token_prefix
Feature.enabled?(:projects_runners_token_prefix, self, default_enabled: :yaml) ? RUNNERS_TOKEN_PREFIX : ''
end
override :format_runners_token
def format_runners_token(token)
"#{runners_token_prefix}#{token}"
Loading
Loading
---
name: groups_runners_token_prefix
introduced_by_url:
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/353805
milestone: '14.9'
type: development
group: group::database
default_enabled: true
---
name: projects_runners_token_prefix
introduced_by_url:
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/353805
milestone: '14.9'
type: development
group: group::database
default_enabled: true
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe RunnersTokenPrefixable do
before do
stub_const('DummyModel', Class.new)
DummyModel.class_eval do
include RunnersTokenPrefixable
end
end
describe '.runners_token_prefix' do
subject { DummyModel.new }
it 'returns RUNNERS_TOKEN_PREFIX' do
expect(subject.runners_token_prefix).to eq(RunnersTokenPrefixable::RUNNERS_TOKEN_PREFIX)
end
end
end
Loading
Loading
@@ -297,7 +297,7 @@ RSpec.shared_examples 'prefixed token rotation' do
 
context 'token is not set' do
it 'generates a new token' do
expect(subject).to match(/^#{instance.class::RUNNERS_TOKEN_PREFIX}/)
expect(subject).to match(/^#{RunnersTokenPrefixable::RUNNERS_TOKEN_PREFIX}/)
expect(instance).not_to be_persisted
end
end
Loading
Loading
@@ -308,26 +308,14 @@ RSpec.shared_examples 'prefixed token rotation' do
end
 
it 'generates a new token' do
expect(subject).to match(/^#{instance.class::RUNNERS_TOKEN_PREFIX}/)
expect(subject).to match(/^#{RunnersTokenPrefixable::RUNNERS_TOKEN_PREFIX}/)
expect(instance).not_to be_persisted
end
context 'feature flag is disabled' do
before do
flag = "#{described_class.name.downcase.pluralize}_runners_token_prefix"
stub_feature_flags(flag => false)
end
it 'leaves the token unchanged' do
expect { subject }.not_to change(instance, :runners_token)
expect(instance).not_to be_persisted
end
end
end
 
context 'token is set and matches prefix' do
before do
instance.set_runners_token(instance.class::RUNNERS_TOKEN_PREFIX + '-abcdef')
instance.set_runners_token(RunnersTokenPrefixable::RUNNERS_TOKEN_PREFIX + '-abcdef')
end
 
it 'leaves the token unchanged' do
Loading
Loading
@@ -342,7 +330,7 @@ RSpec.shared_examples 'prefixed token rotation' do
 
context 'token is not set' do
it 'generates a new token' do
expect(subject).to match(/^#{instance.class::RUNNERS_TOKEN_PREFIX}/)
expect(subject).to match(/^#{RunnersTokenPrefixable::RUNNERS_TOKEN_PREFIX}/)
expect(instance).to be_persisted
end
end
Loading
Loading
@@ -353,25 +341,14 @@ RSpec.shared_examples 'prefixed token rotation' do
end
 
it 'generates a new token' do
expect(subject).to match(/^#{instance.class::RUNNERS_TOKEN_PREFIX}/)
expect(subject).to match(/^#{RunnersTokenPrefixable::RUNNERS_TOKEN_PREFIX}/)
expect(instance).to be_persisted
end
context 'feature flag is disabled' do
before do
flag = "#{described_class.name.downcase.pluralize}_runners_token_prefix"
stub_feature_flags(flag => false)
end
it 'leaves the token unchanged' do
expect { subject }.not_to change(instance, :runners_token)
end
end
end
 
context 'token is set and matches prefix' do
before do
instance.set_runners_token(instance.class::RUNNERS_TOKEN_PREFIX + '-abcdef')
instance.set_runners_token(RunnersTokenPrefixable::RUNNERS_TOKEN_PREFIX + '-abcdef')
instance.save!
end
 
Loading
Loading
Loading
Loading
@@ -3155,6 +3155,6 @@ RSpec.describe Group do
 
subject { group }
 
it_behaves_like 'it has a prefixable runners_token', :groups_runners_token_prefix
it_behaves_like 'it has a prefixable runners_token'
end
end
Loading
Loading
@@ -7845,7 +7845,7 @@ RSpec.describe Project, factory_default: :keep do
 
subject { project }
 
it_behaves_like 'it has a prefixable runners_token', :projects_runners_token_prefix
it_behaves_like 'it has a prefixable runners_token'
end
 
private
Loading
Loading
# frozen_string_literal: true
 
RSpec.shared_examples 'it has a prefixable runners_token' do |feature_flag|
context 'feature flag enabled' do
before do
stub_feature_flags(feature_flag => [subject])
RSpec.shared_examples 'it has a prefixable runners_token' do
describe '#runners_token' do
it 'has a runners_token_prefix' do
expect(subject.runners_token_prefix).not_to be_empty
end
 
describe '#runners_token' do
it 'has a runners_token_prefix' do
expect(subject.runners_token_prefix).not_to be_empty
end
it 'starts with the runners_token_prefix' do
expect(subject.runners_token).to start_with(subject.runners_token_prefix)
end
end
end
context 'feature flag disabled' do
before do
stub_feature_flags(feature_flag => false)
end
describe '#runners_token' do
it 'does not have a runners_token_prefix' do
expect(subject.runners_token_prefix).to be_empty
end
it 'starts with the runners_token_prefix' do
expect(subject.runners_token).to start_with(subject.runners_token_prefix)
end
it 'starts with the runners_token_prefix' do
expect(subject.runners_token).to start_with(subject.runners_token_prefix)
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment