diff options
Diffstat (limited to 'spec/initializers')
20 files changed, 73 insertions, 66 deletions
diff --git a/spec/initializers/100_patch_omniauth_saml_spec.rb b/spec/initializers/100_patch_omniauth_saml_spec.rb index c4d20f79af0..3496eb4d680 100644 --- a/spec/initializers/100_patch_omniauth_saml_spec.rb +++ b/spec/initializers/100_patch_omniauth_saml_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'OmniAuth::Strategies::SAML', type: :strategy do +RSpec.describe 'OmniAuth::Strategies::SAML', type: :strategy do let(:idp_sso_target_url) { 'https://login.example.com/idp' } let(:strategy) { [OmniAuth::Strategies::SAML, { idp_sso_target_url: idp_sso_target_url }] } diff --git a/spec/initializers/6_validations_spec.rb b/spec/initializers/6_validations_spec.rb index 248f967311b..b909fc9db0a 100644 --- a/spec/initializers/6_validations_spec.rb +++ b/spec/initializers/6_validations_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require_relative '../../config/initializers/6_validations.rb' -describe '6_validations' do +RSpec.describe '6_validations' do describe 'validate_storages_config' do context 'with correct settings' do before do diff --git a/spec/initializers/action_mailer_hooks_spec.rb b/spec/initializers/action_mailer_hooks_spec.rb index 03eee09f737..f04fe804d62 100644 --- a/spec/initializers/action_mailer_hooks_spec.rb +++ b/spec/initializers/action_mailer_hooks_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'ActionMailer hooks' do +RSpec.describe 'ActionMailer hooks' do describe 'smime signature interceptor' do before do class_spy(ActionMailer::Base).as_stubbed_const diff --git a/spec/initializers/actionpack_generate_old_csrf_token_spec.rb b/spec/initializers/actionpack_generate_old_csrf_token_spec.rb deleted file mode 100644 index 036f52398bb..00000000000 --- a/spec/initializers/actionpack_generate_old_csrf_token_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe ActionController::Base, 'CSRF token generation patch', type: :controller do # rubocop:disable RSpec/FilePath - let(:fixed_seed) { SecureRandom.random_bytes(described_class::AUTHENTICITY_TOKEN_LENGTH) } - - context 'global_csrf_token feature flag is enabled' do - it 'generates 6.0.3.1 style CSRF token', :aggregate_failures do - generated_token = controller.send(:form_authenticity_token) - - expect(valid_authenticity_token?(generated_token)).to be_truthy - expect(compare_with_real_token(generated_token)).to be_falsey - expect(compare_with_global_token(generated_token)).to be_truthy - end - end - - context 'global_csrf_token feature flag is disabled' do - before do - stub_feature_flags(global_csrf_token: false) - end - - it 'generates 6.0.3 style CSRF token', :aggregate_failures do - generated_token = controller.send(:form_authenticity_token) - - expect(valid_authenticity_token?(generated_token)).to be_truthy - expect(compare_with_real_token(generated_token)).to be_truthy - expect(compare_with_global_token(generated_token)).to be_falsey - end - end - - def compare_with_global_token(token) - unmasked_token = controller.send :unmask_token, Base64.strict_decode64(token) - - controller.send(:compare_with_global_token, unmasked_token, session) - end - - def compare_with_real_token(token) - unmasked_token = controller.send :unmask_token, Base64.strict_decode64(token) - - controller.send(:compare_with_real_token, unmasked_token, session) - end - - def valid_authenticity_token?(token) - controller.send(:valid_authenticity_token?, session, token) - end -end diff --git a/spec/initializers/active_record_locking_spec.rb b/spec/initializers/active_record_locking_spec.rb index 5a16aef78e6..e979fa0b793 100644 --- a/spec/initializers/active_record_locking_spec.rb +++ b/spec/initializers/active_record_locking_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'ActiveRecord locking' do +RSpec.describe 'ActiveRecord locking' do let(:issue) { create(:issue) } shared_examples 'locked model' do diff --git a/spec/initializers/asset_proxy_setting_spec.rb b/spec/initializers/asset_proxy_setting_spec.rb index 7eab5de155b..62bb31b2be9 100644 --- a/spec/initializers/asset_proxy_setting_spec.rb +++ b/spec/initializers/asset_proxy_setting_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'Asset proxy settings initialization' do +RSpec.describe 'Asset proxy settings initialization' do describe '#asset_proxy' do it 'defaults to disabled' do expect(Banzai::Filter::AssetProxyFilter).to receive(:initialize_settings) diff --git a/spec/initializers/attr_encrypted_no_db_connection_spec.rb b/spec/initializers/attr_encrypted_no_db_connection_spec.rb index 14e0e1f2167..ad3d14ed7d4 100644 --- a/spec/initializers/attr_encrypted_no_db_connection_spec.rb +++ b/spec/initializers/attr_encrypted_no_db_connection_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'GitLab monkey-patches to AttrEncrypted' do +RSpec.describe 'GitLab monkey-patches to AttrEncrypted' do describe '#attribute_instance_methods_as_symbols_available?' do it 'returns false' do expect(ActiveRecord::Base.__send__(:attribute_instance_methods_as_symbols_available?)).to be_falsy diff --git a/spec/initializers/attr_encrypted_thread_safe_spec.rb b/spec/initializers/attr_encrypted_thread_safe_spec.rb index 096b8b196b4..e79b7c716ec 100644 --- a/spec/initializers/attr_encrypted_thread_safe_spec.rb +++ b/spec/initializers/attr_encrypted_thread_safe_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe AttrEncrypted do +RSpec.describe AttrEncrypted do describe '#encrypted_attributes' do subject do Class.new(ActiveRecord::Base) do diff --git a/spec/initializers/database_config_spec.rb b/spec/initializers/database_config_spec.rb index 7c0b280fdaf..29d499efcd3 100644 --- a/spec/initializers/database_config_spec.rb +++ b/spec/initializers/database_config_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'Database config initializer' do +RSpec.describe 'Database config initializer' do subject do load Rails.root.join('config/initializers/database_config.rb') end diff --git a/spec/initializers/direct_upload_support_spec.rb b/spec/initializers/direct_upload_support_spec.rb index 7db40f4b5ab..aa77c0905c9 100644 --- a/spec/initializers/direct_upload_support_spec.rb +++ b/spec/initializers/direct_upload_support_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'Direct upload support' do +RSpec.describe 'Direct upload support' do subject do load Rails.root.join('config/initializers/direct_upload_support.rb') end diff --git a/spec/initializers/doorkeeper_spec.rb b/spec/initializers/doorkeeper_spec.rb index 47c196cb3a3..164225a00b2 100644 --- a/spec/initializers/doorkeeper_spec.rb +++ b/spec/initializers/doorkeeper_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require_relative '../../config/initializers/doorkeeper' -describe Doorkeeper.configuration do +RSpec.describe Doorkeeper.configuration do describe '#default_scopes' do it 'matches Gitlab::Auth::DEFAULT_SCOPES' do expect(subject.default_scopes).to eq Gitlab::Auth::DEFAULT_SCOPES diff --git a/spec/initializers/fog_google_https_private_urls_spec.rb b/spec/initializers/fog_google_https_private_urls_spec.rb index 8a0d7ad8f15..4825525a3d8 100644 --- a/spec/initializers/fog_google_https_private_urls_spec.rb +++ b/spec/initializers/fog_google_https_private_urls_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'Fog::Storage::GoogleXML::File', :fog_requests do +RSpec.describe 'Fog::Storage::GoogleXML::File', :fog_requests do let(:storage) do Fog.mock! Fog::Storage.new( diff --git a/spec/initializers/hangouts_chat_http_override_spec.rb b/spec/initializers/hangouts_chat_http_override_spec.rb index 0eee891799f..42236c8c853 100644 --- a/spec/initializers/hangouts_chat_http_override_spec.rb +++ b/spec/initializers/hangouts_chat_http_override_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'HangoutsChat::Sender Gitlab::HTTP override' do +RSpec.describe 'HangoutsChat::Sender Gitlab::HTTP override' do describe 'HangoutsChat::Sender::HTTP#post' do it 'calls Gitlab::HTTP.post with default protection settings' do webhook_url = 'https://example.gitlab.com' diff --git a/spec/initializers/lograge_spec.rb b/spec/initializers/lograge_spec.rb index 9e5eab4fc6b..de722764bf4 100644 --- a/spec/initializers/lograge_spec.rb +++ b/spec/initializers/lograge_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'lograge', type: :request do +RSpec.describe 'lograge', type: :request do let(:headers) { { 'X-Request-ID' => 'new-correlation-id' } } let(:large_params) do @@ -152,5 +152,35 @@ describe 'lograge', type: :request do expect(log_data['etag_route']).to eq(etag_route) end end + + context 'with transaction' do + let(:transaction) { Gitlab::Metrics::WebTransaction.new({}) } + + before do + allow(Gitlab::Metrics::Transaction).to receive(:current).and_return(transaction) + end + + context 'when RequestStore is enabled', :request_store do + context 'with db payload' do + it 'includes db counters', :request_store do + ActiveRecord::Base.connection.execute('SELECT pg_sleep(0.1);') + subscriber.process_action(event) + + expect(log_data).to include("db_count" => 1, "db_write_count" => 0, "db_cached_count" => 0) + end + end + end + + context 'when RequestStore is disabled' do + context 'with db payload' do + it 'does not include db counters' do + ActiveRecord::Base.connection.execute('SELECT pg_sleep(0.1);') + subscriber.process_action(event) + + expect(log_data).not_to include("db_count" => 1, "db_write_count" => 0, "db_cached_count" => 0) + end + end + end + end end end diff --git a/spec/initializers/mail_encoding_patch_spec.rb b/spec/initializers/mail_encoding_patch_spec.rb index 41074af3503..efacaf6b1b4 100644 --- a/spec/initializers/mail_encoding_patch_spec.rb +++ b/spec/initializers/mail_encoding_patch_spec.rb @@ -5,7 +5,7 @@ require 'fast_spec_helper' require 'mail' require_relative '../../config/initializers/mail_encoding_patch.rb' -describe 'Mail quoted-printable transfer encoding patch and Unicode characters' do +RSpec.describe 'Mail quoted-printable transfer encoding patch and Unicode characters' do shared_examples 'email encoding' do |email| it 'enclosing in a new object does not change the encoded original' do new_email = Mail.new(email) diff --git a/spec/initializers/rest-client-hostname_override_spec.rb b/spec/initializers/rest-client-hostname_override_spec.rb index 7e36656ba1c..187f18a6b1d 100644 --- a/spec/initializers/rest-client-hostname_override_spec.rb +++ b/spec/initializers/rest-client-hostname_override_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'rest-client dns rebinding protection' do +RSpec.describe 'rest-client dns rebinding protection' do it_behaves_like 'a request using Gitlab::UrlBlocker' do let(:http_method) { :get } let(:url_blocked_error_class) { ArgumentError } diff --git a/spec/initializers/secret_token_spec.rb b/spec/initializers/secret_token_spec.rb index b7979144c72..362371e0962 100644 --- a/spec/initializers/secret_token_spec.rb +++ b/spec/initializers/secret_token_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require_relative '../../config/initializers/01_secret_token' -describe 'create_tokens' do +RSpec.describe 'create_tokens' do include StubENV let(:secrets) { ActiveSupport::OrderedOptions.new } @@ -19,6 +19,30 @@ describe 'create_tokens' do allow(self).to receive(:exit) end + describe 'ensure acknowledged secrets in any installations' do + let(:acknowledged_secrets) do + %w[secret_key_base otp_key_base db_key_base openid_connect_signing_key] + end + + it 'does not allow to add a new secret without a proper handling' do + create_tokens + + secrets_hash = YAML.load_file(Rails.root.join('config/secrets.yml')) + + secrets_hash.each do |environment, secrets| + new_secrets = secrets.keys - acknowledged_secrets + + expect(new_secrets).to be_empty, + <<~EOS + CAUTION: + It looks like you have just added new secret(s) #{new_secrets.inspect} to the secrets.yml. + Please read the development guide for GitLab secrets at doc/development/application_secrets.md before you proceed this change. + If you're absolutely sure that the change is safe, please add the new secrets to the 'acknowledged_secrets' in order to silence this warning. + EOS + end + end + end + context 'setting secret keys' do context 'when none of the secrets exist' do before do diff --git a/spec/initializers/settings_spec.rb b/spec/initializers/settings_spec.rb index 6cb45b4c86b..71ea12a41aa 100644 --- a/spec/initializers/settings_spec.rb +++ b/spec/initializers/settings_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require_relative '../../config/initializers/1_settings' unless defined?(Settings) -describe Settings do +RSpec.describe Settings do describe '#ldap' do it 'can be accessed with dot syntax all the way down' do expect(Gitlab.config.ldap.servers.main.label).to eq('ldap') diff --git a/spec/initializers/trusted_proxies_spec.rb b/spec/initializers/trusted_proxies_spec.rb index a2bd0ff9f1c..2786f034969 100644 --- a/spec/initializers/trusted_proxies_spec.rb +++ b/spec/initializers/trusted_proxies_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'trusted_proxies' do +RSpec.describe 'trusted_proxies' do context 'with default config' do before do set_trusted_proxies([]) diff --git a/spec/initializers/zz_metrics_spec.rb b/spec/initializers/zz_metrics_spec.rb index f41a807f1eb..ad93c30ee22 100644 --- a/spec/initializers/zz_metrics_spec.rb +++ b/spec/initializers/zz_metrics_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'instrument_classes' do +RSpec.describe 'instrument_classes' do let(:config) { double(:config) } before do |