Commit ea6ea902 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

More tests

parent 8d374284
source "http://rubygems.org"
gem 'rspec'
group :development do
gem 'rspec'
gem 'guard'
gem 'guard-rspec'
end
GEM
remote: http://rubygems.org/
specs:
coderay (1.0.8)
diff-lcs (1.1.3)
guard (1.5.4)
listen (>= 0.4.2)
lumberjack (>= 1.0.2)
pry (>= 0.9.10)
thor (>= 0.14.6)
guard-rspec (2.1.2)
guard (>= 1.1)
rspec (~> 2.11)
listen (0.5.3)
lumberjack (1.0.2)
method_source (0.8.1)
pry (0.9.10)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.3.1)
rspec (2.12.0)
rspec-core (~> 2.12.0)
rspec-expectations (~> 2.12.0)
......@@ -10,9 +26,13 @@ GEM
rspec-expectations (2.12.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.12.2)
slop (3.3.3)
thor (0.16.0)
PLATFORMS
ruby
DEPENDENCIES
guard
guard-rspec
rspec
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard 'rspec' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
# Capybara features specs
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end
......@@ -15,7 +15,6 @@ class GitlabKeys
case @command
when 'add-key'; add_key
when 'rm-key'; rm_key
when 'rm-user'; rm_user
else
puts 'not allowed'
end
......@@ -33,9 +32,4 @@ class GitlabKeys
cmd = "sed '/#{@key}/d' #{auth_file}"
system(cmd)
end
def rm_user
cmd = "sed -i '/gitlab-shell #{@username},/d' #{auth_file}"
system(cmd)
end
end
......@@ -4,7 +4,7 @@ require 'net/http'
require_relative 'gitlab_config'
class GitlabShell
attr_accessor :username, :repo_name, :git_cmd, :repos_path
attr_accessor :username, :repo_name, :git_cmd, :repos_path, :repo_name
def initialize
@username = ARGV.shift
......
......@@ -5,7 +5,7 @@ describe GitlabShell do
describe :initialize do
before do
ENV['SSH_ORIGINAL_COMMAND'] = 'git-receive-pack'
ssh_cmd 'git-receive-pack'
ARGV[0] = 'dzaporozhets'
@shell = GitlabShell.new
end
......@@ -13,4 +13,59 @@ describe GitlabShell do
it { @shell.username.should == 'dzaporozhets' }
it { @shell.repos_path.should == "/home/git/repositories" }
end
describe :parse_cmd do
context 'w/o namespace' do
before do
ssh_cmd 'git-upload-pack gitlab-ci.git'
@shell = GitlabShell.new
@shell.send :parse_cmd
end
it { @shell.repo_name.should == 'gitlab-ci.git' }
it { @shell.git_cmd.should == 'git-upload-pack' }
end
context 'namespace' do
before do
ssh_cmd 'git-upload-pack dmitriy.zaporozhets/gitlab-ci.git'
@shell = GitlabShell.new
@shell.send :parse_cmd
end
it { @shell.repo_name.should == 'dmitriy.zaporozhets/gitlab-ci.git' }
it { @shell.git_cmd.should == 'git-upload-pack' }
end
end
describe :exec do
context 'git-upload-pack' do
before do
ssh_cmd 'git-upload-pack gitlab-ci.git'
stubbed_shell
end
it { @shell.exec.should be_true }
end
context 'git-receive-pack' do
before do
ssh_cmd 'git-receive-pack gitlab-ci.git'
stubbed_shell
end
it { @shell.exec.should be_true }
end
end
def ssh_cmd(cmd)
ENV['SSH_ORIGINAL_COMMAND'] = cmd
end
def stubbed_shell
ARGV[0] = 'dzaporozhets'
@shell = GitlabShell.new
@shell.stub(validate_access: true)
@shell.stub(process_cmd: true)
end
end
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