Welcome to mirror list, hosted at ThFree Co, Russian Federation.

admin_mode_middleware_spec.rb « api_guard « api « requests « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 63bcec4b52a7976eedb7fb84198f12d04aa735cf (plain)
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe API::APIGuard::AdminModeMiddleware, :request_store do
  let(:user) { create(:admin) }

  it 'is loaded' do
    expect(API::API.middleware).to include([:use, described_class])
  end

  context 'when there is an exception in the api call' do
    let(:app) do
      Class.new(API::API) do
        get 'willfail' do
          raise StandardError.new('oh noes!')
        end
      end
    end

    it 'resets admin mode' do
      Gitlab::Auth::CurrentUserMode.bypass_session!(user.id)

      expect(Gitlab::Auth::CurrentUserMode.bypass_session_admin_id).to be(user.id)
      expect(Gitlab::Auth::CurrentUserMode).to receive(:reset_bypass_session!).and_call_original

      get api('/willfail')

      expect(response).to have_gitlab_http_status(:internal_server_error)
      expect(response.body).to include('oh noes!')

      expect(Gitlab::Auth::CurrentUserMode.bypass_session_admin_id).to be_nil
    end
  end
end