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

auth_token_service_spec.rb « dependency_proxy « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4b96f9d75a91d98bf5e14c41b289ce11555dc54a (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
# frozen_string_literal: true
require 'spec_helper'

RSpec.describe DependencyProxy::AuthTokenService do
  include DependencyProxyHelpers

  describe '.decoded_token_payload' do
    let_it_be(:user) { create(:user) }
    let_it_be(:token) { build_jwt(user) }

    subject { described_class.decoded_token_payload(token.encoded) }

    it 'returns the user' do
      result = subject

      expect(result['user_id']).to eq(user.id)
    end

    it 'raises an error if the token is expired' do
      travel_to(Time.zone.now + Auth::DependencyProxyAuthenticationService.token_expire_at + 1.minute) do
        expect { subject }.to raise_error(JWT::ExpiredSignature)
      end
    end

    it 'raises an error if decoding fails' do
      allow(JWT).to receive(:decode).and_raise(JWT::DecodeError)

      expect { subject }.to raise_error(JWT::DecodeError)
    end

    it 'raises an error if signature is immature' do
      allow(JWT).to receive(:decode).and_raise(JWT::ImmatureSignature)

      expect { subject }.to raise_error(JWT::ImmatureSignature)
    end
  end
end