Allow trailing newline in secret base64 data
This commit is contained in:
parent
82b8cc5d66
commit
11f54caada
2 changed files with 6 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue