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

encryption_helper_spec.rb « token_authenticatable_strategies « concerns « models « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6f322a32a3b148d351764d752c67b597db4b1a2f (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe TokenAuthenticatableStrategies::EncryptionHelper do
  let(:encrypted_token) { described_class.encrypt_token('my-value') }

  describe '.encrypt_token' do
    it 'encrypts token' do
      expect(encrypted_token).not_to eq('my-value')
    end
  end

  describe '.decrypt_token' do
    it 'decrypts token with static iv' do
      expect(described_class.decrypt_token(encrypted_token)).to eq('my-value')
    end

    it 'decrypts token with dynamic iv' do
      iv = ::Digest::SHA256.hexdigest('my-value').bytes.take(described_class::NONCE_SIZE).pack('c*')
      token = Gitlab::CryptoHelper.aes256_gcm_encrypt('my-value', nonce: iv)
      encrypted_token = "#{described_class::DYNAMIC_NONCE_IDENTIFIER}#{token}#{iv}"

      expect(described_class.decrypt_token(encrypted_token)).to eq('my-value')
    end
  end
end