Commit 559196cb authored by Jacob Vosmaer's avatar Jacob Vosmaer

Fix return values in GitlabKeys

parent c67395e9
...@@ -31,6 +31,7 @@ class GitlabKeys ...@@ -31,6 +31,7 @@ class GitlabKeys
$logger.info "Adding key #{@key_id} => #{@key.inspect}" $logger.info "Adding key #{@key_id} => #{@key.inspect}"
auth_line = "command=\"#{ROOT_PATH}/bin/gitlab-shell #{@key_id}\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty #{@key}" auth_line = "command=\"#{ROOT_PATH}/bin/gitlab-shell #{@key_id}\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty #{@key}"
open(auth_file, 'a') { |file| file.puts(auth_line) } open(auth_file, 'a') { |file| file.puts(auth_line) }
true
end end
def rm_key def rm_key
...@@ -44,9 +45,11 @@ class GitlabKeys ...@@ -44,9 +45,11 @@ class GitlabKeys
temp.close temp.close
FileUtils.cp(temp.path, auth_file) FileUtils.cp(temp.path, auth_file)
end end
true
end end
def clear def clear
open(auth_file, 'w') { |file| file.puts '# Managed by gitlab-shell' } open(auth_file, 'w') { |file| file.puts '# Managed by gitlab-shell' }
true
end end
end end
...@@ -25,10 +25,17 @@ describe GitlabKeys do ...@@ -25,10 +25,17 @@ describe GitlabKeys do
File.read(tmp_authorized_keys_path).should == "existing content\n#{auth_line}\n" File.read(tmp_authorized_keys_path).should == "existing content\n#{auth_line}\n"
end end
it "should log an add-key event" do context "without file writing" do
$logger.should_receive(:info).with('Adding key key-741 => "ssh-rsa AAAAB3NzaDAxx2E"') before { gitlab_keys.stub(:open) }
gitlab_keys.stub(:open)
gitlab_keys.send :add_key it "should log an add-key event" do
$logger.should_receive(:info).with('Adding key key-741 => "ssh-rsa AAAAB3NzaDAxx2E"')
gitlab_keys.send :add_key
end
it "should return true" do
gitlab_keys.send(:add_key).should be_true
end
end end
end end
...@@ -50,6 +57,18 @@ describe GitlabKeys do ...@@ -50,6 +57,18 @@ describe GitlabKeys do
$logger.should_receive(:info).with('Removing key key-741') $logger.should_receive(:info).with('Removing key key-741')
gitlab_keys.send :rm_key gitlab_keys.send :rm_key
end end
it "should return true" do
gitlab_keys.send(:rm_key).should be_true
end
end
describe :clear do
let(:gitlab_keys) { build_gitlab_keys('clear') }
it "should return true" do
gitlab_keys.send(:clear).should be_true
end
end end
describe :exec do describe :exec 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