summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/grape_logging/loggers/token_logger_spec.rb
blob: d2022a28a9023020eb5f75882d198fa51bcfffbf (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::GrapeLogging::Loggers::TokenLogger do
  subject { described_class.new }

  describe ".parameters" do
    let(:token_id) { 1 }
    let(:token_type) { "PersonalAccessToken" }

    describe 'when no token information is available' do
      let(:mock_request) { instance_double(ActionDispatch::Request, 'env', env: {}) }

      it 'returns an empty hash' do
        expect(subject.parameters(mock_request, nil)).to eq({})
      end
    end

    describe 'when token information is available' do
      let(:mock_request) do
        instance_double(ActionDispatch::Request, 'env',
          env: {
            'gitlab.api.token' => { 'token_id': token_id, 'token_type': token_type }
          }
        )
      end

      it 'adds the token information to log parameters' do
        expect(subject.parameters(mock_request, nil)).to eq( { 'token_id': 1, 'token_type': "PersonalAccessToken" })
      end
    end
  end
end