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: d8a3c98e5757e5f143b81ad3e8f2cb26456bf489 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# 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` is a variable' do
    it 'is valid' do
      config = { aud: '$WATHEVER' }
      id_token = described_class.new(config)

      id_token.compose!

      expect(id_token).to be_valid
    end
  end

  context 'when given `aud` includes a variable' do
    it 'is valid' do
      config = { aud: 'blah-$WATHEVER' }
      id_token = described_class.new(config)

      id_token.compose!

      expect(id_token).to be_valid
    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 given `aud` as an array with variables' do
    it 'is valid and concatenates the values' do
      config = { aud: ['$WATHEVER', 'blah-$WATHEVER'] }
      id_token = described_class.new(config)

      id_token.compose!

      expect(id_token).to be_valid
    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