summaryrefslogtreecommitdiff
path: root/lib/gitlab/git
diff options
context:
space:
mode:
authorTimothy Andrew <mail@timothyandrew.net>2016-12-09 15:15:55 +0530
committerTimothy Andrew <mail@timothyandrew.net>2016-12-16 23:32:25 +0530
commita2b39feb1a3ae6fe2615418bb759bf39125e5d0e (patch)
tree0d4cfeadd4c01a9593c4487a5f3da32436edaaa8 /lib/gitlab/git
parentf82d549d26af89cba00005e1a1c9b721c076f7a0 (diff)
downloadgitlab-ce-a2b39feb1a3ae6fe2615418bb759bf39125e5d0e.tar.gz
Validate environment variables in `Gitlab::Git::RevList`
The list of environment variables in `Gitlab::Git::RevList` need to be validate to make sure that they don't reference any other project on disk. This commit mixes in `ActiveModel::Validations` into `Gitlab::Git::RevList`, and validates that the environment variables are on the level (using a custom validator class). If the validations fail, the force push is still executed without any environment variables set. Add specs for the validation using shared examples.
Diffstat (limited to 'lib/gitlab/git')
-rw-r--r--lib/gitlab/git/rev_list.rb16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/gitlab/git/rev_list.rb b/lib/gitlab/git/rev_list.rb
index ecdb7f07744..d8c78d806ea 100644
--- a/lib/gitlab/git/rev_list.rb
+++ b/lib/gitlab/git/rev_list.rb
@@ -3,19 +3,29 @@
module Gitlab
module Git
class RevList
+ include ActiveModel::Validations
+
+ validates :env, git_environment_variables: true
+
+ attr_reader :project, :env
+
def initialize(oldrev, newrev, project:, env: nil)
+ @project = project
+ @env = env.presence || {}
@args = [Gitlab.config.git.bin_path,
"--git-dir=#{project.repository.path_to_repo}",
"rev-list",
"--max-count=1",
oldrev,
"^#{newrev}"]
-
- @env = env.slice(*allowed_environment_variables)
end
def execute
- Gitlab::Popen.popen(@args, nil, @env.slice(*allowed_environment_variables))
+ if self.valid?
+ Gitlab::Popen.popen(@args, nil, @env.slice(*allowed_environment_variables))
+ else
+ Gitlab::Popen.popen(@args)
+ end
end
private