summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsh McKenzie <amckenzie@gitlab.com>2018-08-20 14:44:05 +1000
committerAsh McKenzie <amckenzie@gitlab.com>2018-09-07 15:37:44 +1000
commit1ff3561895f361b79f46a059880ea122e3500d08 (patch)
tree9ddb7dd123af25567870b89fbf9b4402950654d6
parentca93c218228cee959253a3d7ce53926e07654a45 (diff)
downloadgitlab-shell-1ff3561895f361b79f46a059880ea122e3500d08.tar.gz
GitlabAccessStatus needs HTTP response status code
-rw-r--r--lib/gitlab_access_status.rb6
-rw-r--r--spec/gitlab_access_spec.rb2
-rw-r--r--spec/gitlab_shell_spec.rb25
3 files changed, 20 insertions, 13 deletions
diff --git a/lib/gitlab_access_status.rb b/lib/gitlab_access_status.rb
index bc9b98b..68fbba1 100644
--- a/lib/gitlab_access_status.rb
+++ b/lib/gitlab_access_status.rb
@@ -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"],
diff --git a/spec/gitlab_access_spec.rb b/spec/gitlab_access_spec.rb
index a4f633d..c9922dd 100644
--- a/spec/gitlab_access_spec.rb
+++ b/spec/gitlab_access_spec.rb
@@ -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,
diff --git a/spec/gitlab_shell_spec.rb b/spec/gitlab_shell_spec.rb
index 22b21fd..24fe151 100644
--- a/spec/gitlab_shell_spec.rb
+++ b/spec/gitlab_shell_spec.rb
@@ -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,