Commit f6330a06 authored by Stan Hu's avatar Stan Hu

Merge branch '220561-fix-invalid-project-path-response-in-go-middleware' into 'master'

Handle the blacklisted IP error in the Go middleware

See merge request gitlab-org/gitlab!44614
parents ce2fc1e2 940e74f8
---
title: Handle the blacklisted ip error in the Go middleware
merge_request: 44614
author:
type: changed
......@@ -18,6 +18,15 @@ module Gitlab
request = ActionDispatch::Request.new(env)
render_go_doc(request) || @app.call(env)
rescue Gitlab::Auth::IpBlacklisted
Gitlab::AuthLogger.error(
message: 'Rack_Attack',
env: :blocklist,
remote_ip: request.ip,
request_method: request.request_method,
path: request.fullpath
)
Rack::Response.new('', 403).finish
end
private
......
......@@ -135,6 +135,17 @@ RSpec.describe Gitlab::Middleware::Go do
it_behaves_like 'unauthorized'
end
context 'with a blacklisted ip' do
it 'returns forbidden' do
expect(Gitlab::Auth).to receive(:find_for_git_client).and_raise(Gitlab::Auth::IpBlacklisted)
response = go
expect(response[0]).to eq(403)
expect(response[1]['Content-Length']).to eq('0')
expect(response[2].body).to eq([''])
end
end
end
end
end
......
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