Commit 2467697d authored by Jacob Vosmaer's avatar Jacob Vosmaer

Simplify the GitAccessStatus class

Make the optional 'message' argument required. Remove unused 'to_json'
method.
parent c6f14956
require 'json' require 'json'
class GitAccessStatus class GitAccessStatus
attr_accessor :status, :message attr_reader :message
alias_method :allowed?, :status
def initialize(status, message = '') def initialize(status, message)
@status = status @status = status
@message = message @message = message
end end
...@@ -14,7 +13,7 @@ class GitAccessStatus ...@@ -14,7 +13,7 @@ class GitAccessStatus
self.new(values["status"], values["message"]) self.new(values["status"], values["message"])
end end
def to_json def allowed?
{ status: @status, message: @message }.to_json @status
end end
end end
...@@ -7,7 +7,7 @@ describe GitlabAccess do ...@@ -7,7 +7,7 @@ describe GitlabAccess do
let(:repo_path) { File.join(repository_path, repo_name) + ".git" } let(:repo_path) { File.join(repository_path, repo_name) + ".git" }
let(:api) do let(:api) do
double(GitlabNet).tap do |api| double(GitlabNet).tap do |api|
api.stub(check_access: GitAccessStatus.new(true)) api.stub(check_access: GitAccessStatus.new(true, 'ok'))
end end
end end
subject do subject do
...@@ -38,7 +38,7 @@ describe GitlabAccess do ...@@ -38,7 +38,7 @@ describe GitlabAccess do
context "access is denied" do context "access is denied" do
before do before do
api.stub(check_access: GitAccessStatus.new(false)) api.stub(check_access: GitAccessStatus.new(false, 'denied'))
end end
it "returns false" do it "returns false" do
......
...@@ -22,7 +22,7 @@ describe GitlabShell do ...@@ -22,7 +22,7 @@ describe GitlabShell do
let(:api) do let(:api) do
double(GitlabNet).tap do |api| double(GitlabNet).tap do |api|
api.stub(discover: { 'name' => 'John Doe' }) api.stub(discover: { 'name' => 'John Doe' })
api.stub(check_access: GitAccessStatus.new(true)) api.stub(check_access: GitAccessStatus.new(true, 'ok'))
end end
end end
...@@ -230,7 +230,7 @@ describe GitlabShell do ...@@ -230,7 +230,7 @@ describe GitlabShell do
end end
it "should disallow access and log the attempt if check_access returns false status" do 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 = "gitlab-shell: Access denied for git command <git-upload-pack gitlab-ci.git> "
message << "by user with key #{key_id}." message << "by user with key #{key_id}."
$logger.should_receive(:warn).with(message) $logger.should_receive(:warn).with(message)
......
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