summaryrefslogtreecommitdiff
path: root/spec/gitlab_shell_spec.rb
diff options
context:
space:
mode:
authorDrew Blessing <drew@gitlab.com>2016-08-20 13:07:00 -0500
committerDrew Blessing <drew@gitlab.com>2016-08-26 15:10:31 -0500
commitdcc20876554ae18c6869b80071728f1b91858c5f (patch)
tree5e5dc709238c54a8e5213cd11f577751fc744ef8 /spec/gitlab_shell_spec.rb
parent3043b31c458bf720843a84b35c9fbad5c1488c1d (diff)
downloadgitlab-shell-dcc20876554ae18c6869b80071728f1b91858c5f.tar.gz
Add option to recover 2FA via SSH
Diffstat (limited to 'spec/gitlab_shell_spec.rb')
-rw-r--r--spec/gitlab_shell_spec.rb66
1 files changed, 63 insertions, 3 deletions
diff --git a/spec/gitlab_shell_spec.rb b/spec/gitlab_shell_spec.rb
index 0b0a817..ea11652 100644
--- a/spec/gitlab_shell_spec.rb
+++ b/spec/gitlab_shell_spec.rb
@@ -23,6 +23,10 @@ describe GitlabShell do
double(GitlabNet).tap do |api|
api.stub(discover: { 'name' => 'John Doe' })
api.stub(check_access: GitAccessStatus.new(true, 'ok', repo_path))
+ api.stub(two_factor_recovery_codes: {
+ 'success' => true,
+ 'recovery_codes' => ['f67c514de60c4953', '41278385fc00c1e0']
+ })
end
end
@@ -53,7 +57,7 @@ describe GitlabShell do
end
its(:repo_name) { should == 'gitlab-ci.git' }
- its(:git_cmd) { should == 'git-upload-pack' }
+ its(:command) { should == 'git-upload-pack' }
end
context 'namespace' do
@@ -65,7 +69,7 @@ describe GitlabShell do
end
its(:repo_name) { should == 'dmitriy.zaporozhets/gitlab-ci.git' }
- its(:git_cmd) { should == 'git-upload-pack' }
+ its(:command) { should == 'git-upload-pack' }
end
context 'with an invalid number of arguments' do
@@ -75,6 +79,24 @@ describe GitlabShell do
expect { subject.send :parse_cmd, ssh_args }.to raise_error(GitlabShell::DisallowedCommandError)
end
end
+
+ context 'with an API command' do
+ before do
+ subject.send :parse_cmd, ssh_args
+ end
+
+ context 'when generating recovery codes' do
+ let(:ssh_args) { %w(2fa_recovery_codes) }
+
+ it 'sets the correct command' do
+ expect(subject.command).to eq('2fa_recovery_codes')
+ end
+
+ it 'does not set repo name' do
+ expect(subject.repo_name).to be_nil
+ end
+ end
+ end
end
describe 'git-annex' do
@@ -88,7 +110,7 @@ describe GitlabShell do
end
its(:repo_name) { should == 'dzaporozhets/gitlab.git' }
- its(:git_cmd) { should == 'git-annex-shell' }
+ its(:command) { should == 'git-annex-shell' }
end
end
@@ -233,6 +255,44 @@ describe GitlabShell do
end
end
end
+
+ context 'with an API command' do
+ before do
+ allow(subject).to receive(:continue?).and_return(true)
+ end
+
+ context 'when generating recovery codes' do
+ let(:ssh_cmd) { '2fa_recovery_codes' }
+ after do
+ subject.exec(ssh_cmd)
+ end
+
+ it 'does not call verify_access' do
+ expect(subject).not_to receive(:verify_access)
+ end
+
+ it 'calls the corresponding method' do
+ expect(subject).to receive(:api_2fa_recovery_codes)
+ end
+
+ it 'outputs recovery codes' do
+ expect($stdout).to receive(:puts)
+ .with(/f67c514de60c4953\n41278385fc00c1e0/)
+ end
+
+ context 'when the process is unsuccessful' do
+ it 'displays the error to the user' do
+ api.stub(two_factor_recovery_codes: {
+ 'success' => false,
+ 'message' => 'Could not find the given key'
+ })
+
+ expect($stdout).to receive(:puts)
+ .with(/Could not find the given key/)
+ end
+ end
+ end
+ end
end
describe :validate_access do