diff options
author | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2014-03-13 18:03:39 +0100 |
---|---|---|
committer | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2014-03-14 11:53:41 +0100 |
commit | 3a48eae79eafe1d3641b0aa4271b83b348a95ee6 (patch) | |
tree | 398d32db7a41036c088e44bcad387692f294f74f /spec/gitlab_keys_spec.rb | |
parent | bde689a8d326db46a79444143e35abfd6a47c419 (diff) | |
download | gitlab-shell-3a48eae79eafe1d3641b0aa4271b83b348a95ee6.tar.gz |
Add gitlab-keys batch-add-keys
This command is intended to be called by the GitLab Rails code when
restoring an application backup.
Diffstat (limited to 'spec/gitlab_keys_spec.rb')
-rw-r--r-- | spec/gitlab_keys_spec.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/gitlab_keys_spec.rb b/spec/gitlab_keys_spec.rb index e86874a..5bf4c04 100644 --- a/spec/gitlab_keys_spec.rb +++ b/spec/gitlab_keys_spec.rb @@ -1,5 +1,6 @@ require_relative 'spec_helper' require_relative '../lib/gitlab_keys' +require 'stringio' describe GitlabKeys do before do @@ -39,6 +40,47 @@ describe GitlabKeys do end end + describe :batch_add_keys do + let(:gitlab_keys) { build_gitlab_keys('batch-add-keys') } + let(:fake_stdin) { StringIO.new("key-12\tssh-dsa ASDFASGADG\nkey-123\tssh-rsa GFDGDFSGSDFG\n", 'r') } + before do + create_authorized_keys_fixture + gitlab_keys.stub(stdin: fake_stdin) + end + + it "adds lines at the end of the file" do + gitlab_keys.send :batch_add_keys + auth_line1 = "command=\"#{ROOT_PATH}/bin/gitlab-shell key-12\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-dsa ASDFASGADG" + auth_line2 = "command=\"#{ROOT_PATH}/bin/gitlab-shell key-123\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa GFDGDFSGSDFG" + File.read(tmp_authorized_keys_path).should == "existing content\n#{auth_line1}\n#{auth_line2}\n" + end + + context "with invalid input" do + let(:fake_stdin) { StringIO.new("key-12\tssh-dsa ASDFASGADG\nkey-123\tssh-rsa GFDGDFSGSDFG\nfoo\tbar\tbaz\n", 'r') } + + it "aborts" do + gitlab_keys.should_receive(:abort) + gitlab_keys.send :batch_add_keys + end + end + + context "without file writing" do + before do + gitlab_keys.should_receive(:open).and_yield(mock(:file, puts: nil)) + end + + it "should log an add-key event" do + $logger.should_receive(:info).with('Adding key key-12 => "ssh-dsa ASDFASGADG"') + $logger.should_receive(:info).with('Adding key key-123 => "ssh-rsa GFDGDFSGSDFG"') + gitlab_keys.send :batch_add_keys + end + + it "should return true" do + gitlab_keys.send(:batch_add_keys).should be_true + end + end + end + describe :rm_key do let(:gitlab_keys) { build_gitlab_keys('rm-key', 'key-741', 'ssh-rsa AAAAB3NzaDAxx2E') } |