summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dzaporozhets@gitlab.com>2015-03-16 17:52:57 +0000
committerDmitriy Zaporozhets <dzaporozhets@gitlab.com>2015-03-16 17:52:57 +0000
commitbc722a20289d2318db73513e2f7c16149c7e3e12 (patch)
tree3278cbabbbeed5a63c68b10cc6a2b0faa637a85e
parentf19eee9959bc89c6d9bbb4bf2e4b19158f5c7fd5 (diff)
parent7929e8bf4d21b55f4b500b012c5201f947635ddb (diff)
downloadgitlab-shell-bc722a20289d2318db73513e2f7c16149c7e3e12.tar.gz
Merge branch 'post-receive-base64' into 'master'
Prevent character encoding issues by sending received changes as raw data. Better alternative to !64 that doesn't require new gems and leaves dealing with string character encoding to gitlab-rails. See gitlab/gitlabhq!1701 for the corresponding changes there. Fixes: - https://github.com/gitlabhq/gitlabhq/issues/7486 - https://gitlab.com/gitlab-org/gitlab-ce/issues/858 - https://gitlab.com/gitlab-org/gitlab-ce/issues/877 - https://gitlab.com/gitlab-org/gitlab-ce/issues/965 See merge request !65
-rw-r--r--CHANGELOG3
-rw-r--r--VERSION2
-rw-r--r--lib/gitlab_post_receive.rb6
-rw-r--r--spec/gitlab_post_receive_spec.rb8
4 files changed, 14 insertions, 5 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 8269ed1..c0221ec 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,6 @@
+v2.5.5
+ - Prevent character encoding issues by sending received changes as raw data.
+
v2.5.4
- Remove recursive commands from bin/install
diff --git a/VERSION b/VERSION
index fe16b34..0cadbc1 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.5.4
+2.5.5
diff --git a/lib/gitlab_post_receive.rb b/lib/gitlab_post_receive.rb
index 1c9e8a6..3c601ee 100644
--- a/lib/gitlab_post_receive.rb
+++ b/lib/gitlab_post_receive.rb
@@ -1,6 +1,7 @@
require_relative 'gitlab_init'
require_relative 'gitlab_net'
require 'json'
+require 'base64'
class GitlabPostReceive
attr_reader :config, :repo_path, :changes
@@ -70,8 +71,11 @@ class GitlabPostReceive
end
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"
- 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,
err: '/dev/null', out: '/dev/null')
return true
diff --git a/spec/gitlab_post_receive_spec.rb b/spec/gitlab_post_receive_spec.rb
index fdb9e27..5a9892a 100644
--- a/spec/gitlab_post_receive_spec.rb
+++ b/spec/gitlab_post_receive_spec.rb
@@ -5,9 +5,11 @@ describe GitlabPostReceive do
let(:repository_path) { "/home/git/repositories" }
let(:repo_name) { 'dzaporozhets/gitlab-ci' }
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(: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 }
before do
@@ -56,7 +58,7 @@ describe GitlabPostReceive do
expect(gitlab_post_receive).to receive(:system).with(
*[
*%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" }
]
).and_return(true)