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

id_token_spec.rb « entry « config « ci « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 12585d662ec515cce7556a82d3c3730205757769 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Ci::Config::Entry::IdToken do
  context 'when given `aud` as a string' do
    it 'is valid' do
      config = { aud: 'https://gitlab.com' }
      id_token = described_class.new(config)

      id_token.compose!

      expect(id_token).to be_valid
      expect(id_token.value).to eq(aud: 'https://gitlab.com')
    end
  end

  context 'when given `aud` as an array' do
    it 'is valid and concatenates the values' do
      config = { aud: ['https://gitlab.com', 'https://aws.com'] }
      id_token = described_class.new(config)

      id_token.compose!

      expect(id_token).to be_valid
      expect(id_token.value).to eq(aud: ['https://gitlab.com', 'https://aws.com'])
    end
  end

  context 'when not given an `aud`' do
    it 'is invalid' do
      config = {}
      id_token = described_class.new(config)

      id_token.compose!

      expect(id_token).not_to be_valid
      expect(id_token.errors).to match_array([
                                               'id token config missing required keys: aud',
                                               'id token aud should be an array of strings or a string'
                                             ])
    end
  end

  context 'when given an unknown keyword' do
    it 'is invalid' do
      config = { aud: 'https://gitlab.com', unknown: 'test' }
      id_token = described_class.new(config)

      id_token.compose!

      expect(id_token).not_to be_valid
      expect(id_token.errors).to match_array([
                                               'id token config contains unknown keys: unknown'
                                             ])
    end
  end
end