summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2019-10-14 16:23:59 +0100
committerNick Thomas <nick@gitlab.com>2019-10-15 07:44:13 +0100
commite14cc772480d51abf647daf61139929a73ddc72c (patch)
tree642d9ec4ec8676ba0c3a3caad9ccabca599deb95
parent18096b5440e0818605add32538751c6be38e8343 (diff)
downloadgitlab-shell-e14cc772480d51abf647daf61139929a73ddc72c.tar.gz
Simplify integration specs
-rw-r--r--spec/gitlab_shell_authorized_principals_check_spec.rb35
-rw-r--r--spec/gitlab_shell_custom_git_receive_pack_spec.rb38
-rw-r--r--spec/gitlab_shell_discover_spec.rb (renamed from spec/gitlab_shell_gitlab_shell_spec.rb)26
-rw-r--r--spec/gitlab_shell_lfs_authentication_spec.rb31
-rw-r--r--spec/gitlab_shell_two_factor_recovery_spec.rb32
5 files changed, 32 insertions, 130 deletions
diff --git a/spec/gitlab_shell_authorized_principals_check_spec.rb b/spec/gitlab_shell_authorized_principals_check_spec.rb
index c2a3306..14693ab 100644
--- a/spec/gitlab_shell_authorized_principals_check_spec.rb
+++ b/spec/gitlab_shell_authorized_principals_check_spec.rb
@@ -3,13 +3,17 @@ require_relative 'spec_helper'
describe 'bin/gitlab-shell-authorized-principals-check' do
include_context 'gitlab shell'
+ before(:all) do
+ write_config({})
+ end
+
def mock_server(server)
# Do nothing as we're not connecting to a server in this check.
end
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
output, status = run!
@@ -39,35 +43,6 @@ describe 'bin/gitlab-shell-authorized-principals-check' do
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'])
cmd = [
authorized_principals_check_path,
diff --git a/spec/gitlab_shell_custom_git_receive_pack_spec.rb b/spec/gitlab_shell_custom_git_receive_pack_spec.rb
index 95cd8ea..0a57903 100644
--- a/spec/gitlab_shell_custom_git_receive_pack_spec.rb
+++ b/spec/gitlab_shell_custom_git_receive_pack_spec.rb
@@ -7,6 +7,12 @@ require 'base64'
describe 'Custom bin/gitlab-shell git-receive-pack' do
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)
server.mount_proc('/geo/proxy_git_push_ssh/info_refs') do |req, res|
res.content_type = 'application/json'
@@ -58,7 +64,9 @@ describe 'Custom bin/gitlab-shell git-receive-pack' do
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
def verify_successful_call!(cmd)
Open3.popen3(env, cmd) do |stdin, stdout, stderr|
@@ -103,32 +111,4 @@ describe 'Custom bin/gitlab-shell git-receive-pack' do
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
diff --git a/spec/gitlab_shell_gitlab_shell_spec.rb b/spec/gitlab_shell_discover_spec.rb
index 3e714d8..ea99067 100644
--- a/spec/gitlab_shell_gitlab_shell_spec.rb
+++ b/spec/gitlab_shell_discover_spec.rb
@@ -5,6 +5,10 @@ require 'open3'
describe 'bin/gitlab-shell' do
include_context 'gitlab shell'
+ before(:context) do
+ write_config("gitlab_url" => "http+unix://#{CGI.escape(tmp_socket_path)}")
+ end
+
def mock_server(server)
server.mount_proc('/api/v4/internal/discover') do |req, res|
identifier = req.query['key_id'] || req.query['username'] || req.query['user_id']
@@ -35,7 +39,7 @@ describe 'bin/gitlab-shell' do
Open3.capture3(env, cmd)
end
- shared_examples 'results with keys' do
+ describe 'results with keys' do
# Basic valid input
it 'succeeds and prints username when a valid known key id is given' do
output, _, status = run!(["key-100"])
@@ -102,26 +106,6 @@ describe 'bin/gitlab-shell' do
expect(output).to eq("Welcome to GitLab, @someuser!\n")
expect(status).to be_success
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
_, stderr, status = run!(["-c/usr/share/webapps/gitlab-shell/bin/gitlab-shell", "username-someuser"], env: {})
diff --git a/spec/gitlab_shell_lfs_authentication_spec.rb b/spec/gitlab_shell_lfs_authentication_spec.rb
index 7cdb320..d27f50a 100644
--- a/spec/gitlab_shell_lfs_authentication_spec.rb
+++ b/spec/gitlab_shell_lfs_authentication_spec.rb
@@ -6,6 +6,11 @@ describe 'bin/gitlab-shell git-lfs-authentication' do
include_context 'gitlab shell'
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)
server.mount_proc('/api/v4/internal/lfs_authenticate') do |req, res|
@@ -49,7 +54,7 @@ describe 'bin/gitlab-shell git-lfs-authentication' do
end
end
- shared_examples 'lfs authentication command' do
+ describe 'lfs authentication command' do
def successful_response
{
"header" => {
@@ -119,28 +124,4 @@ describe 'bin/gitlab-shell git-lfs-authentication' do
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
diff --git a/spec/gitlab_shell_two_factor_recovery_spec.rb b/spec/gitlab_shell_two_factor_recovery_spec.rb
index a7fa909..ba7f997 100644
--- a/spec/gitlab_shell_two_factor_recovery_spec.rb
+++ b/spec/gitlab_shell_two_factor_recovery_spec.rb
@@ -5,6 +5,12 @@ require 'open3'
describe 'bin/gitlab-shell 2fa_recovery_codes' do
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)
server.mount_proc('/api/v4/internal/two_factor_recovery_codes') do |req, res|
res.content_type = 'application/json'
@@ -31,7 +37,7 @@ describe 'bin/gitlab-shell 2fa_recovery_codes' do
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
def verify_successful_regeneration!(cmd)
Open3.popen2(env, cmd) do |stdin, stdout|
@@ -101,28 +107,4 @@ describe 'bin/gitlab-shell 2fa_recovery_codes' do
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