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

GitlabAccessStatus needs HTTP response status code

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