Commit f13afa2d authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'avoid_sed_i' of /home/git/repositories/gitlab/gitlab-shell

parents f31c38e8 4de0ee3b
require 'open3' require 'tempfile'
require_relative 'gitlab_config' require_relative 'gitlab_config'
require_relative 'gitlab_logger' require_relative 'gitlab_logger'
...@@ -36,9 +36,11 @@ class GitlabKeys ...@@ -36,9 +36,11 @@ class GitlabKeys
def rm_key def rm_key
$logger.info "Removing key #{@key_id}" $logger.info "Removing key #{@key_id}"
cmd = "sed -i '/shell #{@key_id}\"/d' #{auth_file}" Tempfile.open('authorized_keys') do |temp|
cmd = "sed '/shell #{@key_id}\"/d' #{auth_file} > #{temp.path} && mv #{temp.path} #{auth_file}"
system(cmd) system(cmd)
end end
end
def clear def clear
system("echo '# Managed by gitlab-shell' > #{auth_file}") system("echo '# Managed by gitlab-shell' > #{auth_file}")
......
...@@ -31,9 +31,12 @@ describe GitlabKeys do ...@@ -31,9 +31,12 @@ describe GitlabKeys do
describe :rm_key do describe :rm_key do
let(:gitlab_keys) { build_gitlab_keys('rm-key', 'key-741', 'ssh-rsa AAAAB3NzaDAxx2E') } let(:gitlab_keys) { build_gitlab_keys('rm-key', 'key-741', 'ssh-rsa AAAAB3NzaDAxx2E') }
let(:temp_file) { mock(:temp_file, path: 'tmp_path') }
before { Tempfile.should_receive(:open).and_yield(temp_file) }
it "should receive valid cmd" do it "should receive valid cmd" do
valid_cmd = "sed -i '/shell key-741\"/d' #{GitlabConfig.new.auth_file}" auth_file = GitlabConfig.new.auth_file
valid_cmd = "sed '/shell key-741\"/d' #{auth_file} > tmp_path && mv tmp_path #{auth_file}"
gitlab_keys.should_receive(:system).with(valid_cmd) gitlab_keys.should_receive(:system).with(valid_cmd)
gitlab_keys.send :rm_key gitlab_keys.send :rm_key
end end
......
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