blob: 21fd7e3adcfb7d6376e1a29fe0efae88d855eadf (
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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Ci::JwtV2 do
let(:namespace) { build_stubbed(:namespace) }
let(:project) { build_stubbed(:project, namespace: namespace) }
let(:user) do
build_stubbed(
:user,
identities: [build_stubbed(:identity, extern_uid: '1', provider: 'github')]
)
end
let(:pipeline) { build_stubbed(:ci_pipeline, ref: 'auto-deploy-2020-03-19') }
let(:aud) { described_class::DEFAULT_AUD }
let(:build) do
build_stubbed(
:ci_build,
project: project,
user: user,
pipeline: pipeline
)
end
subject(:ci_job_jwt_v2) { described_class.new(build, ttl: 30, aud: aud) }
it { is_expected.to be_a Gitlab::Ci::Jwt }
describe '#payload' do
subject(:payload) { ci_job_jwt_v2.payload }
it 'has correct values for the standard JWT attributes' do
aggregate_failures do
expect(payload[:iss]).to eq(Settings.gitlab.base_url)
expect(payload[:aud]).to eq(Settings.gitlab.base_url)
expect(payload[:sub]).to eq("project_path:#{project.full_path}:ref_type:branch:ref:#{pipeline.source_ref}")
end
end
it 'includes user identities when enabled' do
expect(user).to receive(:pass_user_identities_to_ci_jwt).and_return(true)
identities = payload[:user_identities].map { |identity| identity.slice(:extern_uid, :provider) }
expect(identities).to eq([{ extern_uid: '1', provider: 'github' }])
end
it 'does not include user identities when disabled' do
expect(user).to receive(:pass_user_identities_to_ci_jwt).and_return(false)
expect(payload).not_to include(:user_identities)
end
context 'when given an aud' do
let(:aud) { 'AWS' }
it 'uses that aud in the payload' do
expect(payload[:aud]).to eq('AWS')
end
end
end
end
|