diff options
author | Nick Thomas <nick@gitlab.com> | 2019-03-15 17:16:17 +0000 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2019-03-15 17:16:17 +0000 |
commit | f237aba6df1c1873f1f9d5ba18c3b8924d85cb51 (patch) | |
tree | 22d69b9450693bb153e58dbe8b7cd6feb3f8e1e0 /spec/gitlab_shell_gitlab_shell_spec.rb | |
parent | 049beb74303a03d9fa598d23b150e0ccea3cd60d (diff) | |
parent | 83c0f18e1de04b3bad9c424084e738e911c47336 (diff) | |
download | gitlab-shell-f237aba6df1c1873f1f9d5ba18c3b8924d85cb51.tar.gz |
Merge branch 'bvl-discover-command' into 'master'
Call gitlab "/internal/discover" from go
Closes #175
See merge request gitlab-org/gitlab-shell!283
Diffstat (limited to 'spec/gitlab_shell_gitlab_shell_spec.rb')
-rw-r--r-- | spec/gitlab_shell_gitlab_shell_spec.rb | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/spec/gitlab_shell_gitlab_shell_spec.rb b/spec/gitlab_shell_gitlab_shell_spec.rb index 11692d3..cb3fd9c 100644 --- a/spec/gitlab_shell_gitlab_shell_spec.rb +++ b/spec/gitlab_shell_gitlab_shell_spec.rb @@ -30,12 +30,19 @@ describe 'bin/gitlab-shell' do @server = HTTPUNIXServer.new(BindAddress: tmp_socket_path) @server.mount_proc('/api/v4/internal/discover') do |req, res| - if req.query['key_id'] == '100' || - req.query['user_id'] == '10' || - req.query['username'] == 'someuser' + identifier = req.query['key_id'] || req.query['username'] || req.query['user_id'] + known_identifiers = %w(10 someuser 100) + if known_identifiers.include?(identifier) res.status = 200 res.content_type = 'application/json' res.body = '{"id":1, "name": "Some User", "username": "someuser"}' + elsif identifier == 'broken_message' + res.status = 401 + res.body = '{"message": "Forbidden!"}' + elsif identifier && identifier != 'broken' + res.status = 200 + res.content_type = 'application/json' + res.body = 'null' else res.status = 500 end @@ -145,11 +152,7 @@ describe 'bin/gitlab-shell' do ) end - it_behaves_like 'results with keys' do - before do - pending - end - 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: {}) @@ -157,6 +160,20 @@ describe 'bin/gitlab-shell' do expect(stderr).to eq("Only ssh allowed\n") expect(status).not_to be_success end + + it 'returns an error message when the API call fails with a message' do + _, stderr, status = run!(["-c/usr/share/webapps/gitlab-shell/bin/gitlab-shell", "username-broken_message"]) + + expect(stderr).to match(/Failed to get username: Forbidden!/) + expect(status).not_to be_success + end + + it 'returns an error message when the API call fails without a message' do + _, stderr, status = run!(["-c/usr/share/webapps/gitlab-shell/bin/gitlab-shell", "username-broken"]) + + expect(stderr).to match(/Failed to get username: Internal API error \(500\)/) + expect(status).not_to be_success + end end def run!(args, env: {'SSH_CONNECTION' => 'fake'}) |