Commit e14cc772 authored by Nick Thomas's avatar Nick Thomas

Simplify integration specs

parent 18096b54
...@@ -3,13 +3,17 @@ require_relative 'spec_helper' ...@@ -3,13 +3,17 @@ require_relative 'spec_helper'
describe 'bin/gitlab-shell-authorized-principals-check' do describe 'bin/gitlab-shell-authorized-principals-check' do
include_context 'gitlab shell' include_context 'gitlab shell'
before(:all) do
write_config({})
end
def mock_server(server) def mock_server(server)
# Do nothing as we're not connecting to a server in this check. # Do nothing as we're not connecting to a server in this check.
end end
let(:authorized_principals_check_path) { File.join(tmp_root_path, 'bin', 'gitlab-shell-authorized-principals-check') } let(:authorized_principals_check_path) { File.join(tmp_root_path, 'bin', 'gitlab-shell-authorized-principals-check') }
shared_examples 'authorized principals check' do describe 'authorized principals check' do
it 'succeeds when a valid principal is given' do it 'succeeds when a valid principal is given' do
output, status = run! output, status = run!
...@@ -39,35 +43,6 @@ describe 'bin/gitlab-shell-authorized-principals-check' do ...@@ -39,35 +43,6 @@ describe 'bin/gitlab-shell-authorized-principals-check' do
end end
end end
describe 'without go features' do
before(:all) do
write_config({})
end
it_behaves_like 'authorized principals check'
end
describe 'without go features (via go)', :go do
before(:all) do
write_config({})
end
it_behaves_like 'authorized principals check'
end
describe 'with the go authorized-principals-check feature', :go do
before(:all) do
write_config(
'migration' => {
'enabled' => true,
'features' => ['authorized-principals-check']
}
)
end
it_behaves_like 'authorized principals check'
end
def run!(key_id: 'key', principals: ['principal']) def run!(key_id: 'key', principals: ['principal'])
cmd = [ cmd = [
authorized_principals_check_path, authorized_principals_check_path,
......
...@@ -7,6 +7,12 @@ require 'base64' ...@@ -7,6 +7,12 @@ require 'base64'
describe 'Custom bin/gitlab-shell git-receive-pack' do describe 'Custom bin/gitlab-shell git-receive-pack' do
include_context 'gitlab shell' include_context 'gitlab shell'
let(:env) { {'SSH_CONNECTION' => 'fake', 'SSH_ORIGINAL_COMMAND' => 'git-receive-pack group/repo' } }
before(:context) do
write_config("gitlab_url" => "http+unix://#{CGI.escape(tmp_socket_path)}")
end
def mock_server(server) def mock_server(server)
server.mount_proc('/geo/proxy_git_push_ssh/info_refs') do |req, res| server.mount_proc('/geo/proxy_git_push_ssh/info_refs') do |req, res|
res.content_type = 'application/json' res.content_type = 'application/json'
...@@ -58,7 +64,9 @@ describe 'Custom bin/gitlab-shell git-receive-pack' do ...@@ -58,7 +64,9 @@ describe 'Custom bin/gitlab-shell git-receive-pack' do
end end
end end
shared_examples 'dialog for performing a custom action' do describe 'dialog for performing a custom action' do
let(:inaccessible_error) { "Internal API error (403)\n" }
context 'when API calls perform successfully' do context 'when API calls perform successfully' do
def verify_successful_call!(cmd) def verify_successful_call!(cmd)
Open3.popen3(env, cmd) do |stdin, stdout, stderr| Open3.popen3(env, cmd) do |stdin, stdout, stderr|
...@@ -103,32 +111,4 @@ describe 'Custom bin/gitlab-shell git-receive-pack' do ...@@ -103,32 +111,4 @@ describe 'Custom bin/gitlab-shell git-receive-pack' do
end end
end end
end end
let(:env) { {'SSH_CONNECTION' => 'fake', 'SSH_ORIGINAL_COMMAND' => 'git-receive-pack group/repo' } }
describe 'without go features' do
before(:context) do
write_config(
"gitlab_url" => "http+unix://#{CGI.escape(tmp_socket_path)}",
)
end
it_behaves_like 'dialog for performing a custom action' do
let(:inaccessible_error) { "> GitLab: API is not accessible\n" }
end
end
describe 'with go features', :go do
before(:context) do
write_config(
"gitlab_url" => "http+unix://#{CGI.escape(tmp_socket_path)}",
"migration" => { "enabled" => true,
"features" => ["git-receive-pack"] }
)
end
it_behaves_like 'dialog for performing a custom action' do
let(:inaccessible_error) { "Internal API error (403)\n" }
end
end
end end
...@@ -5,6 +5,10 @@ require 'open3' ...@@ -5,6 +5,10 @@ require 'open3'
describe 'bin/gitlab-shell' do describe 'bin/gitlab-shell' do
include_context 'gitlab shell' include_context 'gitlab shell'
before(:context) do
write_config("gitlab_url" => "http+unix://#{CGI.escape(tmp_socket_path)}")
end
def mock_server(server) def mock_server(server)
server.mount_proc('/api/v4/internal/discover') do |req, res| server.mount_proc('/api/v4/internal/discover') do |req, res|
identifier = req.query['key_id'] || req.query['username'] || req.query['user_id'] identifier = req.query['key_id'] || req.query['username'] || req.query['user_id']
...@@ -35,7 +39,7 @@ describe 'bin/gitlab-shell' do ...@@ -35,7 +39,7 @@ describe 'bin/gitlab-shell' do
Open3.capture3(env, cmd) Open3.capture3(env, cmd)
end end
shared_examples 'results with keys' do describe 'results with keys' do
# Basic valid input # Basic valid input
it 'succeeds and prints username when a valid known key id is given' do it 'succeeds and prints username when a valid known key id is given' do
output, _, status = run!(["key-100"]) output, _, status = run!(["key-100"])
...@@ -102,26 +106,6 @@ describe 'bin/gitlab-shell' do ...@@ -102,26 +106,6 @@ describe 'bin/gitlab-shell' do
expect(output).to eq("Welcome to GitLab, @someuser!\n") expect(output).to eq("Welcome to GitLab, @someuser!\n")
expect(status).to be_success expect(status).to be_success
end end
end
describe 'without go features' do
before(:context) do
write_config("gitlab_url" => "http+unix://#{CGI.escape(tmp_socket_path)}")
end
it_behaves_like 'results with keys'
end
describe 'with the go discover feature', :go do
before(:context) do
write_config(
"gitlab_url" => "http+unix://#{CGI.escape(tmp_socket_path)}",
"migration" => { "enabled" => true,
"features" => ["discover"] }
)
end
it_behaves_like 'results with keys'
it 'outputs "Only SSH allowed"' do it 'outputs "Only SSH allowed"' do
_, stderr, status = run!(["-c/usr/share/webapps/gitlab-shell/bin/gitlab-shell", "username-someuser"], env: {}) _, stderr, status = run!(["-c/usr/share/webapps/gitlab-shell/bin/gitlab-shell", "username-someuser"], env: {})
......
...@@ -6,6 +6,11 @@ describe 'bin/gitlab-shell git-lfs-authentication' do ...@@ -6,6 +6,11 @@ describe 'bin/gitlab-shell git-lfs-authentication' do
include_context 'gitlab shell' include_context 'gitlab shell'
let(:path) { "https://gitlab.com/repo/path" } let(:path) { "https://gitlab.com/repo/path" }
let(:env) { {'SSH_CONNECTION' => 'fake', 'SSH_ORIGINAL_COMMAND' => 'git-lfs-authenticate project/repo download' } }
before(:context) do
write_config("gitlab_url" => "http+unix://#{CGI.escape(tmp_socket_path)}")
end
def mock_server(server) def mock_server(server)
server.mount_proc('/api/v4/internal/lfs_authenticate') do |req, res| server.mount_proc('/api/v4/internal/lfs_authenticate') do |req, res|
...@@ -49,7 +54,7 @@ describe 'bin/gitlab-shell git-lfs-authentication' do ...@@ -49,7 +54,7 @@ describe 'bin/gitlab-shell git-lfs-authentication' do
end end
end end
shared_examples 'lfs authentication command' do describe 'lfs authentication command' do
def successful_response def successful_response
{ {
"header" => { "header" => {
...@@ -119,28 +124,4 @@ describe 'bin/gitlab-shell git-lfs-authentication' do ...@@ -119,28 +124,4 @@ describe 'bin/gitlab-shell git-lfs-authentication' do
end end
end end
end end
let(:env) { {'SSH_CONNECTION' => 'fake', 'SSH_ORIGINAL_COMMAND' => 'git-lfs-authenticate project/repo download' } }
describe 'without go features' do
before(:context) do
write_config(
"gitlab_url" => "http+unix://#{CGI.escape(tmp_socket_path)}",
)
end
it_behaves_like 'lfs authentication command'
end
describe 'with go features' do
before(:context) do
write_config(
"gitlab_url" => "http+unix://#{CGI.escape(tmp_socket_path)}",
"migration" => { "enabled" => true,
"features" => ["git-lfs-authenticate"] }
)
end
it_behaves_like 'lfs authentication command'
end
end end
...@@ -5,6 +5,12 @@ require 'open3' ...@@ -5,6 +5,12 @@ require 'open3'
describe 'bin/gitlab-shell 2fa_recovery_codes' do describe 'bin/gitlab-shell 2fa_recovery_codes' do
include_context 'gitlab shell' include_context 'gitlab shell'
let(:env) { {'SSH_CONNECTION' => 'fake', 'SSH_ORIGINAL_COMMAND' => '2fa_recovery_codes' } }
before(:context) do
write_config("gitlab_url" => "http+unix://#{CGI.escape(tmp_socket_path)}")
end
def mock_server(server) def mock_server(server)
server.mount_proc('/api/v4/internal/two_factor_recovery_codes') do |req, res| server.mount_proc('/api/v4/internal/two_factor_recovery_codes') do |req, res|
res.content_type = 'application/json' res.content_type = 'application/json'
...@@ -31,7 +37,7 @@ describe 'bin/gitlab-shell 2fa_recovery_codes' do ...@@ -31,7 +37,7 @@ describe 'bin/gitlab-shell 2fa_recovery_codes' do
end end
end end
shared_examples 'dialog for regenerating recovery keys' do describe 'dialog for regenerating recovery keys' do
context 'when the user agrees to regenerate keys' do context 'when the user agrees to regenerate keys' do
def verify_successful_regeneration!(cmd) def verify_successful_regeneration!(cmd)
Open3.popen2(env, cmd) do |stdin, stdout| Open3.popen2(env, cmd) do |stdin, stdout|
...@@ -101,28 +107,4 @@ describe 'bin/gitlab-shell 2fa_recovery_codes' do ...@@ -101,28 +107,4 @@ describe 'bin/gitlab-shell 2fa_recovery_codes' do
end end
end end
end end
let(:env) { {'SSH_CONNECTION' => 'fake', 'SSH_ORIGINAL_COMMAND' => '2fa_recovery_codes' } }
describe 'without go features' do
before(:context) do
write_config(
"gitlab_url" => "http+unix://#{CGI.escape(tmp_socket_path)}",
)
end
it_behaves_like 'dialog for regenerating recovery keys'
end
describe 'with go features', :go do
before(:context) do
write_config(
"gitlab_url" => "http+unix://#{CGI.escape(tmp_socket_path)}",
"migration" => { "enabled" => true,
"features" => ["2fa_recovery_codes"] }
)
end
it_behaves_like 'dialog for regenerating recovery keys'
end
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