Commit 9a00ad21 authored by James Fargher's avatar James Fargher

Merge branch 'rc/fix_leaky_constants_5' into 'master'

Fix RSpec/LeakyConstantDeclaration violations

See merge request gitlab-org/gitlab!31792
parents 7e18aef5 c299f9aa
...@@ -348,12 +348,7 @@ RSpec/LeakyConstantDeclaration: ...@@ -348,12 +348,7 @@ RSpec/LeakyConstantDeclaration:
Enabled: true Enabled: true
Exclude: Exclude:
- 'spec/db/schema_spec.rb' - 'spec/db/schema_spec.rb'
- 'spec/graphql/gitlab_schema_spec.rb'
- 'spec/helpers/visibility_level_helper_spec.rb'
- 'spec/initializers/secret_token_spec.rb'
- 'spec/lib/declarative_policy_spec.rb'
- 'spec/lib/feature_spec.rb' - 'spec/lib/feature_spec.rb'
- 'spec/lib/gitlab/background_migration/migrate_issue_trackers_sensitive_data_spec.rb'
- 'spec/lib/gitlab/ci/build/credentials/factory_spec.rb' - 'spec/lib/gitlab/ci/build/credentials/factory_spec.rb'
- 'spec/lib/gitlab/ci/config/entry/retry_spec.rb' - 'spec/lib/gitlab/ci/config/entry/retry_spec.rb'
- 'spec/lib/gitlab/cluster/mixins/puma_cluster_spec.rb' - 'spec/lib/gitlab/cluster/mixins/puma_cluster_spec.rb'
......
...@@ -191,7 +191,8 @@ describe GitlabSchema do ...@@ -191,7 +191,8 @@ describe GitlabSchema do
context 'for other classes' do context 'for other classes' do
# We cannot use an anonymous class here as `GlobalID` expects `.name` not # We cannot use an anonymous class here as `GlobalID` expects `.name` not
# to return `nil` # to return `nil`
class TestGlobalId before do
test_global_id = Class.new do
include GlobalID::Identification include GlobalID::Identification
attr_accessor :id attr_accessor :id
...@@ -200,6 +201,9 @@ describe GitlabSchema do ...@@ -200,6 +201,9 @@ describe GitlabSchema do
end end
end end
stub_const('TestGlobalId', test_global_id)
end
it 'falls back to a regular find' do it 'falls back to a regular find' do
result = TestGlobalId.new(123) result = TestGlobalId.new(123)
......
...@@ -146,22 +146,22 @@ describe VisibilityLevelHelper do ...@@ -146,22 +146,22 @@ describe VisibilityLevelHelper do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
PUBLIC = Gitlab::VisibilityLevel::PUBLIC public_vis = Gitlab::VisibilityLevel::PUBLIC
INTERNAL = Gitlab::VisibilityLevel::INTERNAL internal_vis = Gitlab::VisibilityLevel::INTERNAL
PRIVATE = Gitlab::VisibilityLevel::PRIVATE private_vis = Gitlab::VisibilityLevel::PRIVATE
# This is a subset of all the permutations # This is a subset of all the permutations
where(:requested_level, :max_allowed, :global_default_level, :restricted_levels, :expected) do where(:requested_level, :max_allowed, :global_default_level, :restricted_levels, :expected) do
PUBLIC | PUBLIC | PUBLIC | [] | PUBLIC public_vis | public_vis | public_vis | [] | public_vis
PUBLIC | PUBLIC | PUBLIC | [PUBLIC] | INTERNAL public_vis | public_vis | public_vis | [public_vis] | internal_vis
INTERNAL | PUBLIC | PUBLIC | [] | INTERNAL internal_vis | public_vis | public_vis | [] | internal_vis
INTERNAL | PRIVATE | PRIVATE | [] | PRIVATE internal_vis | private_vis | private_vis | [] | private_vis
PRIVATE | PUBLIC | PUBLIC | [] | PRIVATE private_vis | public_vis | public_vis | [] | private_vis
PUBLIC | PRIVATE | INTERNAL | [] | PRIVATE public_vis | private_vis | internal_vis | [] | private_vis
PUBLIC | INTERNAL | PUBLIC | [] | INTERNAL public_vis | internal_vis | public_vis | [] | internal_vis
PUBLIC | PRIVATE | PUBLIC | [] | PRIVATE public_vis | private_vis | public_vis | [] | private_vis
PUBLIC | INTERNAL | INTERNAL | [] | INTERNAL public_vis | internal_vis | internal_vis | [] | internal_vis
PUBLIC | PUBLIC | INTERNAL | [] | PUBLIC public_vis | public_vis | internal_vis | [] | public_vis
end end
before do before do
......
...@@ -7,9 +7,8 @@ describe 'create_tokens' do ...@@ -7,9 +7,8 @@ describe 'create_tokens' do
include StubENV include StubENV
let(:secrets) { ActiveSupport::OrderedOptions.new } let(:secrets) { ActiveSupport::OrderedOptions.new }
let(:hex_key) { /\h{128}/.freeze }
HEX_KEY = /\h{128}/.freeze let(:rsa_key) { /\A-----BEGIN RSA PRIVATE KEY-----\n.+\n-----END RSA PRIVATE KEY-----\n\Z/m.freeze }
RSA_KEY = /\A-----BEGIN RSA PRIVATE KEY-----\n.+\n-----END RSA PRIVATE KEY-----\n\Z/m.freeze
before do before do
allow(File).to receive(:write) allow(File).to receive(:write)
...@@ -35,7 +34,7 @@ describe 'create_tokens' do ...@@ -35,7 +34,7 @@ describe 'create_tokens' do
keys = secrets.values_at(:secret_key_base, :otp_key_base, :db_key_base) keys = secrets.values_at(:secret_key_base, :otp_key_base, :db_key_base)
expect(keys.uniq).to eq(keys) expect(keys.uniq).to eq(keys)
expect(keys).to all(match(HEX_KEY)) expect(keys).to all(match(hex_key))
end end
it 'generates an RSA key for openid_connect_signing_key' do it 'generates an RSA key for openid_connect_signing_key' do
...@@ -44,7 +43,7 @@ describe 'create_tokens' do ...@@ -44,7 +43,7 @@ describe 'create_tokens' do
keys = secrets.values_at(:openid_connect_signing_key) keys = secrets.values_at(:openid_connect_signing_key)
expect(keys.uniq).to eq(keys) expect(keys.uniq).to eq(keys)
expect(keys).to all(match(RSA_KEY)) expect(keys).to all(match(rsa_key))
end end
it 'warns about the secrets to add to secrets.yml' do it 'warns about the secrets to add to secrets.yml' do
......
...@@ -23,8 +23,10 @@ describe DeclarativePolicy do ...@@ -23,8 +23,10 @@ describe DeclarativePolicy do
end end
context 'when found policy class does not inherit base' do context 'when found policy class does not inherit base' do
class Foo; end before do
class FooPolicy; end stub_const('Foo', Class.new)
stub_const('FooPolicy', Class.new)
end
it 'raises error if inferred class does not inherit Base' do it 'raises error if inferred class does not inherit Base' do
instance = Foo.new instance = Foo.new
......
...@@ -4,8 +4,9 @@ require 'spec_helper' ...@@ -4,8 +4,9 @@ require 'spec_helper'
describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, schema: 20200130145430 do describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, schema: 20200130145430 do
let(:services) { table(:services) } let(:services) { table(:services) }
before do
# we need to define the classes due to encryption # we need to define the classes due to encryption
class IssueTrackerData < ApplicationRecord issue_tracker_data = Class.new(ApplicationRecord) do
self.table_name = 'issue_tracker_data' self.table_name = 'issue_tracker_data'
def self.encryption_options def self.encryption_options
...@@ -22,7 +23,7 @@ describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, schema: ...@@ -22,7 +23,7 @@ describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, schema:
attr_encrypted :new_issue_url, encryption_options attr_encrypted :new_issue_url, encryption_options
end end
class JiraTrackerData < ApplicationRecord jira_tracker_data = Class.new(ApplicationRecord) do
self.table_name = 'jira_tracker_data' self.table_name = 'jira_tracker_data'
def self.encryption_options def self.encryption_options
...@@ -40,6 +41,10 @@ describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, schema: ...@@ -40,6 +41,10 @@ describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, schema:
attr_encrypted :password, encryption_options attr_encrypted :password, encryption_options
end end
stub_const('IssueTrackerData', issue_tracker_data)
stub_const('JiraTrackerData', jira_tracker_data)
end
let(:url) { 'http://base-url.tracker.com' } let(:url) { 'http://base-url.tracker.com' }
let(:new_issue_url) { 'http://base-url.tracker.com/new_issue' } let(:new_issue_url) { 'http://base-url.tracker.com/new_issue' }
let(:issues_url) { 'http://base-url.tracker.com/issues' } let(:issues_url) { 'http://base-url.tracker.com/issues' }
......
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