summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/terraform_registry_token_spec.rb
blob: 49c1c07e942193ffcb5ff183a0429395fbe82a89 (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
# frozen_string_literal: true
require 'spec_helper'

RSpec.describe Gitlab::TerraformRegistryToken do
  let_it_be(:user) { create(:user) }

  describe '.from_token' do
    let(:jwt_token) { described_class.from_token(token) }

    subject { described_class.decode(jwt_token.encoded) }

    context 'with a deploy token' do
      let(:deploy_token) { create(:deploy_token, username: 'deployer') }
      let(:token) { deploy_token }

      it 'returns the correct token' do
        expect(subject['token']).to eq jwt_token['token']
      end
    end

    context 'with a job' do
      let_it_be(:job) { create(:ci_build) }

      let(:token) { job }

      it 'returns the correct token' do
        expect(subject['token']).to eq jwt_token['token']
      end
    end

    context 'with a personal access token' do
      let(:token) { create(:personal_access_token) }

      it 'returns the correct token' do
        expect(subject['token']).to eq jwt_token['token']
      end
    end
  end

  it_behaves_like 'a gitlab jwt token'
end