Commit 7929e8bf authored by Douwe Maan's avatar Douwe Maan

Prevent character encoding issues by sending received changes as raw data.

parent f19eee99
v2.5.5
- Prevent character encoding issues by sending received changes as raw data.
v2.5.4 v2.5.4
- Remove recursive commands from bin/install - Remove recursive commands from bin/install
......
require_relative 'gitlab_init' require_relative 'gitlab_init'
require_relative 'gitlab_net' require_relative 'gitlab_net'
require 'json' require 'json'
require 'base64'
class GitlabPostReceive class GitlabPostReceive
attr_reader :config, :repo_path, :changes attr_reader :config, :repo_path, :changes
...@@ -70,8 +71,11 @@ class GitlabPostReceive ...@@ -70,8 +71,11 @@ class GitlabPostReceive
end end
def update_redis def update_redis
# Encode changes as base64 so we don't run into trouble with non-UTF-8 input.
changes = Base64.encode64(@changes)
queue = "#{config.redis_namespace}:queue:post_receive" queue = "#{config.redis_namespace}:queue:post_receive"
msg = JSON.dump({ 'class' => 'PostReceive', 'args' => [@repo_path, @actor, @changes] }) msg = JSON.dump({ 'class' => 'PostReceive', 'args' => [@repo_path, @actor, changes] })
if system(*config.redis_command, 'rpush', queue, msg, if system(*config.redis_command, 'rpush', queue, msg,
err: '/dev/null', out: '/dev/null') err: '/dev/null', out: '/dev/null')
return true return true
......
...@@ -5,9 +5,11 @@ describe GitlabPostReceive do ...@@ -5,9 +5,11 @@ describe GitlabPostReceive do
let(:repository_path) { "/home/git/repositories" } let(:repository_path) { "/home/git/repositories" }
let(:repo_name) { 'dzaporozhets/gitlab-ci' } let(:repo_name) { 'dzaporozhets/gitlab-ci' }
let(:actor) { 'key-123' } let(:actor) { 'key-123' }
let(:changes) { 'wow' } let(:changes) { "123456 789012 refs/heads/tést\n654321 210987 refs/tags/tag" }
let(:wrongly_encoded_changes) { changes.encode("ISO-8859-1").force_encoding("UTF-8") }
let(:base64_changes) { Base64.encode64(wrongly_encoded_changes) }
let(:repo_path) { File.join(repository_path, repo_name) + ".git" } let(:repo_path) { File.join(repository_path, repo_name) + ".git" }
let(:gitlab_post_receive) { GitlabPostReceive.new(repo_path, actor, changes) } let(:gitlab_post_receive) { GitlabPostReceive.new(repo_path, actor, wrongly_encoded_changes) }
let(:message) { "test " * 10 + "message " * 10 } let(:message) { "test " * 10 + "message " * 10 }
before do before do
...@@ -56,7 +58,7 @@ describe GitlabPostReceive do ...@@ -56,7 +58,7 @@ describe GitlabPostReceive do
expect(gitlab_post_receive).to receive(:system).with( expect(gitlab_post_receive).to receive(:system).with(
*[ *[
*%w(env -i redis-cli rpush resque:gitlab:queue:post_receive), *%w(env -i redis-cli rpush resque:gitlab:queue:post_receive),
%Q/{"class":"PostReceive","args":["#{repo_path}","#{actor}","#{changes}"]}/, %Q/{"class":"PostReceive","args":["#{repo_path}","#{actor}",#{base64_changes.inspect}]}/,
{ err: "/dev/null", out: "/dev/null" } { err: "/dev/null", out: "/dev/null" }
] ]
).and_return(true) ).and_return(true)
......
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