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