summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2016-06-23 09:35:51 +0000
committerValery Sizov <valery@gitlab.com>2016-06-23 09:35:51 +0000
commitf2325a45c1ce4e6685f61a6e5d1ef0f351e34a18 (patch)
treec8aae6ffcab759a07102913bfafa705d62fba223
parentf9e59b36016c3d696b4e798c0642874e2f8f76ec (diff)
parent2467697d81e4ab9e9d770d55d8cb33cb5779db22 (diff)
downloadgitlab-shell-f2325a45c1ce4e6685f61a6e5d1ef0f351e34a18.tar.gz
Merge branch 'simplify-access-status' into 'master'
Simplify the GitAccessStatus class Make the optional 'message' argument required. Remove unused 'to_json' method. See merge request !65
-rw-r--r--lib/gitlab_access_status.rb9
-rw-r--r--spec/gitlab_access_spec.rb4
-rw-r--r--spec/gitlab_shell_spec.rb4
3 files changed, 8 insertions, 9 deletions
diff --git a/lib/gitlab_access_status.rb b/lib/gitlab_access_status.rb
index 14ec1ef..7a5f7d5 100644
--- a/lib/gitlab_access_status.rb
+++ b/lib/gitlab_access_status.rb
@@ -1,10 +1,9 @@
require 'json'
class GitAccessStatus
- attr_accessor :status, :message
- alias_method :allowed?, :status
+ attr_reader :message
- def initialize(status, message = '')
+ def initialize(status, message)
@status = status
@message = message
end
@@ -14,7 +13,7 @@ class GitAccessStatus
self.new(values["status"], values["message"])
end
- def to_json
- { status: @status, message: @message }.to_json
+ def allowed?
+ @status
end
end
diff --git a/spec/gitlab_access_spec.rb b/spec/gitlab_access_spec.rb
index 4768c71..39c3ab3 100644
--- a/spec/gitlab_access_spec.rb
+++ b/spec/gitlab_access_spec.rb
@@ -7,7 +7,7 @@ describe GitlabAccess do
let(:repo_path) { File.join(repository_path, repo_name) + ".git" }
let(:api) do
double(GitlabNet).tap do |api|
- api.stub(check_access: GitAccessStatus.new(true))
+ api.stub(check_access: GitAccessStatus.new(true, 'ok'))
end
end
subject do
@@ -38,7 +38,7 @@ describe GitlabAccess do
context "access is denied" do
before do
- api.stub(check_access: GitAccessStatus.new(false))
+ api.stub(check_access: GitAccessStatus.new(false, 'denied'))
end
it "returns false" do
diff --git a/spec/gitlab_shell_spec.rb b/spec/gitlab_shell_spec.rb
index dd5cfb2..3be1671 100644
--- a/spec/gitlab_shell_spec.rb
+++ b/spec/gitlab_shell_spec.rb
@@ -22,7 +22,7 @@ describe GitlabShell do
let(:api) do
double(GitlabNet).tap do |api|
api.stub(discover: { 'name' => 'John Doe' })
- api.stub(check_access: GitAccessStatus.new(true))
+ api.stub(check_access: GitAccessStatus.new(true, 'ok'))
end
end
@@ -230,7 +230,7 @@ describe GitlabShell do
end
it "should disallow access and log the attempt if check_access returns false status" do
- api.stub(check_access: GitAccessStatus.new(false))
+ api.stub(check_access: GitAccessStatus.new(false, 'denied'))
message = "gitlab-shell: Access denied for git command <git-upload-pack gitlab-ci.git> "
message << "by user with key #{key_id}."
$logger.should_receive(:warn).with(message)