mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 06:34:46 +02:00
Use errors as first-class objects
This commit is contained in:
parent
72c865e656
commit
d4775ba5c5
8 changed files with 146 additions and 186 deletions
|
@ -20,10 +20,9 @@ module Epp
|
|||
|
||||
server_md5 = Certificate.parse_md_from_string(File.read(ENV['cert_path']))
|
||||
if client_md5 != server_md5
|
||||
epp_errors << {
|
||||
msg: 'Authentication error; server closing connection (certificate is not valid)',
|
||||
code: '2501'
|
||||
}
|
||||
epp_errors.add(:epp_errors,
|
||||
msg: 'Authentication error; server closing connection (certificate is not valid)',
|
||||
code: '2501')
|
||||
|
||||
success = false
|
||||
end
|
||||
|
@ -32,56 +31,50 @@ module Epp
|
|||
if !Rails.env.development? && (!webclient_request && @api_user)
|
||||
unless @api_user.pki_ok?(request.env['HTTP_SSL_CLIENT_CERT'],
|
||||
request.env['HTTP_SSL_CLIENT_S_DN_CN'])
|
||||
epp_errors << {
|
||||
msg: 'Authentication error; server closing connection (certificate is not valid)',
|
||||
code: '2501'
|
||||
}
|
||||
epp_errors.add(:epp_errors,
|
||||
msg: 'Authentication error; server closing connection (certificate is not valid)',
|
||||
code: '2501')
|
||||
|
||||
success = false
|
||||
end
|
||||
end
|
||||
|
||||
if success && !@api_user
|
||||
epp_errors << {
|
||||
msg: 'Authentication error; server closing connection (API user not found)',
|
||||
code: '2501'
|
||||
}
|
||||
epp_errors.add(:epp_errors,
|
||||
msg: 'Authentication error; server closing connection (API user not found)',
|
||||
code: '2501')
|
||||
|
||||
success = false
|
||||
end
|
||||
|
||||
if success && !@api_user.try(:active)
|
||||
epp_errors << {
|
||||
msg: 'Authentication error; server closing connection (API user is not active)',
|
||||
code: '2501'
|
||||
}
|
||||
epp_errors.add(:epp_errors,
|
||||
msg: 'Authentication error; server closing connection (API user is not active)',
|
||||
code: '2501')
|
||||
|
||||
success = false
|
||||
end
|
||||
|
||||
if success && @api_user.cannot?(:create, :epp_login)
|
||||
epp_errors << {
|
||||
msg: 'Authentication error; server closing connection (API user does not have epp role)',
|
||||
code: '2501'
|
||||
}
|
||||
epp_errors.add(:epp_errors,
|
||||
msg: 'Authentication error; server closing connection (API user does not have epp role)',
|
||||
code: '2501')
|
||||
|
||||
success = false
|
||||
end
|
||||
|
||||
if success && !ip_white?
|
||||
epp_errors << {
|
||||
msg: 'Authentication error; server closing connection (IP is not whitelisted)',
|
||||
code: '2501'
|
||||
}
|
||||
epp_errors.add(:epp_errors,
|
||||
msg: 'Authentication error; server closing connection (IP is not whitelisted)',
|
||||
code: '2501')
|
||||
|
||||
success = false
|
||||
end
|
||||
|
||||
if success && EppSession.limit_reached?(@api_user.registrar)
|
||||
epp_errors << {
|
||||
msg: 'Session limit exceeded; server closing connection (connection limit reached)',
|
||||
code: '2502',
|
||||
}
|
||||
epp_errors.add(:epp_errors,
|
||||
msg: 'Session limit exceeded; server closing connection (connection limit reached)',
|
||||
code: '2502')
|
||||
|
||||
success = false
|
||||
end
|
||||
|
@ -98,10 +91,9 @@ module Epp
|
|||
already_authenticated = EppSession.exists?(session_id: epp_session_id)
|
||||
|
||||
if already_authenticated
|
||||
epp_errors << {
|
||||
msg: 'Command use error; Already authenticated',
|
||||
code: 2002,
|
||||
}
|
||||
epp_errors.add(:epp_errors,
|
||||
msg: 'Command use error; Already authenticated',
|
||||
code: 2002)
|
||||
handle_errors
|
||||
return
|
||||
end
|
||||
|
@ -127,10 +119,9 @@ module Epp
|
|||
|
||||
def logout
|
||||
unless signed_in?
|
||||
epp_errors << {
|
||||
code: 2201,
|
||||
msg: 'Authorization error'
|
||||
}
|
||||
epp_errors.add(:epp_errors,
|
||||
code: 2201,
|
||||
msg: 'Authorization error')
|
||||
handle_errors
|
||||
return
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue