Commit 670b2c1a authored by Nick Thomas's avatar Nick Thomas

JSON-encoded binary fields should use Base64::encode64

It is not interoperable to use Base64::urlsafe_encode64 for fields in
JSON that contain binary (as opposed to UTF8-safe) data. For instance,
the Golang JSON decoder (which is what gitlab-workhorse uses) insists
upon the standard base64 encoding.
parent 2845e8d9
...@@ -229,12 +229,17 @@ module Gitlab ...@@ -229,12 +229,17 @@ module Gitlab
protected protected
# This is the outermost encoding of a senddata: header. It is safe for
# inclusion in HTTP response headers
def encode(hash) def encode(hash)
Base64.urlsafe_encode64(JSON.dump(hash)) Base64.urlsafe_encode64(JSON.dump(hash))
end end
# This is for encoding individual fields inside the senddata JSON that
# contain binary data. In workhorse, the corresponding struct field should
# be type []byte
def encode_binary(binary) def encode_binary(binary)
Base64.urlsafe_encode64(binary) Base64.encode64(binary)
end end
def gitaly_server_hash(repository) def gitaly_server_hash(repository)
......
...@@ -39,7 +39,7 @@ describe Gitlab::Workhorse do ...@@ -39,7 +39,7 @@ describe Gitlab::Workhorse do
token: Gitlab::GitalyClient.token(project.repository_storage) token: Gitlab::GitalyClient.token(project.repository_storage)
}, },
'ArchivePath' => metadata['ArchivePath'], 'ArchivePath' => metadata['ArchivePath'],
'GetArchiveRequest' => Base64.urlsafe_encode64( 'GetArchiveRequest' => Base64.encode64(
Gitaly::GetArchiveRequest.new( Gitaly::GetArchiveRequest.new(
repository: repository.gitaly_repository, repository: repository.gitaly_repository,
commit_id: metadata['CommitId'], commit_id: metadata['CommitId'],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment