diff options
Diffstat (limited to 'spec/action')
-rw-r--r-- | spec/action/api_2fa_recovery.rb_spec.rb | 73 | ||||
-rw-r--r-- | spec/action/base_spec.rb | 12 | ||||
-rw-r--r-- | spec/action/git_lfs_authenticate_spec.rb | 48 | ||||
-rw-r--r-- | spec/action/gitaly_spec.rb | 137 |
4 files changed, 0 insertions, 270 deletions
diff --git a/spec/action/api_2fa_recovery.rb_spec.rb b/spec/action/api_2fa_recovery.rb_spec.rb deleted file mode 100644 index 70091e9..0000000 --- a/spec/action/api_2fa_recovery.rb_spec.rb +++ /dev/null @@ -1,73 +0,0 @@ -require_relative '../spec_helper' -require_relative '../../lib/action/api_2fa_recovery' - -describe Action::API2FARecovery do - let(:key_id) { '1' } - let(:actor) { Actor::Key.new(key_id) } - let(:username) { 'testuser' } - let(:discover_payload) { { 'username' => username } } - let(:api) { double(GitlabNet) } - - before do - allow(GitlabNet).to receive(:new).and_return(api) - allow(api).to receive(:discover).with(actor).and_return(discover_payload) - end - - subject do - described_class.new(actor) - end - - describe '#execute' do - context 'with an invalid repsonse' do - it 'returns nil' do - expect($stdin).to receive(:gets).and_return("meh\n") - - expect do - expect(subject.execute(nil, nil)).to be_nil - end.to output(/New recovery codes have \*not\* been generated/).to_stdout - end - end - - context 'with a negative response' do - before do - expect(subject).to receive(:continue?).and_return(false) - end - - it 'returns nil' do - expect do - expect(subject.execute(nil, nil)).to be_nil - end.to output(/New recovery codes have \*not\* been generated/).to_stdout - end - end - - - context 'with an affirmative response' do - let(:recovery_codes) { %w{ 8dfe0f433208f40b289904c6072e4a72 c33cee7fd0a73edb56e61b785e49af03 } } - - before do - expect(subject).to receive(:continue?).and_return(true) - expect(api).to receive(:two_factor_recovery_codes).with(actor).and_return(response) - end - - context 'with a unsuccessful response' do - let(:response) { { 'success' => false } } - - it 'puts error message to stdout' do - expect do - expect(subject.execute(nil, nil)).to be_falsey - end.to output(/An error occurred while trying to generate new recovery codes/).to_stdout - end - end - - context 'with a successful response' do - let(:response) { { 'success' => true, 'recovery_codes' => recovery_codes } } - - it 'puts information message including recovery codes to stdout' do - expect do - expect(subject.execute(nil, nil)).to be_truthy - end.to output(Regexp.new(recovery_codes.join("\n"))).to_stdout - end - end - end - end -end diff --git a/spec/action/base_spec.rb b/spec/action/base_spec.rb deleted file mode 100644 index e986378..0000000 --- a/spec/action/base_spec.rb +++ /dev/null @@ -1,12 +0,0 @@ -require_relative '../spec_helper' -require_relative '../../lib/action/base' - -describe Action::Base do - describe '.create_from_json' do - it 'raises a NotImplementedError exeption' do - expect do - described_class.create_from_json('nomatter') - end.to raise_error(NotImplementedError) - end - end -end diff --git a/spec/action/git_lfs_authenticate_spec.rb b/spec/action/git_lfs_authenticate_spec.rb deleted file mode 100644 index 07e844f..0000000 --- a/spec/action/git_lfs_authenticate_spec.rb +++ /dev/null @@ -1,48 +0,0 @@ -require_relative '../spec_helper' -require_relative '../../lib/action/git_lfs_authenticate' - -describe Action::GitLFSAuthenticate do - let(:key_id) { '1' } - let(:repo_name) { 'gitlab-ci.git' } - let(:actor) { Actor::Key.new(key_id) } - let(:username) { 'testuser' } - let(:discover_payload) { { 'username' => username } } - let(:api) { double(GitlabNet) } - - before do - allow(GitlabNet).to receive(:new).and_return(api) - allow(api).to receive(:discover).with(actor).and_return(discover_payload) - end - - subject do - described_class.new(actor, repo_name) - end - - describe '#execute' do - context 'when response from API is not a success' do - before do - expect(api).to receive(:lfs_authenticate).with(actor, repo_name).and_return(nil) - end - - it 'returns nil' do - expect(subject.execute(nil, nil)).to be_nil - end - end - - context 'when response from API is a success' do - let(:username) { 'testuser' } - let(:lfs_token) { '1234' } - let(:repository_http_path) { "/tmp/#{repo_name}" } - let(:gitlab_lfs_authentication) { GitlabLfsAuthentication.new(username, lfs_token, repository_http_path) } - - before do - expect(api).to receive(:lfs_authenticate).with(actor, repo_name).and_return(gitlab_lfs_authentication) - end - - it 'puts payload to stdout' do - expect($stdout).to receive(:puts).with('{"header":{"Authorization":"Basic dGVzdHVzZXI6MTIzNA=="},"href":"/tmp/gitlab-ci.git/info/lfs/"}') - expect(subject.execute(nil, nil)).to be_truthy - end - end - end -end diff --git a/spec/action/gitaly_spec.rb b/spec/action/gitaly_spec.rb deleted file mode 100644 index a5f6f0b..0000000 --- a/spec/action/gitaly_spec.rb +++ /dev/null @@ -1,137 +0,0 @@ -require_relative '../spec_helper' -require_relative '../../lib/action/gitaly' - -describe Action::Gitaly do - let(:git_trace_log_file_valid) { '/tmp/git_trace_performance.log' } - let(:git_trace_log_file_invalid) { "/bleep-bop#{git_trace_log_file_valid}" } - let(:git_trace_log_file_relative) { "..#{git_trace_log_file_valid}" } - let(:key_id) { '1' } - let(:key_str) { 'key-1' } - let(:key) { Actor::Key.new(key_id) } - let(:gl_repository) { 'project-1' } - let(:gl_username) { 'testuser' } - let(:git_protocol) { 'version=2' } - let(:tmp_repos_path) { File.join(ROOT_PATH, 'tmp', 'repositories') } - let(:repo_name) { 'gitlab-ci.git' } - let(:repository_path) { File.join(tmp_repos_path, repo_name) } - let(:gitaly_address) { 'unix:gitaly.socket' } - let(:gitaly_token) { '123456' } - let(:gitaly) do - { - 'repository' => { 'relative_path' => repo_name, 'storage_name' => 'default' }, - 'address' => gitaly_address, - 'token' => gitaly_token - } - end - - describe '.create_from_json' do - it 'returns an instance of Action::Gitaly' do - json = { - "gl_repository" => gl_repository, - "gl_username" => gl_username, - "repository_path" => repository_path, - "gitaly" => gitaly - } - expect(described_class.create_from_json(key_id, json)).to be_instance_of(Action::Gitaly) - end - end - - subject do - described_class.new(key, gl_repository, gl_username, git_protocol, repository_path, gitaly) - end - - describe '#execute' do - let(:args) { [ repository_path ] } - let(:base_exec_env) do - { - 'HOME' => ENV['HOME'], - 'PATH' => ENV['PATH'], - 'LD_LIBRARY_PATH' => ENV['LD_LIBRARY_PATH'], - 'LANG' => ENV['LANG'], - 'GL_ID' => key_str, - 'GL_PROTOCOL' => GitlabNet::GL_PROTOCOL, - 'GL_REPOSITORY' => gl_repository, - 'GL_USERNAME' => gl_username, - 'GITALY_TOKEN' => gitaly_token, - } - end - let(:with_trace_exec_env) do - base_exec_env.merge({ - 'GIT_TRACE' => git_trace_log_file, - 'GIT_TRACE_PACKET' => git_trace_log_file, - 'GIT_TRACE_PERFORMANCE' => git_trace_log_file - }) - end - let(:gitaly_request) do - { - 'repository' => gitaly['repository'], - 'gl_repository' => gl_repository, - 'gl_id' => key_str, - 'gl_username' => gl_username, - 'git_protocol' => git_protocol - } - end - - context 'for migrated commands' do - context 'such as git-upload-pack' do - let(:git_trace_log_file) { nil } - let(:command) { 'git-upload-pack' } - - before do - allow_any_instance_of(GitlabConfig).to receive(:git_trace_log_file).and_return(git_trace_log_file) - end - - context 'with an invalid config.git_trace_log_file' do - let(:git_trace_log_file) { git_trace_log_file_invalid } - - it 'returns true' do - expect(Kernel).to receive(:exec).with( - base_exec_env, - described_class::MIGRATED_COMMANDS[command], - gitaly_address, - JSON.dump(gitaly_request), - unsetenv_others: true, - chdir: ROOT_PATH - ).and_return(true) - - expect(subject.execute(command, args)).to be_truthy - end - end - - context 'with n relative config.git_trace_log_file' do - let(:git_trace_log_file) { git_trace_log_file_relative } - - it 'returns true' do - expect(Kernel).to receive(:exec).with( - base_exec_env, - described_class::MIGRATED_COMMANDS[command], - gitaly_address, - JSON.dump(gitaly_request), - unsetenv_others: true, - chdir: ROOT_PATH - ).and_return(true) - - expect(subject.execute(command, args)).to be_truthy - end - end - - context 'with a valid config.git_trace_log_file' do - let(:git_trace_log_file) { git_trace_log_file_valid } - - it 'returns true' do - expect(Kernel).to receive(:exec).with( - with_trace_exec_env, - described_class::MIGRATED_COMMANDS[command], - gitaly_address, - JSON.dump(gitaly_request), - unsetenv_others: true, - chdir: ROOT_PATH - ).and_return(true) - - expect(subject.execute(command, args)).to be_truthy - end - end - end - end - end -end |