summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2016-09-13 19:45:02 +0200
committerJacob Vosmaer <jacob@gitlab.com>2016-09-13 19:45:02 +0200
commit11f54caada4baaf8fb179213b1a93aa1a047f9b3 (patch)
treec032e130a73cdafbf10f5c07d2b1358fca82e7b5
parent82b8cc5d66655605091b1fa089b6a3e946bd536d (diff)
downloadgitlab-ce-11f54caada4baaf8fb179213b1a93aa1a047f9b3.tar.gz
Allow trailing newline in secret base64 data
-rw-r--r--lib/gitlab/workhorse.rb2
-rw-r--r--spec/lib/gitlab/workhorse_spec.rb5
2 files changed, 6 insertions, 1 deletions
diff --git a/lib/gitlab/workhorse.rb b/lib/gitlab/workhorse.rb
index efe4aeb399d..60aae541d46 100644
--- a/lib/gitlab/workhorse.rb
+++ b/lib/gitlab/workhorse.rb
@@ -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
diff --git a/spec/lib/gitlab/workhorse_spec.rb b/spec/lib/gitlab/workhorse_spec.rb
index 395192149a9..6c7fa7e7c15 100644
--- a/spec/lib/gitlab/workhorse_spec.rb
+++ b/spec/lib/gitlab/workhorse_spec.rb
@@ -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)