mirror of
https://github.com/internetee/registry.git
synced 2025-08-16 22:43:50 +02:00
refactoring 2.0
This commit is contained in:
parent
7fbbdcb5a3
commit
8f8b97a6ba
2 changed files with 16 additions and 11 deletions
|
@ -19,23 +19,15 @@ module Repp
|
||||||
desc 'Submit a new api user certificate signing request'
|
desc 'Submit a new api user certificate signing request'
|
||||||
def create
|
def create
|
||||||
@api_user = current_user.registrar.api_users.find(cert_params[:api_user_id])
|
@api_user = current_user.registrar.api_users.find(cert_params[:api_user_id])
|
||||||
|
|
||||||
csr = decode_cert_params(cert_params[:csr])
|
csr = decode_cert_params(cert_params[:csr])
|
||||||
|
|
||||||
@certificate = @api_user.certificates.build(csr: csr)
|
|
||||||
|
|
||||||
if csr.blank?
|
if csr.blank?
|
||||||
@certificate.errors.add(:base, I18n.t(:crt_or_csr_must_be_present))
|
@certificate.errors.add(:base, I18n.t(:crt_or_csr_must_be_present))
|
||||||
return handle_non_epp_errors(@certificate)
|
return handle_non_epp_errors(@certificate)
|
||||||
end
|
end
|
||||||
|
|
||||||
if Rails.env.test? && cert_params[:csr][:body] != 'invalid'
|
|
||||||
result = @certificate.save(validate: false)
|
|
||||||
else
|
|
||||||
result = @certificate.save
|
|
||||||
end
|
|
||||||
|
|
||||||
if result
|
@certificate = @api_user.certificates.build(csr: csr)
|
||||||
|
if @certificate.save
|
||||||
notify_admins
|
notify_admins
|
||||||
render_success(data: { api_user: { id: @api_user.id } })
|
render_success(data: { api_user: { id: @api_user.id } })
|
||||||
else
|
else
|
||||||
|
|
|
@ -10,12 +10,23 @@ class ReppV1CertificatesCreateTest < ActionDispatch::IntegrationTest
|
||||||
|
|
||||||
adapter = ENV['shunter_default_adapter'].constantize.new
|
adapter = ENV['shunter_default_adapter'].constantize.new
|
||||||
adapter&.clear!
|
adapter&.clear!
|
||||||
|
|
||||||
|
@user.registrar.update!(address_country_code: 'ET',vat_rate: 22)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_creates_new_api_user_certificate_and_informs_admins
|
def test_creates_new_api_user_certificate_and_informs_admins
|
||||||
|
original_username = @user.username
|
||||||
|
@user.update!(username: 'host.ee') && @user.reload
|
||||||
|
|
||||||
|
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
|
||||||
|
headers = { 'Authorization' => "Basic #{token}" }
|
||||||
|
|
||||||
assert_difference('Certificate.count') do
|
assert_difference('Certificate.count') do
|
||||||
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
|
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
|
||||||
post repp_v1_certificates_path, headers: @auth_headers, params: request_body
|
post repp_v1_certificates_path, headers: headers, params: request_body
|
||||||
|
|
||||||
|
puts "Response status: #{response.status}"
|
||||||
|
puts "Response body: #{response.body}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
json = JSON.parse(response.body, symbolize_names: true)
|
json = JSON.parse(response.body, symbolize_names: true)
|
||||||
|
@ -23,6 +34,8 @@ class ReppV1CertificatesCreateTest < ActionDispatch::IntegrationTest
|
||||||
assert_response :ok
|
assert_response :ok
|
||||||
assert_equal 1000, json[:code]
|
assert_equal 1000, json[:code]
|
||||||
assert_equal 'Command completed successfully', json[:message]
|
assert_equal 'Command completed successfully', json[:message]
|
||||||
|
|
||||||
|
@user.update!(username: original_username)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_return_error_when_invalid_certificate
|
def test_return_error_when_invalid_certificate
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue