Commit 1ff35618 authored by Ash McKenzie's avatar Ash McKenzie

GitlabAccessStatus needs HTTP response status code

parent ca93c218
...@@ -3,8 +3,9 @@ require 'json' ...@@ -3,8 +3,9 @@ require 'json'
class GitAccessStatus class GitAccessStatus
attr_reader :message, :gl_repository, :gl_id, :gl_username, :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: nil, gl_id: nil, gl_username: nil, gitaly: nil, git_protocol: nil, git_config_options: nil) def initialize(status, status_code, message, gl_repository: nil, gl_id: nil, gl_username: nil, gitaly: nil, git_protocol: nil, git_config_options: nil)
@status = status @status = status
@status_code = status_code
@message = message @message = message
@gl_repository = gl_repository @gl_repository = gl_repository
@gl_id = gl_id @gl_id = gl_id
...@@ -14,9 +15,10 @@ class GitAccessStatus ...@@ -14,9 +15,10 @@ class GitAccessStatus
@git_protocol = git_protocol @git_protocol = git_protocol
end end
def self.create_from_json(json) def self.create_from_json(json, status_code)
values = JSON.parse(json) values = JSON.parse(json)
new(values["status"], new(values["status"],
status_code,
values["message"], values["message"],
gl_repository: values["gl_repository"], gl_repository: values["gl_repository"],
gl_id: values["gl_id"], gl_id: values["gl_id"],
......
...@@ -8,6 +8,7 @@ describe GitlabAccess do ...@@ -8,6 +8,7 @@ describe GitlabAccess do
let(:api) do let(:api) do
double(GitlabNet).tap do |api| double(GitlabNet).tap do |api|
allow(api).to receive(:check_access).and_return(GitAccessStatus.new(true, allow(api).to receive(:check_access).and_return(GitAccessStatus.new(true,
HTTPCodes::HTTP_SUCCESS,
'ok', 'ok',
gl_repository: 'project-1', gl_repository: 'project-1',
gl_id: 'user-123', gl_id: 'user-123',
...@@ -45,6 +46,7 @@ describe GitlabAccess do ...@@ -45,6 +46,7 @@ describe GitlabAccess do
before do before do
allow(api).to receive(:check_access).and_return(GitAccessStatus.new( allow(api).to receive(:check_access).and_return(GitAccessStatus.new(
false, false,
HTTPCodes::HTTP_UNAUTHORIZED,
'denied', 'denied',
gl_repository: nil, gl_repository: nil,
gl_id: nil, gl_id: nil,
......
...@@ -22,23 +22,26 @@ describe GitlabShell do ...@@ -22,23 +22,26 @@ describe GitlabShell do
let(:git_config_options) { ['receive.MaxInputSize=10000'] } let(:git_config_options) { ['receive.MaxInputSize=10000'] }
let(:gitaly_check_access) { GitAccessStatus.new( let(:gitaly_check_access) do
true, GitAccessStatus.new(
'ok', true,
gl_repository: gl_repository, HTTPCodes::HTTP_SUCCESS,
gl_id: gl_id, 'ok',
gl_username: gl_username, gl_repository: gl_repository,
git_config_options: git_config_options, gl_id: gl_id,
gitaly: { 'repository' => { 'relative_path' => repo_name, 'storage_name' => 'default'} , 'address' => 'unix:gitaly.socket' }, gl_username: gl_username,
git_protocol: git_protocol git_config_options: git_config_options,
) gitaly: { 'repository' => { 'relative_path' => repo_name, 'storage_name' => 'default'} , 'address' => 'unix:gitaly.socket' },
} git_protocol: git_protocol
)
end
let(:api) do let(:api) do
double(GitlabNet).tap do |api| double(GitlabNet).tap do |api|
allow(api).to receive(:discover).and_return({ 'name' => 'John Doe', 'username' => 'testuser' }) allow(api).to receive(:discover).and_return({ 'name' => 'John Doe', 'username' => 'testuser' })
allow(api).to receive(:check_access).and_return(GitAccessStatus.new( allow(api).to receive(:check_access).and_return(GitAccessStatus.new(
true, true,
HTTPCodes::HTTP_SUCCESS,
'ok', 'ok',
gl_repository: gl_repository, gl_repository: gl_repository,
gl_id: gl_id, gl_id: gl_id,
......
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