File: application_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (66 lines) | stat: -rw-r--r-- 2,769 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Application, feature_category: :scalability do # rubocop:disable RSpec/SpecFilePathFormat
  describe 'config.filter_parameters' do
    using RSpec::Parameterized::TableSyntax

    filtered = ActiveSupport::ParameterFilter::FILTERED

    context 'when parameters are logged' do
      describe 'rails does not leak confidential parameters' do
        def request_for_url(input_url)
          env = Rack::MockRequest.env_for(input_url)
          env['action_dispatch.parameter_filter'] = described_class.config.filter_parameters

          ActionDispatch::Request.new(env)
        end

        where(:input_url, :output_query) do
          '/'                                      | {}
          '/?safe=1'                               | { 'safe' => '1' }
          '/?token=secret'                         | { 'token' => filtered }
          '/?TOKEN=secret'                         | { 'TOKEN' => filtered }
          '/?private_token=secret'                 | { 'private_token' => filtered }
          '/?PRIVATE_TOKEN=secret'                 | { 'PRIVATE_TOKEN' => filtered }
          '/?mixed=1&private_token=secret'         | { 'mixed' => '1', 'private_token' => filtered }
          '/?note=secret&noteable=1&prefix_note=2' | { 'note' => filtered, 'noteable' => '1', 'prefix_note' => '2' }
          '/?note[note]=secret&target_type=1'      | { 'note' => filtered, 'target_type' => '1' }
          '/?safe[note]=secret&target_type=1'      | { 'safe' => { 'note' => filtered }, 'target_type' => '1' }
          '/?safe[selectedText]=secret'            | { 'safe' => { 'selectedText' => filtered } }
          '/?selectedText=secret'                  | { 'selectedText' => filtered }
          '/?query=secret'                         | { 'query' => filtered }
        end

        with_them do
          it { expect(request_for_url(input_url).filtered_parameters).to eq(output_query) }
        end
      end
    end
  end

  describe 'clear_active_connections_again initializer' do
    subject(:clear_active_connections_again) do
      described_class.initializers.find { |i| i.name == :clear_active_connections_again }
    end

    it 'is included in list of Rails initializers' do
      expect(clear_active_connections_again).to be_present
    end

    it 'is configured after set_routes_reloader_hook' do
      expect(clear_active_connections_again.after).to eq(:set_routes_reloader_hook)
    end

    describe 'functionality', :reestablished_active_record_base do
      it 'clears all connections' do
        Project.first

        clear_active_connections_again.run

        expect(ActiveRecord::Base.connection_handler.active_connections?).to eq(false)
      end
    end
  end
end