diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-11-21 13:44:19 +0100 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-11-21 14:02:17 +0100 |
commit | 13cfd53dd982bcbcda53d5eb5899c3efc6e92654 (patch) | |
tree | ea328196d196dee3d68f6d23877c4ff99e3b6012 /spec/lib | |
parent | c7a39ffa911f06ae60cc22ac237b6e82522a93b8 (diff) | |
download | gitlab-ce-13cfd53dd982bcbcda53d5eb5899c3efc6e92654.tar.gz |
Add missing specs for crypto helper class
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/crypto_helper_spec.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/spec/lib/gitlab/crypto_helper_spec.rb b/spec/lib/gitlab/crypto_helper_spec.rb new file mode 100644 index 00000000000..080d865b615 --- /dev/null +++ b/spec/lib/gitlab/crypto_helper_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper' + +describe Gitlab::CryptoHelper do + describe '.sha256' do + it 'generates SHA256 digest Base46 encoded' do + digest = described_class.sha256('some-value') + + expect(digest).to match %r{^[A-Za-z0-9+/=]+$} + expect(digest).to eq digest.strip + end + end + + describe '.aes256_gcm_encrypt' do + it 'is Base64 encoded string without new line character' do + encrypted = described_class.aes256_gcm_encrypt('some-value') + + expect(encrypted).to match %r{^[A-Za-z0-9+/=]+$} + expect(encrypted).to eq encrypted.strip + end + end + + describe '.aes256_gcm_decrypt' do + let(:encrypted) { described_class.aes256_gcm_encrypt('some-value') } + + it 'correctly decrypts encrypted string' do + decrypted = described_class.aes256_gcm_decrypt(encrypted) + + expect(decrypted).to eq 'some-value' + end + + it 'decrypts a value when it ends with a new line character' do + decrypted = described_class.aes256_gcm_decrypt(encrypted + "\n") + + expect(decrypted).to eq 'some-value' + end + end +end |