Skip to content

Add git_ssl_no_verify option to disable SSL verification for HTTPS repos #420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ Git env config

# If you need to use a custom SSH script
config.git_ssh = '/path/to/ssh/script'

# If you need to ignore SSL verification
config.git_ssl_no_verify = true
end

```
Expand Down
8 changes: 7 additions & 1 deletion lib/git/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ module Git

class Config

attr_writer :binary_path, :git_ssh
attr_writer :binary_path, :git_ssh, :git_ssl_no_verify

def initialize
@binary_path = nil
@git_ssh = nil
@git_ssl_no_verify = nil
end

def binary_path
Expand All @@ -17,6 +18,11 @@ def git_ssh
@git_ssh || ENV['GIT_SSH']
end

def git_ssl_no_verify
return 'true' if @git_ssl_no_verify
ENV['GIT_SSL_NO_VERIFY']
end

end

end
3 changes: 2 additions & 1 deletion lib/git/lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ def meets_required_version?
# Systen ENV variables involved in the git commands.
#
# @return [<String>] the names of the EVN variables involved in the git commands
ENV_VARIABLE_NAMES = ['GIT_DIR', 'GIT_WORK_TREE', 'GIT_INDEX_FILE', 'GIT_SSH']
ENV_VARIABLE_NAMES = %w(GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE GIT_SSH GIT_SSL_NO_VERIFY)

def command_lines(cmd, opts = [], chdir = true, redirect = '')
cmd_op = command(cmd, opts, chdir)
Expand Down Expand Up @@ -933,6 +933,7 @@ def set_custom_git_env_variables
ENV['GIT_WORK_TREE'] = @git_work_dir
ENV['GIT_INDEX_FILE'] = @git_index_file
ENV['GIT_SSH'] = Git::Base.config.git_ssh
ENV['GIT_SSL_NO_VERIFY'] = Git::Base.config.git_ssl_no_verify
end

# Runs a block inside an environment with customized ENV variables.
Expand Down
3 changes: 3 additions & 0 deletions tests/units/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ def test_env_config
Git.configure do |config|
config.binary_path = '/usr/bin/git'
config.git_ssh = '/path/to/ssh/script'
config.git_ssl_no_verify = true
end

assert_equal(Git::Base.config.git_ssh, '/path/to/ssh/script')
assert_equal(Git::Base.config.git_ssl_no_verify, 'true')

@git.log
ensure
Expand All @@ -50,6 +52,7 @@ def test_env_config
Git.configure do |config|
config.binary_path = nil
config.git_ssh = nil
config.git_ssl_no_verify = nil
end
end
end
Expand Down
18 changes: 18 additions & 0 deletions tests/units/test_lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@ def test_environment_reset
ENV['GIT_DIR'] = '/my/git/dir'
ENV['GIT_WORK_TREE'] = '/my/work/tree'
ENV['GIT_INDEX_FILE'] = 'my_index'
ENV['GIT_SSL_NO_VERIFY'] = 'true'

@lib.log_commits :count => 10

assert_equal(ENV['GIT_DIR'], '/my/git/dir')
assert_equal(ENV['GIT_WORK_TREE'], '/my/work/tree')
assert_equal(ENV['GIT_INDEX_FILE'],'my_index')
assert_equal(ENV['GIT_SSL_NO_VERIFY'], 'true')
end
end

Expand Down Expand Up @@ -115,6 +117,22 @@ def test_git_ssh_from_environment_is_passed_to_binary
end
end

def test_git_ssl_no_verify
with_custom_env_variables do
begin
ENV['GIT_SSL_NO_VERIFY'] = 'false'
assert_equal(Git::Base.config.git_ssl_no_verify, 'false')

Git::Base.config.git_ssl_no_verify = true
assert_equal(Git::Base.config.git_ssl_no_verify, 'true')
ensure
Git.configure do |config|
config.git_ssl_no_verify = nil
end
end
end
end

def test_revparse
assert_equal('1cc8667014381e2788a94777532a788307f38d26', @lib.revparse('1cc8667014381')) # commit
assert_equal('94c827875e2cadb8bc8d4cdd900f19aa9e8634c7', @lib.revparse('1cc8667014381^{tree}')) #tree
Expand Down