Commit 22c6951d authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg

Fix handling non 200 response codes

After the cleanup in https://gitlab.com/gitlab-org/gitlab-shell/merge_requests/231
gitlab-shell mishandled the non 200 response codes. This commit removes
another few lines of codes, which fixes this. Also now we test against
this case through mocking.

Fixes https://gitlab.com/gitlab-org/gitlab-shell/issues/152
parent 306b6b5b
require 'json'
class GitAccessStatus
attr_reader :message, :gl_repository, :gl_id, :gl_username, :repository_path, :gitaly, :git_protocol, :git_config_options
attr_reader :message, :gl_repository, :gl_id, :gl_username, :gitaly, :git_protocol, :git_config_options
def initialize(status, message, gl_repository:, gl_id:, gl_username:, gitaly:, git_protocol:, git_config_options:)
@status = status
......
......@@ -44,7 +44,6 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
gl_id: nil,
gl_username: nil,
git_config_options: nil,
repository_path: nil,
gitaly: nil,
git_protocol: nil)
end
......
......@@ -347,6 +347,15 @@ describe GitlabNet, vcr: true do
end
end
it 'handles non 200 status codes' do
resp = double(:resp, code: 501)
allow(gitlab_net).to receive(:post).and_return(resp)
access = gitlab_net.check_access('git-upload-pack', nil, project, 'user-2', changes, 'ssh')
expect(access).not_to be_allowed
end
it "raises an exception if the connection fails" do
allow_any_instance_of(Net::HTTP).to receive(:request).and_raise(StandardError)
expect {
......
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