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,13 +191,17 @@ describe GitlabSchema do ...@@ -191,13 +191,17 @@ 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
include GlobalID::Identification test_global_id = Class.new do
attr_accessor :id include GlobalID::Identification
attr_accessor :id
def initialize(id)
@id = id def initialize(id)
@id = id
end
end end
stub_const('TestGlobalId', test_global_id)
end end
it 'falls back to a regular find' do it 'falls back to a regular find' do
......
...@@ -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,40 +4,45 @@ require 'spec_helper' ...@@ -4,40 +4,45 @@ 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) }
# we need to define the classes due to encryption before do
class IssueTrackerData < ApplicationRecord # we need to define the classes due to encryption
self.table_name = 'issue_tracker_data' issue_tracker_data = Class.new(ApplicationRecord) do
self.table_name = 'issue_tracker_data'
def self.encryption_options
{ def self.encryption_options
key: Settings.attr_encrypted_db_key_base_32, {
encode: true, key: Settings.attr_encrypted_db_key_base_32,
mode: :per_attribute_iv, encode: true,
algorithm: 'aes-256-gcm' 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 end
attr_encrypted :project_url, encryption_options jira_tracker_data = Class.new(ApplicationRecord) do
attr_encrypted :issues_url, encryption_options self.table_name = 'jira_tracker_data'
attr_encrypted :new_issue_url, encryption_options
end
class JiraTrackerData < ApplicationRecord def self.encryption_options
self.table_name = 'jira_tracker_data' {
key: Settings.attr_encrypted_db_key_base_32,
encode: true,
mode: :per_attribute_iv,
algorithm: 'aes-256-gcm'
}
end
def self.encryption_options attr_encrypted :url, encryption_options
{ attr_encrypted :api_url, encryption_options
key: Settings.attr_encrypted_db_key_base_32, attr_encrypted :username, encryption_options
encode: true, attr_encrypted :password, encryption_options
mode: :per_attribute_iv,
algorithm: 'aes-256-gcm'
}
end end
attr_encrypted :url, encryption_options stub_const('IssueTrackerData', issue_tracker_data)
attr_encrypted :api_url, encryption_options stub_const('JiraTrackerData', jira_tracker_data)
attr_encrypted :username, encryption_options
attr_encrypted :password, encryption_options
end end
let(:url) { 'http://base-url.tracker.com' } 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