Commit d64ddc87 authored by François Bobot's avatar François Bobot

Execute command directly without using shell

   use Shellwords.shellwords for splitting origin_cmd instead of .split(' ')
parent 2c238b71
require 'open3' require 'open3'
require 'shellwords'
require_relative 'gitlab_net' require_relative 'gitlab_net'
...@@ -40,9 +41,9 @@ class GitlabShell ...@@ -40,9 +41,9 @@ class GitlabShell
protected protected
def parse_cmd def parse_cmd
args = @origin_cmd.split(' ') args = Shellwords.shellwords(@origin_cmd)
@git_cmd = args.shift @git_cmd = args[0]
@repo_name = args.shift @repo_name = args[1]
end end
def git_cmds def git_cmds
...@@ -51,17 +52,16 @@ class GitlabShell ...@@ -51,17 +52,16 @@ class GitlabShell
def process_cmd def process_cmd
repo_full_path = File.join(repos_path, repo_name) repo_full_path = File.join(repos_path, repo_name)
cmd = "#{@git_cmd} #{repo_full_path}" $logger.info "gitlab-shell: executing git command <#{@git_cmd} #{repo_full_path}> for #{log_username}."
$logger.info "gitlab-shell: executing git command <#{cmd}> for #{log_username}." exec_cmd(@git_cmd,repo_full_path)
exec_cmd(cmd)
end end
def validate_access def validate_access
api.allowed?(@git_cmd, @repo_name, @key_id, '_any') api.allowed?(@git_cmd, @repo_name, @key_id, '_any')
end end
def exec_cmd args def exec_cmd *args
Kernel::exec args Kernel::exec *args
end end
def api def api
......
...@@ -60,7 +60,7 @@ describe GitlabShell do ...@@ -60,7 +60,7 @@ describe GitlabShell do
end end
it "should execute the command" do it "should execute the command" do
subject.should_receive(:exec_cmd).with("git-upload-pack #{File.join(repository_path, 'gitlab-ci.git')}") subject.should_receive(:exec_cmd).with("git-upload-pack", File.join(repository_path, 'gitlab-ci.git'))
end end
it "should set the GL_ID environment variable" do it "should set the GL_ID environment variable" do
...@@ -89,7 +89,7 @@ describe GitlabShell do ...@@ -89,7 +89,7 @@ describe GitlabShell do
end end
it "should execute the command" do it "should execute the command" do
subject.should_receive(:exec_cmd).with("git-receive-pack #{File.join(repository_path, 'gitlab-ci.git')}") subject.should_receive(:exec_cmd).with("git-receive-pack", File.join(repository_path, 'gitlab-ci.git'))
end end
it "should log the command execution" do it "should log the command execution" do
......
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