File: middleware_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 (45 lines) | stat: -rw-r--r-- 1,091 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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Ci::JobToken::Middleware, feature_category: :secrets_management do
  using RSpec::Parameterized::TableSyntax

  describe '#call' do
    let(:middleware) { described_class.new(->(env) { env }) }
    let(:response_code) { 200 }
    let(:env) do
      [
        response_code,
        { 'Content-Type' => 'application/json' },
        { 'foo' => 'bar' }.to_json
      ]
    end

    it 'does not alter the response' do
      expect(middleware.call(env)).to eq(env)
    end

    where(:response_code, :schedule_log) do
      200 | true
      201 | true
      204 | true
      400 | false
      403 | false
      404 | false
      500 | false
    end

    with_them do
      it 'decides whether to schedule the authorization log based on the response code' do
        if schedule_log
          expect(Ci::JobToken::Authorization).to receive(:log_captures_async)
        else
          expect(Ci::JobToken::Authorization).not_to receive(:log_captures_async)
        end

        middleware.call(env)
      end
    end
  end
end