Commit b03ee4666bc5dfa3c509768918cbc8a477d24efb

Authored by randx
1 parent c48c0f95

Handle invalid ssh exception

app/controllers/application_controller.rb
... ... @@ -14,6 +14,10 @@ class ApplicationController < ActionController::Base
14 14 render "errors/gitolite", layout: "error"
15 15 end
16 16  
  17 + rescue_from Gitlab::Gitolite::InvalidKey do |exception|
  18 + render "errors/invalid_ssh_key", layout: "error"
  19 + end
  20 +
17 21 rescue_from Encoding::CompatibilityError do |exception|
18 22 render "errors/encoding", layout: "error", status: 404
19 23 end
... ...
app/views/errors/invalid_ssh_key.html.haml 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +%h1 Git Error
  2 +%hr
  3 +%p Seems like SSH Key you provided is not a valid SSH key.
... ...
lib/gitlab/backend/gitolite.rb
... ... @@ -6,6 +6,7 @@ require 'fileutils'
6 6 module Gitlab
7 7 class Gitolite
8 8 class AccessDenied < StandardError; end
  9 + class InvalidKey < StandardError; end
9 10  
10 11 def set_key key_id, key_content, projects
11 12 configure do |c|
... ... @@ -190,8 +191,12 @@ module Gitlab
190 191 end
191 192 end
192 193 rescue Exception => ex
193   - Gitlab::Logger.error(ex.message)
194   - raise Gitolite::AccessDenied.new("gitolite timeout")
  194 + if ex.message =~ /is not a valid SSH key string/
  195 + raise Gitolite::InvalidKey.new("ssh key is not valid")
  196 + else
  197 + Gitlab::Logger.error(ex.message)
  198 + raise Gitolite::AccessDenied.new("gitolite timeout")
  199 + end
195 200 end
196 201 end
197 202 end
... ...