summaryrefslogtreecommitdiff
path: root/spec/gitlab_shell_spec.rb
diff options
context:
space:
mode:
authorKim "BKC" Carlbäcker <kim.carlbacker@gmail.com>2017-06-26 17:36:15 +0200
committerKim "BKC" Carlbäcker <kim.carlbacker@gmail.com>2017-07-03 19:12:05 +0200
commit799417a3f59b5b6e2923016c6fa3ecf1f84851bb (patch)
tree3c703ebd078f4bd6be231ccacd6ebb7452f79d07 /spec/gitlab_shell_spec.rb
parent4539a066ecd2c5a16cab66f9e85f8f0ab747fc5f (diff)
downloadgitlab-shell-799417a3f59b5b6e2923016c6fa3ecf1f84851bb.tar.gz
- Update gitaly vendoring
- Wire up gitaly-*-pack to Gitaly. Don't pass git-*-pack to go - Disable tests for go1.5 & 1.6
Diffstat (limited to 'spec/gitlab_shell_spec.rb')
-rw-r--r--spec/gitlab_shell_spec.rb72
1 files changed, 65 insertions, 7 deletions
diff --git a/spec/gitlab_shell_spec.rb b/spec/gitlab_shell_spec.rb
index e0d1af6..ab12e87 100644
--- a/spec/gitlab_shell_spec.rb
+++ b/spec/gitlab_shell_spec.rb
@@ -19,10 +19,12 @@ describe GitlabShell do
end
end
+ let(:gitaly_check_access) { GitAccessStatus.new(true, 'ok', gl_repository, repo_path, { 'repository' => { 'relative_path' => repo_name, 'storage_name' => 'default'} , 'address' => 'unix:gitaly.socket' })}
+
let(:api) do
double(GitlabNet).tap do |api|
api.stub(discover: { 'name' => 'John Doe' })
- api.stub(check_access: GitAccessStatus.new(true, 'ok', gl_repository, repo_path))
+ api.stub(check_access: GitAccessStatus.new(true, 'ok', gl_repository, repo_path, nil))
api.stub(two_factor_recovery_codes: {
'success' => true,
'recovery_codes' => ['f67c514de60c4953', '41278385fc00c1e0']
@@ -128,7 +130,7 @@ describe GitlabShell do
end
describe :exec do
- let(:gitaly_message) { JSON.dump({ 'repository' => { 'path' => repo_path }, 'gl_id' => key_id }) }
+ let(:gitaly_message) { JSON.dump({ 'repository' => { 'relative_path' => repo_name, 'storage_name' => 'default' }, 'gl_repository' => gl_repository , 'gl_id' => key_id}) }
context 'git-upload-pack' do
let(:ssh_cmd) { "git-upload-pack gitlab-ci.git" }
@@ -139,12 +141,40 @@ describe GitlabShell do
end
it "should execute the command" do
- subject.should_receive(:exec_cmd).with(File.join(ROOT_PATH, "bin/gitaly-upload-pack"), '', gitaly_message)
+ subject.should_receive(:exec_cmd).with('git-upload-pack', repo_path)
+ end
+
+ it "should log the command execution" do
+ message = "gitlab-shell: executing git command "
+ message << "<git-upload-pack #{repo_path}> "
+ message << "for user with key #{key_id}."
+ $logger.should_receive(:info).with(message)
+ end
+
+ it "should use usernames if configured to do so" do
+ GitlabConfig.any_instance.stub(audit_usernames: true)
+ $logger.should_receive(:info) { |msg| msg.should =~ /for John Doe/ }
+ end
+ end
+
+ context 'gitaly-upload-pack' do
+ let(:ssh_cmd) { "git-upload-pack gitlab-ci.git" }
+ before {
+ api.stub(check_access: gitaly_check_access)
+ }
+ after { subject.exec(ssh_cmd) }
+
+ it "should process the command" do
+ subject.should_receive(:process_cmd).with(%W(git-upload-pack gitlab-ci.git))
+ end
+
+ it "should execute the command" do
+ subject.should_receive(:exec_cmd).with(File.join(ROOT_PATH, "bin/gitaly-upload-pack"), 'unix:gitaly.socket', gitaly_message)
end
it "should log the command execution" do
message = "gitlab-shell: executing git command "
- message << "<gitaly-upload-pack #{gitaly_message}> "
+ message << "<gitaly-upload-pack unix:gitaly.socket #{gitaly_message}> "
message << "for user with key #{key_id}."
$logger.should_receive(:info).with(message)
end
@@ -164,17 +194,45 @@ describe GitlabShell do
end
it "should execute the command" do
- subject.should_receive(:exec_cmd).with(File.join(ROOT_PATH, "bin/gitaly-receive-pack"), '', gitaly_message)
+ subject.should_receive(:exec_cmd).with('git-receive-pack', repo_path)
end
it "should log the command execution" do
message = "gitlab-shell: executing git command "
- message << "<gitaly-receive-pack #{gitaly_message}> "
+ message << "<git-receive-pack #{repo_path}> "
message << "for user with key #{key_id}."
$logger.should_receive(:info).with(message)
end
end
+ context 'gitaly-receive-pack' do
+ let(:ssh_cmd) { "git-receive-pack gitlab-ci.git" }
+ before {
+ api.stub(check_access: gitaly_check_access)
+ }
+ after { subject.exec(ssh_cmd) }
+
+ it "should process the command" do
+ subject.should_receive(:process_cmd).with(%W(git-receive-pack gitlab-ci.git))
+ end
+
+ it "should execute the command" do
+ subject.should_receive(:exec_cmd).with(File.join(ROOT_PATH, "bin/gitaly-receive-pack"), 'unix:gitaly.socket', gitaly_message)
+ end
+
+ it "should log the command execution" do
+ message = "gitlab-shell: executing git command "
+ message << "<gitaly-receive-pack unix:gitaly.socket #{gitaly_message}> "
+ message << "for user with key #{key_id}."
+ $logger.should_receive(:info).with(message)
+ end
+
+ it "should use usernames if configured to do so" do
+ GitlabConfig.any_instance.stub(audit_usernames: true)
+ $logger.should_receive(:info) { |msg| msg.should =~ /for John Doe/ }
+ end
+ end
+
context 'arbitrary command' do
let(:ssh_cmd) { 'arbitrary command' }
after { subject.exec(ssh_cmd) }
@@ -268,7 +326,7 @@ describe GitlabShell do
end
it "should disallow access and log the attempt if check_access returns false status" do
- api.stub(check_access: GitAccessStatus.new(false, 'denied', nil, nil))
+ api.stub(check_access: GitAccessStatus.new(false, 'denied', nil, nil, nil))
message = "gitlab-shell: Access denied for git command <git-upload-pack gitlab-ci.git> "
message << "by user with key #{key_id}."
$logger.should_receive(:warn).with(message)