diff options
author | Igor <idrozdov@gitlab.com> | 2019-03-21 11:53:09 +0000 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2019-03-21 11:53:09 +0000 |
commit | 98dbdfb758703428626d54b2a257565a44509a55 (patch) | |
tree | a3fdc408786fd0342bd3eb28ad841e70d3d7ac6e /spec/support/gitlab_shell_setup.rb | |
parent | 81bed658f083a165e65b16f7ef86c18938349e33 (diff) | |
download | gitlab-shell-98dbdfb758703428626d54b2a257565a44509a55.tar.gz |
Provide go implementation for 2fa_recovery_codes command
Diffstat (limited to 'spec/support/gitlab_shell_setup.rb')
-rw-r--r-- | spec/support/gitlab_shell_setup.rb | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/spec/support/gitlab_shell_setup.rb b/spec/support/gitlab_shell_setup.rb new file mode 100644 index 0000000..eddd2d1 --- /dev/null +++ b/spec/support/gitlab_shell_setup.rb @@ -0,0 +1,58 @@ +RSpec.shared_context 'gitlab shell', shared_context: :metadata do + def original_root_path + ROOT_PATH + end + + def config_path + File.join(tmp_root_path, 'config.yml') + end + + def write_config(config) + File.open(config_path, 'w') do |f| + f.write(config.to_yaml) + end + end + + def tmp_root_path + @tmp_root_path ||= File.realpath(Dir.mktmpdir) + end + + def mock_server(server) + raise NotImplementedError.new( + 'mock_server method must be implemented in order to include gitlab shell context' + ) + end + + # This has to be a relative path shorter than 100 bytes due to + # limitations in how Unix sockets work. + def tmp_socket_path + 'tmp/gitlab-shell-socket' + end + + let(:gitlab_shell_path) { File.join(tmp_root_path, 'bin', 'gitlab-shell') } + + 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) + + mock_server(@server) + + @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 + system(original_root_path, 'bin/compile') + + 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) + end +end |