diff --git a/app/controllers/repp/v1/certificates_controller.rb b/app/controllers/repp/v1/certificates_controller.rb index 707bb1f9a..f42eb56df 100644 --- a/app/controllers/repp/v1/certificates_controller.rb +++ b/app/controllers/repp/v1/certificates_controller.rb @@ -19,23 +19,15 @@ module Repp desc 'Submit a new api user certificate signing request' def create @api_user = current_user.registrar.api_users.find(cert_params[:api_user_id]) - csr = decode_cert_params(cert_params[:csr]) - @certificate = @api_user.certificates.build(csr: csr) - if csr.blank? @certificate.errors.add(:base, I18n.t(:crt_or_csr_must_be_present)) return handle_non_epp_errors(@certificate) 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 render_success(data: { api_user: { id: @api_user.id } }) else diff --git a/test/integration/repp/v1/certificates/create_test.rb b/test/integration/repp/v1/certificates/create_test.rb index 7ead82706..97813391b 100644 --- a/test/integration/repp/v1/certificates/create_test.rb +++ b/test/integration/repp/v1/certificates/create_test.rb @@ -10,12 +10,23 @@ class ReppV1CertificatesCreateTest < ActionDispatch::IntegrationTest adapter = ENV['shunter_default_adapter'].constantize.new adapter&.clear! + + @user.registrar.update!(address_country_code: 'ET',vat_rate: 22) end 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 '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 json = JSON.parse(response.body, symbolize_names: true) @@ -23,6 +34,8 @@ class ReppV1CertificatesCreateTest < ActionDispatch::IntegrationTest assert_response :ok assert_equal 1000, json[:code] assert_equal 'Command completed successfully', json[:message] + + @user.update!(username: original_username) end def test_return_error_when_invalid_certificate