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

facade_spec.rb « hash_digest « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b352744513e93e13c08a49305a7c76ef9ea7ad49 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::HashDigest::Facade do
  describe '.hexdigest' do
    let(:plaintext) { 'something that is plaintext' }

    let(:sha256_hash) { OpenSSL::Digest::SHA256.hexdigest(plaintext) }
    let(:md5_hash) { Digest::MD5.hexdigest(plaintext) } # rubocop:disable Fips/MD5

    it 'uses SHA256' do
      expect(described_class.hexdigest(plaintext)).to eq(sha256_hash)
    end

    context 'when feature flags is not available' do
      before do
        allow(Feature).to receive(:feature_flags_available?).and_return(false)
      end

      it 'uses MD5' do
        expect(described_class.hexdigest(plaintext)).to eq(md5_hash)
      end
    end

    context 'when active_support_hash_digest_sha256 FF is disabled' do
      before do
        stub_feature_flags(active_support_hash_digest_sha256: false)
      end

      it 'uses MD5' do
        expect(described_class.hexdigest(plaintext)).to eq(md5_hash)
      end
    end
  end
end