summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-02-05 10:16:14 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-02-05 10:16:14 +0200
commit2b01b84f8d0cf469bdd3b031b1658db6fd8c0f52 (patch)
tree921bceed956d5e13ba805a3c1f3c315ce3ec402a
parentea6ea902bea6857d2a0dbdf6d5492105a527d276 (diff)
downloadgitlab-shell-2b01b84f8d0cf469bdd3b031b1658db6fd8c0f52.tar.gz
gitlab-keys with tests
-rwxr-xr-xbin/gitlab-keys1
-rw-r--r--spec/gitlab_keys_spec.rb47
-rw-r--r--spec/gitlab_shell_spec.rb1
3 files changed, 48 insertions, 1 deletions
diff --git a/bin/gitlab-keys b/bin/gitlab-keys
index 6a297c4..dc3876b 100755
--- a/bin/gitlab-keys
+++ b/bin/gitlab-keys
@@ -6,6 +6,7 @@
# Ex.
# /bin/gitlab-keys add-key dzaporozhets "ssh-rsa AAAAx321..."
#
+# /bin/gitlab-keys rm-key dzaporozhets "ssh-rsa AAAAx321..."
#
ROOT_PATH = File.join(File.expand_path(File.dirname(__FILE__)), "..")
require File.join(ROOT_PATH, 'lib', 'gitlab_keys')
diff --git a/spec/gitlab_keys_spec.rb b/spec/gitlab_keys_spec.rb
new file mode 100644
index 0000000..620b7b9
--- /dev/null
+++ b/spec/gitlab_keys_spec.rb
@@ -0,0 +1,47 @@
+require_relative 'spec_helper'
+require_relative '../lib/gitlab_keys'
+
+describe GitlabKeys do
+ describe :initialize do
+ before do
+ argv('add-key', 'dzaporozhets', 'ssh-rsa AAAAB3NzaDAxx2E')
+ @gl_keys = GitlabKeys.new
+ end
+
+ it { @gl_keys.username.should == 'dzaporozhets' }
+ it { @gl_keys.key.should == 'ssh-rsa AAAAB3NzaDAxx2E' }
+ it { @gl_keys.instance_variable_get(:@command).should == 'add-key' }
+ end
+
+ describe :add_key do
+ before do
+ argv('add-key', 'dzaporozhets', 'ssh-rsa AAAAB3NzaDAxx2E')
+ @gl_keys = GitlabKeys.new
+ end
+
+ it "should receive valid cmd" do
+ valid_cmd = "echo 'command=\"/home/git/gitlab-shell/spec/../bin/gitlab-shell dzaporozhets\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa AAAAB3NzaDAxx2E' >> /home/git/.ssh/authorized_keys"
+ @gl_keys.should_receive(:system).with(valid_cmd)
+ @gl_keys.send :add_key
+ end
+ end
+
+ describe :rm_key do
+ before do
+ argv('rm-key', 'dzaporozhets', 'ssh-rsa AAAAB3NzaDAxx2E')
+ @gl_keys = GitlabKeys.new
+ end
+
+ it "should receive valid cmd" do
+ valid_cmd = "sed '/ssh-rsa AAAAB3NzaDAxx2E/d' /home/git/.ssh/authorized_keys"
+ @gl_keys.should_receive(:system).with(valid_cmd)
+ @gl_keys.send :rm_key
+ end
+ end
+
+ def argv(*args)
+ args.each_with_index do |arg, i|
+ ARGV[i] = arg
+ end
+ end
+end
diff --git a/spec/gitlab_shell_spec.rb b/spec/gitlab_shell_spec.rb
index fa46fb5..ada3e87 100644
--- a/spec/gitlab_shell_spec.rb
+++ b/spec/gitlab_shell_spec.rb
@@ -2,7 +2,6 @@ require_relative 'spec_helper'
require_relative '../lib/gitlab_shell'
describe GitlabShell do
-
describe :initialize do
before do
ssh_cmd 'git-receive-pack'