summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/utils_spec.rb
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-11-22 15:35:49 +0100
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-11-22 15:35:49 +0100
commit777b6713bb473d2e09c8340ab9a96373fdbaae50 (patch)
tree786e78f65c73daef684150844a9aa6054dfdb2d3 /spec/lib/gitlab/utils_spec.rb
parent8a235c0c05efec1c8ee14c7454982dc2b8ca9464 (diff)
downloadgitlab-ce-777b6713bb473d2e09c8340ab9a96373fdbaae50.tar.gz
Ensure that db encryption keys have proper bytesize
Diffstat (limited to 'spec/lib/gitlab/utils_spec.rb')
-rw-r--r--spec/lib/gitlab/utils_spec.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/spec/lib/gitlab/utils_spec.rb b/spec/lib/gitlab/utils_spec.rb
index ad2c9d7f2af..9927ad41108 100644
--- a/spec/lib/gitlab/utils_spec.rb
+++ b/spec/lib/gitlab/utils_spec.rb
@@ -127,4 +127,42 @@ describe Gitlab::Utils do
end
end
end
+
+ describe '.ensure_utf8_size' do
+ context 'string is has less bytes than expected' do
+ it 'backfills string with null characters' do
+ transformed = described_class.ensure_utf8_size('a' * 10, bytes: 32)
+
+ expect(transformed.bytesize).to eq 32
+ expect(transformed).to eq ('a' * 10) + ("\0" * 22)
+ end
+ end
+
+ context 'string size is exactly the one that is expected' do
+ it 'returns original value' do
+ transformed = described_class.ensure_utf8_size('a' * 32, bytes: 32)
+
+ expect(transformed).to eq 'a' * 32
+ expect(transformed.bytesize).to eq 32
+ end
+ end
+
+ context 'when string contains a few multi-byte UTF characters' do
+ it 'backfills string with null characters' do
+ transformed = described_class.ensure_utf8_size('❤' * 6, bytes: 32)
+
+ expect(transformed).to eq '❤❤❤❤❤❤' + ("\0" * 14)
+ expect(transformed.bytesize).to eq 32
+ end
+ end
+
+ context 'when string has multiple multi-byte UTF chars exceeding 32 bytes' do
+ it 'truncates string to 32 characters and backfills it if needed' do
+ transformed = described_class.ensure_utf8_size('❤' * 18, bytes: 32)
+
+ expect(transformed).to eq ('❤' * 10) + ("\0" * 2)
+ expect(transformed.bytesize).to eq 32
+ end
+ end
+ end
end