summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG28
-rw-r--r--README.md22
-rw-r--r--VERSION2
-rwxr-xr-xbin/authorized_keys25
-rwxr-xr-xbin/gitlab-projects2
-rw-r--r--lib/gitlab_authorized_keys.rb0
-rw-r--r--lib/gitlab_keys.rb26
-rw-r--r--lib/gitlab_net.rb7
-rw-r--r--lib/gitlab_post_receive.rb6
-rw-r--r--lib/gitlab_projects.rb108
-rw-r--r--lib/gitlab_shell.rb5
-rw-r--r--spec/gitlab_net_spec.rb36
-rw-r--r--spec/gitlab_post_receive_spec.rb2
-rw-r--r--spec/gitlab_projects_spec.rb80
-rw-r--r--spec/gitlab_shell_spec.rb11
-rw-r--r--spec/vcr_cassettes/ssh-key-not-found.yml50
-rw-r--r--spec/vcr_cassettes/ssh-key-not-implemented.yml50
-rw-r--r--spec/vcr_cassettes/ssh-key-ok.yml40
18 files changed, 341 insertions, 159 deletions
diff --git a/CHANGELOG b/CHANGELOG
index b15af33..63b04cc 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,31 @@
+v3.0.0
+ - Remove rm-tag command (Robert Schilling)
+ - Remove create-branch and rm-branch commands (Robert Schilling)
+ - Update PostReceive worker so it logs a unique JID in Sidekiq
+ - Remove update-head command
+
+v2.7.2
+ - Do not prune objects during 'git gc'
+
+v2.7.1
+ - Add new command to list tags from a remote repo
+ - Add the ability to fetch remote repo with or without tags
+
+v2.7.0
+ - Add support for ssh AuthorizedKeysCommand query by key
+
+v2.6.13
+ - Add push-branches command
+ - Add delete-remote-branches command
+
+v2.6.12
+ - Fix git-annex issue not working using custom SSH port repositories
+
+v2.6.11
+ - Increase HTTP timeout and log request durations
+ - Workaround for a Webrick issue on Ruby 2.2
+ - New optional `--force` parameter for `gitlab-projects fetch-remote`
+
v2.6.10
- Add git gc for housekeeping
diff --git a/README.md b/README.md
index 7f2f044..cb6aacf 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@ When you access the GitLab server over ssh then GitLab Shell will:
1. Limits you to predefined git commands (git push, git pull, git annex).
1. Call the GitLab Rails API to check if you are authorized
1. It will execute the pre-receive hooks (called Git Hooks in GitLab Enterprise Edition)
-1. It will excute the action you requested
+1. It will execute the action you requested
1. Process the GitLab post-receive actions
1. Process any custom post-receive actions
@@ -34,7 +34,7 @@ The authorization checks for git pull are much simpler since you only have to ch
An overview of the four cases described above:
1. git pull over ssh -> gitlab-shell -> API call to gitlab-rails (Authorization) -> accept or decline -> execute git command
-1. git pull over http -> gitlab-rails (AUthorization) -> accept or decline -> execute git command
+1. git pull over http -> gitlab-rails (Authorization) -> accept or decline -> execute git command
1. git push over ssh -> gitlab-shell (git command is not executed yet) -> execute git command -> gitlab-shell pre-receive hook -> API call to gitlab-rails (authorization) -> accept or decline push
1. git push over http -> gitlab-rails (git command is not executed yet) -> execute git command -> gitlab-shell pre-receive hook -> API call to gitlab-rails (authorization) -> accept or decline push
@@ -100,27 +100,11 @@ Fork repo:
./bin/gitlab-projects fork-project gitlab/gitlab-ci.git randx
-Update HEAD:
-
- ./bin/gitlab-projects update-head gitlab/gitlab-ci.git 3-2-stable
-
-Create branch:
-
- ./bin/gitlab-projects create-branch gitlab/gitlab-ci.git 3-2-stable master
-
-Remove branch:
-
- ./bin/gitlab-projects rm-branch gitlab/gitlab-ci.git 3-0-stable
-
Create tag (lightweight & annotated):
./bin/gitlab-projects create-tag gitlab/gitlab-ci.git v3.0.0 3-0-stable
./bin/gitlab-projects create-tag gitlab/gitlab-ci.git v3.0.0 3-0-stable 'annotated message goes here'
-Remove tag:
-
- ./bin/gitlab-projects rm-tag gitlab/gitlab-ci.git v3.0.0
-
Gc repo:
./bin/gitlab-projects gc gitlab/gitlab-ci.git
@@ -168,7 +152,7 @@ This design will work without a script git-lfs-authenticate, but with the follow
* You will need to manually configure lfs-server URL for every user working copy;
* SSO don't work and you need to manually add lfs-server credentials for every user working copy (otherwise, git-lfs will ask for the password for each file).
-Usefull links:
+Useful links:
* https://github.com/github/git-lfs/tree/master/docs/api - Git LFS API, also contains more information about ```git-lfs-authenticate```;
* https://github.com/github/git-lfs/wiki/Implementations - Git LFS-server implementations.
diff --git a/VERSION b/VERSION
index a04abec..37c2961 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.6.10
+2.7.2
diff --git a/bin/authorized_keys b/bin/authorized_keys
new file mode 100755
index 0000000..6aab4a5
--- /dev/null
+++ b/bin/authorized_keys
@@ -0,0 +1,25 @@
+#!/usr/bin/env ruby
+
+#
+# GitLab shell authorized_keys. Query GitLab API to get the authorized command for a given ssh key fingerprint
+#
+# Ex.
+# /bin/authorized_keys BASE64-KEY
+#
+# Returns
+# command="/bin/gitlab-shell key-#",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa AAAAB3NzaC1yc2EAAAADAQA...
+#
+
+key = ARGV[0]
+abort "# No key provided" if key.nil? || key.empty?
+
+require_relative "../lib/gitlab_init"
+require_relative "../lib/gitlab_net"
+require_relative "../lib/gitlab_keys"
+
+authorized_key = GitlabNet.new.authorized_key(key)
+if authorized_key.nil?
+ puts "# No key was found for #{key}"
+else
+ puts GitlabKey.new.key_line("key-#{authorized_key['id']}", authorized_key["key"])
+end
diff --git a/bin/gitlab-projects b/bin/gitlab-projects
index c354fe5..22b0022 100755
--- a/bin/gitlab-projects
+++ b/bin/gitlab-projects
@@ -19,8 +19,6 @@ require_relative '../lib/gitlab_init'
#
# /bin/gitlab-projects import-project randx/six.git https://github.com/randx/six.git
#
-# /bin/gitlab-projects update-head gitlab/gitlab-ci.git 5-2-stable
-#
require File.join(ROOT_PATH, 'lib', 'gitlab_projects')
# Return non-zero if command execution was not successful
diff --git a/lib/gitlab_authorized_keys.rb b/lib/gitlab_authorized_keys.rb
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/lib/gitlab_authorized_keys.rb
diff --git a/lib/gitlab_keys.rb b/lib/gitlab_keys.rb
index 3710f96..f17e6b7 100644
--- a/lib/gitlab_keys.rb
+++ b/lib/gitlab_keys.rb
@@ -11,6 +11,7 @@ class GitlabKeys
@key_id = ARGV.shift
@key = ARGV.shift
@auth_file = GitlabConfig.new.auth_file
+ @gitlab_key = GitlabKey.new
end
def exec
@@ -32,7 +33,7 @@ class GitlabKeys
def add_key
lock do
$logger.info "Adding key #{@key_id} => #{@key.inspect}"
- auth_line = key_line(@key_id, @key)
+ auth_line = @gitlab_key.key_line(@key_id, @key)
open(auth_file, 'a') { |file| file.puts(auth_line) }
end
true
@@ -59,7 +60,7 @@ class GitlabKeys
abort("#{$0}: invalid input #{input.inspect}") unless tokens.count == 2
key_id, public_key = tokens
$logger.info "Adding key #{key_id} => #{public_key.inspect}"
- file.puts(key_line(key_id, public_key))
+ file.puts(@gitlab_key.key_line(key_id, public_key))
end
end
end
@@ -70,20 +71,12 @@ class GitlabKeys
$stdin
end
- def key_command(key_id)
- "#{ROOT_PATH}/bin/gitlab-shell #{key_id}"
- end
-
- def key_line(key_id, public_key)
- auth_line = "command=\"#{key_command(key_id)}\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty #{public_key}"
- end
-
def rm_key
lock do
$logger.info "Removing key #{@key_id}"
open(auth_file, 'r+') do |f|
while line = f.gets do
- next unless line.start_with?("command=\"#{key_command(@key_id)}\"")
+ next unless line.start_with?("command=\"#{@gitlab_key.command(@key_id)}\"")
f.seek(-line.length, IO::SEEK_CUR)
# Overwrite the line with #'s. Because the 'line' variable contains
# a terminating '\n', we write line.length - 1 '#' characters.
@@ -115,3 +108,14 @@ class GitlabKeys
@lock_file ||= auth_file + '.lock'
end
end
+
+
+class GitlabKey
+ def command(key_id)
+ "#{ROOT_PATH}/bin/gitlab-shell #{key_id}"
+ end
+
+ def key_line(key_id, public_key)
+ "command=\"#{command(key_id)}\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty #{public_key}"
+ end
+end
diff --git a/lib/gitlab_net.rb b/lib/gitlab_net.rb
index 71e113b..8b6d33b 100644
--- a/lib/gitlab_net.rb
+++ b/lib/gitlab_net.rb
@@ -56,6 +56,13 @@ class GitlabNet
get("#{host}/check", read_timeout: CHECK_TIMEOUT)
end
+ def authorized_key(key)
+ resp = get("#{host}/authorized_keys?key=#{URI.escape(key, '+/=')}")
+ JSON.parse(resp.body) if resp.code == "200"
+ rescue
+ nil
+ end
+
protected
def config
diff --git a/lib/gitlab_post_receive.rb b/lib/gitlab_post_receive.rb
index ede64f2..0fff479 100644
--- a/lib/gitlab_post_receive.rb
+++ b/lib/gitlab_post_receive.rb
@@ -2,14 +2,16 @@ require_relative 'gitlab_init'
require_relative 'gitlab_net'
require 'json'
require 'base64'
+require 'securerandom'
class GitlabPostReceive
- attr_reader :config, :repo_path, :changes
+ attr_reader :config, :repo_path, :changes, :jid
def initialize(repo_path, actor, changes)
@config = GitlabConfig.new
@repo_path, @actor = repo_path.strip, actor
@changes = changes
+ @jid = SecureRandom.hex(12)
end
def exec
@@ -71,7 +73,7 @@ class GitlabPostReceive
changes = Base64.encode64(@changes)
queue = "#{config.redis_namespace}:queue:post_receive"
- msg = JSON.dump({ 'class' => 'PostReceive', 'args' => [@repo_path, @actor, changes] })
+ msg = JSON.dump({ 'class' => 'PostReceive', 'args' => [@repo_path, @actor, changes], 'jid' => @jid })
if system(*config.redis_command, 'rpush', queue, msg,
err: '/dev/null', out: '/dev/null')
return true
diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb
index c1d175a..767ab79 100644
--- a/lib/gitlab_projects.rb
+++ b/lib/gitlab_projects.rb
@@ -1,5 +1,6 @@
require 'fileutils'
require 'timeout'
+require 'open3'
require_relative 'gitlab_config'
require_relative 'gitlab_logger'
@@ -49,10 +50,7 @@ class GitlabProjects
def exec
case @command
- when 'create-branch'; create_branch
- when 'rm-branch'; rm_branch
when 'create-tag'; create_tag
- when 'rm-tag'; rm_tag
when 'add-project'; add_project
when 'list-projects'; puts list_projects
when 'rm-project'; rm_project
@@ -60,7 +58,9 @@ class GitlabProjects
when 'import-project'; import_project
when 'fork-project'; fork_project
when 'fetch-remote'; fetch_remote
- when 'update-head'; update_head
+ when 'push-branches'; push_branches
+ when 'delete-remote-branches'; delete_remote_branches
+ when 'list-remote-tags'; list_remote_tags
when 'gc'; gc
else
$logger.warn "Attempt to execute invalid gitlab-projects command #{@command.inspect}."
@@ -71,17 +71,66 @@ class GitlabProjects
protected
- def create_branch
- branch_name = ARGV.shift
- ref = ARGV.shift || "HEAD"
- cmd = %W(git --git-dir=#{full_path} branch -- #{branch_name} #{ref})
- system(*cmd)
+ def list_remote_tags
+ remote_name = ARGV.shift
+
+ tag_list, exit_code, error = nil
+ cmd = %W(git --git-dir=#{full_path} ls-remote --tags #{remote_name})
+
+ Open3.popen3(*cmd) do |stdin, stdout, stderr, wait_thr|
+ tag_list = stdout.read
+ error = stderr.read
+ exit_code = wait_thr.value.exitstatus
+ end
+
+ if exit_code.zero?
+ puts tag_list
+ true
+ else
+ puts error
+ false
+ end
end
- def rm_branch
- branch_name = ARGV.shift
- cmd = %W(git --git-dir=#{full_path} branch -D -- #{branch_name})
- system(*cmd)
+ def push_branches
+ remote_name = ARGV.shift
+
+ $logger.info "Pushing branches from #{full_path} to remote #{remote_name}: #{ARGV}"
+ cmd = %W(git --git-dir=#{full_path} push -- #{remote_name}).concat(ARGV)
+ pid = Process.spawn(*cmd)
+
+ begin
+ Process.wait(pid)
+
+ $?.exitstatus.zero?
+ rescue => exception
+ $logger.error "Pushing branches to remote #{remote_name} failed due to: #{exception.message}"
+
+ Process.kill('KILL', pid)
+ Process.wait
+ false
+ end
+ end
+
+ def delete_remote_branches
+ remote_name = ARGV.shift
+ branches = ARGV.map { |branch_name| ":#{branch_name}" }
+
+ $logger.info "Pushing deleted branches from #{full_path} to remote #{remote_name}: #{ARGV}"
+ cmd = %W(git --git-dir=#{full_path} push -- #{remote_name}).concat(branches)
+ pid = Process.spawn(*cmd)
+
+ begin
+ Process.wait(pid)
+
+ $?.exitstatus.zero?
+ rescue => exception
+ $logger.error "Pushing deleted branches to remote #{remote_name} failed due to: #{exception.message}"
+
+ Process.kill('KILL', pid)
+ Process.wait
+ false
+ end
end
def create_tag
@@ -96,12 +145,6 @@ class GitlabProjects
system(*cmd)
end
- def rm_tag
- tag_name = ARGV.shift
- cmd = %W(git --git-dir=#{full_path} tag -d -- #{tag_name})
- system(*cmd)
- end
-
def add_project
$logger.info "Adding project #{@project_name} at <#{full_path}>."
FileUtils.mkdir_p(full_path, mode: 0770)
@@ -135,8 +178,17 @@ class GitlabProjects
# timeout for fetch
timeout = (ARGV.shift || 120).to_i
+
+ # fetch with --force ?
+ forced = ARGV.include?('--force')
+
+ # fetch with --tags or --no-tags
+ tags_option = ARGV.include?('--no-tags') ? '--no-tags' : '--tags'
+
$logger.info "Fetching remote #{@name} for project #{@project_name}."
- cmd = %W(git --git-dir=#{full_path} fetch #{@name} --tags)
+ cmd = %W(git --git-dir=#{full_path} fetch #{@name})
+ cmd << '--force' if forced
+ cmd << tags_option
pid = Process.spawn(*cmd)
begin
@@ -261,22 +313,6 @@ class GitlabProjects
system(*cmd) && self.class.create_hooks(full_destination_path)
end
- def update_head
- new_head = ARGV.shift
-
- unless new_head
- $logger.error "update-head failed: no branch provided."
- return false
- end
-
- File.open(File.join(full_path, 'HEAD'), 'w') do |f|
- f.write("ref: refs/heads/#{new_head}")
- end
-
- $logger.info "Update head in project #{project_name} to <#{new_head}>."
- true
- end
-
def gc
$logger.info "Running git gc for <#{full_path}>."
unless File.exists?(full_path)
diff --git a/lib/gitlab_shell.rb b/lib/gitlab_shell.rb
index 96ee1b7..365c543 100644
--- a/lib/gitlab_shell.rb
+++ b/lib/gitlab_shell.rb
@@ -101,9 +101,8 @@ class GitlabShell
parsed_args =
args.map do |arg|
- # Convert /~/group/project.git to group/project.git
- # to make git annex path compatible with gitlab-shell
- if arg =~ /\A\/~\/.*\.git\Z/
+ # use full repo path
+ if arg =~ /\A\/.*\.git\Z/
repo_full_path
else
arg
diff --git a/spec/gitlab_net_spec.rb b/spec/gitlab_net_spec.rb
index 2d9b544..e4dee33 100644
--- a/spec/gitlab_net_spec.rb
+++ b/spec/gitlab_net_spec.rb
@@ -8,8 +8,8 @@ describe GitlabNet, vcr: true do
let(:changes) { ['0000000000000000000000000000000000000000 92d0970eefd7acb6d548878925ce2208cfe2d2ec refs/heads/branch4'] }
before do
- gitlab_net.stub!(:host).and_return('https://dev.gitlab.org/api/v3/internal')
- gitlab_net.stub!(:secret_token).and_return('a123')
+ gitlab_net.stub(:host).and_return('https://dev.gitlab.org/api/v3/internal')
+ gitlab_net.stub(:secret_token).and_return('a123')
end
describe :check do
@@ -76,6 +76,36 @@ describe GitlabNet, vcr: true do
end
end
+ describe :authorized_key do
+ let (:ssh_key) { "AAAAB3NzaC1yc2EAAAADAQABAAACAQDPKPqqnqQ9PDFw65cO7iHXrKw6ucSZg8Bd2CZ150Yy1YRDPJOWeRNCnddS+M/Lk" }
+
+ it "should return nil when the resource is not implemented" do
+ VCR.use_cassette("ssh-key-not-implemented") do
+ result = gitlab_net.authorized_key("whatever")
+ result.should be_nil
+ end
+ end
+
+ it "should return nil when the fingerprint is not found" do
+ VCR.use_cassette("ssh-key-not-found") do
+ result = gitlab_net.authorized_key("whatever")
+ result.should be_nil
+ end
+ end
+
+ it "should return a ssh key with a valid fingerprint" do
+ VCR.use_cassette("ssh-key-ok") do
+ result = gitlab_net.authorized_key(ssh_key)
+ result.should eq({
+ "created_at" => "2016-03-04T18:27:36.959Z",
+ "id" => 2,
+ "key" => "ssh-rsa a-made=up-rsa-key dummy@gitlab.com",
+ "title" => "some key title"
+ })
+ end
+ end
+ end
+
describe :check_access do
context 'ssh key with access to project' do
it 'should allow pull access for dev.gitlab.org' do
@@ -142,7 +172,7 @@ describe GitlabNet, vcr: true do
describe :http_client_for do
subject { gitlab_net.send :http_client_for, URI('https://localhost/') }
before do
- gitlab_net.stub! :cert_store
+ gitlab_net.stub :cert_store
gitlab_net.send(:config).stub(:http_settings) { {'self_signed_cert' => true} }
end
diff --git a/spec/gitlab_post_receive_spec.rb b/spec/gitlab_post_receive_spec.rb
index 3c1f362..9d7696e 100644
--- a/spec/gitlab_post_receive_spec.rb
+++ b/spec/gitlab_post_receive_spec.rb
@@ -50,7 +50,7 @@ describe GitlabPostReceive do
expect(gitlab_post_receive).to receive(:system).with(
*[
*%w(env -i redis-cli rpush resque:gitlab:queue:post_receive),
- %Q/{"class":"PostReceive","args":["#{repo_path}","#{actor}",#{base64_changes.inspect}]}/,
+ %Q/{"class":"PostReceive","args":["#{repo_path}","#{actor}",#{base64_changes.inspect}],"jid":"#{gitlab_post_receive.jid}"}/,
{ err: "/dev/null", out: "/dev/null" }
]
).and_return(true)
diff --git a/spec/gitlab_projects_spec.rb b/spec/gitlab_projects_spec.rb
index 50af42f..eeebf87 100644
--- a/spec/gitlab_projects_spec.rb
+++ b/spec/gitlab_projects_spec.rb
@@ -68,40 +68,6 @@ describe GitlabProjects do
it { @gl_projects.instance_variable_get(:@full_path).should == "#{GitlabConfig.new.repos_path}/gitlab-ci.git" }
end
- describe :create_branch do
- let(:gl_projects_create) {
- build_gitlab_projects('import-project', repo_name, 'https://github.com/randx/six.git')
- }
- let(:gl_projects) { build_gitlab_projects('create-branch', repo_name, 'test_branch', 'master') }
-
- it "should create a branch" do
- gl_projects_create.exec
- gl_projects.exec
- branch_ref = capture_in_tmp_repo(%W(git rev-parse test_branch))
- master_ref = capture_in_tmp_repo(%W(git rev-parse master))
- branch_ref.should == master_ref
- end
- end
-
- describe :rm_branch do
- let(:gl_projects_create) {
- build_gitlab_projects('import-project', repo_name, 'https://github.com/randx/six.git')
- }
- let(:gl_projects_create_branch) {
- build_gitlab_projects('create-branch', repo_name, 'test_branch', 'master')
- }
- let(:gl_projects) { build_gitlab_projects('rm-branch', repo_name, 'test_branch') }
-
- it "should remove a branch" do
- gl_projects_create.exec
- gl_projects_create_branch.exec
- branch_ref = capture_in_tmp_repo(%W(git rev-parse test_branch))
- gl_projects.exec
- branch_del = capture_in_tmp_repo(%W(git rev-parse test_branch))
- branch_del.should_not == branch_ref
- end
- end
-
describe :create_tag do
let(:gl_projects_create) {
build_gitlab_projects('import-project', repo_name, 'https://github.com/randx/six.git')
@@ -139,25 +105,6 @@ describe GitlabProjects do
end
end
- describe :rm_tag do
- let(:gl_projects_create) {
- build_gitlab_projects('import-project', repo_name, 'https://github.com/randx/six.git')
- }
- let(:gl_projects_create_tag) {
- build_gitlab_projects('create-tag', repo_name, 'test_tag', 'master')
- }
- let(:gl_projects) { build_gitlab_projects('rm-tag', repo_name, 'test_tag') }
-
- it "should remove a branch" do
- gl_projects_create.exec
- gl_projects_create_tag.exec
- branch_ref = capture_in_tmp_repo(%W(git rev-parse test_tag))
- gl_projects.exec
- branch_del = capture_in_tmp_repo(%W(git rev-parse test_tag))
- branch_del.should_not == branch_ref
- end
- end
-
describe :add_project do
let(:gl_projects) { build_gitlab_projects('add-project', repo_name) }
@@ -258,33 +205,6 @@ describe GitlabProjects do
end
end
- describe :update_head do
- let(:gl_projects) { build_gitlab_projects('update-head', repo_name, 'stable') }
- let(:gl_projects_fail) { build_gitlab_projects 'update-head', repo_name }
-
- before do
- FileUtils.mkdir_p(tmp_repo_path)
- system(*%W(git init --bare #{tmp_repo_path}))
- FileUtils.touch(File.join(tmp_repo_path, "refs/heads/stable"))
- File.read(File.join(tmp_repo_path, 'HEAD')).strip.should == 'ref: refs/heads/master'
- end
-
- it "should update head for repo" do
- gl_projects.exec.should be_true
- File.read(File.join(tmp_repo_path, 'HEAD')).strip.should == 'ref: refs/heads/stable'
- end
-
- it "should log an update_head event" do
- $logger.should_receive(:info).with("Update head in project #{repo_name} to <stable>.")
- gl_projects.exec
- end
-
- it "should failed and log an error" do
- $logger.should_receive(:error).with("update-head failed: no branch provided.")
- gl_projects_fail.exec.should be_false
- end
- end
-
describe :import_project do
context 'success import' do
let(:gl_projects) { build_gitlab_projects('import-project', repo_name, 'https://github.com/randx/six.git') }
diff --git a/spec/gitlab_shell_spec.rb b/spec/gitlab_shell_spec.rb
index 86d72f4..dd5cfb2 100644
--- a/spec/gitlab_shell_spec.rb
+++ b/spec/gitlab_shell_spec.rb
@@ -104,6 +104,15 @@ describe GitlabShell do
File.exists?(File.join(tmp_repos_path, 'dzaporozhets/gitlab.git/annex')).should be_false
end
end
+
+ context 'with git-annex and relative path without ~/' do
+ # Using a SSH URL on a custom port will generate /dzaporozhets/gitlab.git
+ let(:ssh_args) { %W(git-annex-shell inannex /dzaporozhets/gitlab.git SHA256E) }
+
+ it 'should init git-annex' do
+ File.exists?(File.join(tmp_repos_path, 'dzaporozhets/gitlab.git/annex')).should be_true
+ end
+ end
end
end
@@ -171,7 +180,7 @@ describe GitlabShell do
end
end
- context 'no command' do
+ context 'no command' do
after { subject.exec(nil) }
it "should call api.discover" do
diff --git a/spec/vcr_cassettes/ssh-key-not-found.yml b/spec/vcr_cassettes/ssh-key-not-found.yml
new file mode 100644
index 0000000..55e5b4f
--- /dev/null
+++ b/spec/vcr_cassettes/ssh-key-not-found.yml
@@ -0,0 +1,50 @@
+---
+http_interactions:
+- request:
+ method: get
+ uri: https://dev.gitlab.org/api/v3/internal/authorized_keys?key=whatever
+ body:
+ encoding: US-ASCII
+ string: secret_token=a123
+ headers:
+ Accept-Encoding:
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
+ Accept:
+ - "*/*"
+ User-Agent:
+ - Ruby
+ Content-Type:
+ - application/x-www-form-urlencoded
+ response:
+ status:
+ code: 404
+ message: Not Found
+ headers:
+ Server:
+ - nginx
+ Date:
+ - Mon, 07 Mar 2016 12:09:59 GMT
+ Content-Type:
+ - text/html; charset=utf-8
+ Connection:
+ - keep-alive
+ Cache-Control:
+ - no-cache
+ Set-Cookie:
+ - _gitlab_session=a924e63729e538c9efe10fa8338077d7; path=/; expires=Mon, 14
+ Mar 2016 12:09:59 -0000; secure; HttpOnly
+ Status:
+ - 404 Not Found
+ X-Content-Type-Options:
+ - nosniff
+ X-Frame-Options:
+ - SAMEORIGIN
+ X-Request-Id:
+ - 275ad011-515f-4239-80be-e537fd7c9086
+ X-Runtime:
+ - '2.169401'
+ X-Xss-Protection:
+ - 1; mode=block
+ http_version:
+ recorded_at: Mon, 07 Mar 2016 12:10:00 GMT
+recorded_with: VCR 2.4.0
diff --git a/spec/vcr_cassettes/ssh-key-not-implemented.yml b/spec/vcr_cassettes/ssh-key-not-implemented.yml
new file mode 100644
index 0000000..98c3c00
--- /dev/null
+++ b/spec/vcr_cassettes/ssh-key-not-implemented.yml
@@ -0,0 +1,50 @@
+---
+http_interactions:
+- request:
+ method: get
+ uri: https://dev.gitlab.org/api/v3/internal/authorized_keys?key=whatever
+ body:
+ encoding: US-ASCII
+ string: secret_token=a123
+ headers:
+ Accept-Encoding:
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
+ Accept:
+ - "*/*"
+ User-Agent:
+ - Ruby
+ Content-Type:
+ - application/x-www-form-urlencoded
+ response:
+ status:
+ code: 501
+ message: Not Implemented
+ headers:
+ Server:
+ - nginx
+ Date:
+ - Mon, 07 Mar 2016 12:09:59 GMT
+ Content-Type:
+ - text/html; charset=utf-8
+ Connection:
+ - keep-alive
+ Cache-Control:
+ - no-cache
+ Set-Cookie:
+ - _gitlab_session=a924e63729e538c9efe10fa8338077d7; path=/; expires=Mon, 14
+ Mar 2016 12:09:59 -0000; secure; HttpOnly
+ Status:
+ - 501 Not Implemented
+ X-Content-Type-Options:
+ - nosniff
+ X-Frame-Options:
+ - SAMEORIGIN
+ X-Request-Id:
+ - 275ad011-515f-4239-80be-e537fd7c9086
+ X-Runtime:
+ - '2.169401'
+ X-Xss-Protection:
+ - 1; mode=block
+ http_version:
+ recorded_at: Mon, 07 Mar 2016 12:10:00 GMT
+recorded_with: VCR 2.4.0
diff --git a/spec/vcr_cassettes/ssh-key-ok.yml b/spec/vcr_cassettes/ssh-key-ok.yml
new file mode 100644
index 0000000..87817d1
--- /dev/null
+++ b/spec/vcr_cassettes/ssh-key-ok.yml
@@ -0,0 +1,40 @@
+---
+http_interactions:
+- request:
+ method: get
+ uri: https://dev.gitlab.org/api/v3/internal/authorized_keys?key=AAAAB3NzaC1yc2EAAAADAQABAAACAQDPKPqqnqQ9PDFw65cO7iHXrKw6ucSZg8Bd2CZ150Yy1YRDPJOWeRNCnddS+M/Lk
+ body:
+ encoding: US-ASCII
+ string: secret_token=a123
+ headers:
+ Accept-Encoding:
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
+ Accept:
+ - "*/*"
+ User-Agent:
+ - Ruby
+ Content-Type:
+ - application/x-www-form-urlencoded
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ Server:
+ - nginx/1.1.19
+ Date:
+ - Wed, 03 Sep 2014 11:27:35 GMT
+ Content-Type:
+ - application/json
+ Connection:
+ - keep-alive
+ Status:
+ - 200 OK
+ Cache-Control:
+ - max-age=0, private, must-revalidate
+ body:
+ encoding: UTF-8
+ string: '{"id":2, "title":"some key title", "key":"ssh-rsa a-made=up-rsa-key dummy@gitlab.com", "created_at":"2016-03-04T18:27:36.959Z"}'
+ http_version:
+ recorded_at: Mon, 07 Mar 2016 12:10:00 GMT
+recorded_with: VCR 2.4.0