diff options
Diffstat (limited to 'spec/gitlab_shell_authorized_keys_check_spec.rb')
-rw-r--r-- | spec/gitlab_shell_authorized_keys_check_spec.rb | 45 |
1 files changed, 7 insertions, 38 deletions
diff --git a/spec/gitlab_shell_authorized_keys_check_spec.rb b/spec/gitlab_shell_authorized_keys_check_spec.rb index baaa560..7050604 100644 --- a/spec/gitlab_shell_authorized_keys_check_spec.rb +++ b/spec/gitlab_shell_authorized_keys_check_spec.rb @@ -1,20 +1,7 @@ require_relative 'spec_helper' describe 'bin/gitlab-shell-authorized-keys-check' do - def original_root_path - ROOT_PATH - end - - # All this test boilerplate is mostly copy/pasted between - # gitlab_shell_gitlab_shell_spec.rb and - # gitlab_shell_authorized_keys_check_spec.rb - def tmp_root_path - @tmp_root_path ||= File.realpath(Dir.mktmpdir) - end - - def config_path - File.join(tmp_root_path, 'config.yml') - end + include_context 'gitlab shell' def tmp_socket_path # This has to be a relative path shorter than 100 bytes due to @@ -22,12 +9,8 @@ describe 'bin/gitlab-shell-authorized-keys-check' do 'tmp/gitlab-shell-authorized-keys-check-socket' end - before(:all) do - FileUtils.mkdir_p(File.dirname(tmp_socket_path)) - FileUtils.touch(File.join(tmp_root_path, '.gitlab_shell_secret')) - - @server = HTTPUNIXServer.new(BindAddress: tmp_socket_path) - @server.mount_proc('/api/v4/internal/authorized_keys') do |req, res| + def mock_server(server) + server.mount_proc('/api/v4/internal/authorized_keys') do |req, res| if req.query['key'] == 'known-rsa-key' res.status = 200 res.content_type = 'application/json' @@ -36,28 +19,14 @@ describe 'bin/gitlab-shell-authorized-keys-check' do res.status = 404 end end - - @webrick_thread = Thread.new { @server.start } - - sleep(0.1) while @webrick_thread.alive? && @server.status != :Running - raise "Couldn't start stub GitlabNet server" unless @server.status == :Running - - File.open(config_path, 'w') do |f| - f.write("---\ngitlab_url: http+unix://#{CGI.escape(tmp_socket_path)}\n") - end - - copy_dirs = ['bin', 'lib'] - FileUtils.rm_rf(copy_dirs.map { |d| File.join(tmp_root_path, d) }) - FileUtils.cp_r(copy_dirs, tmp_root_path) end - after(:all) do - @server.shutdown if @server - @webrick_thread.join if @webrick_thread - FileUtils.rm_rf(tmp_root_path) + before(:all) do + write_config( + "gitlab_url" => "http+unix://#{CGI.escape(tmp_socket_path)}", + ) end - let(:gitlab_shell_path) { File.join(tmp_root_path, 'bin', 'gitlab-shell') } let(:authorized_keys_check_path) { File.join(tmp_root_path, 'bin', 'gitlab-shell-authorized-keys-check') } it 'succeeds when a valid key is given' do |