Allow trailing newline in secret base64 data

This commit is contained in:
Jacob Vosmaer 2016-09-13 19:45:02 +02:00
parent 82b8cc5d66
commit 11f54caada
2 changed files with 6 additions and 1 deletions

View File

@ -102,7 +102,7 @@ module Gitlab
def secret
@secret ||= begin
bytes = Base64.strict_decode64(File.read(secret_path))
bytes = Base64.strict_decode64(File.read(secret_path).chomp)
raise "#{secret_path} does not contain #{SECRET_LENGTH} bytes" if bytes.length != SECRET_LENGTH
bytes
end

View File

@ -30,6 +30,11 @@ describe Gitlab::Workhorse, lib: true do
expect(subject.encoding).to eq(Encoding::ASCII_8BIT)
end
it 'accepts a trailing newline' do
open(described_class.secret_path, 'a') { |f| f.write "\n" }
expect(subject.length).to eq(32)
end
it 'raises an exception if the secret file cannot be read' do
File.delete(described_class.secret_path)
expect { subject }.to raise_exception(Errno::ENOENT)