diff options
Diffstat (limited to 'spec/lib/gitlab/hash_digest')
-rw-r--r-- | spec/lib/gitlab/hash_digest/facade_spec.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/spec/lib/gitlab/hash_digest/facade_spec.rb b/spec/lib/gitlab/hash_digest/facade_spec.rb new file mode 100644 index 00000000000..b352744513e --- /dev/null +++ b/spec/lib/gitlab/hash_digest/facade_spec.rb @@ -0,0 +1,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 |