internetee-registry/app/controllers/repp/v1/certificates/p12_controller.rb
oleghasjanov 0fe20bd63b Fixed Certificate#update_crl test to properly verify CRL updater script call
The test for Certificate.update_crl was failing because it didn't correctly
match how the system method is called in the CertificateConcern module.
The implementation calls system with '/bin/bash' as the first argument
and the crl_updater_path as the second argument, but the test was
expecting different parameters.

- Simplified the test_update_crl_should_call_crl_updater_script test to
  directly verify the script path is used without trying to intercept
  the system call
- Added proper environment variable handling for crl_updater_path
- Ensured original method is restored after test execution
2025-04-16 11:47:52 +03:00

43 lines
1.4 KiB
Ruby

module Repp
module V1
module Certificates
class P12Controller < BaseController
load_and_authorize_resource param_method: :cert_params
THROTTLED_ACTIONS = %i[create].freeze
include Shunter::Integration::Throttle
api :POST, '/repp/v1/certificates/p12'
desc 'Generate a P12 certificate'
def create
api_user_id = cert_params[:api_user_id]
render_error(I18n.t('errors.messages.not_found'), :not_found) and return if api_user_id.blank?
api_user = current_user.registrar.api_users.find(api_user_id)
interface = cert_params[:interface].presence || 'api'
# Validate interface
unless Certificate::INTERFACES.include?(interface)
render_error(I18n.t('errors.invalid_interface'), :unprocessable_entity) and return
end
certificate = Certificate.generate_for_api_user(api_user: api_user, interface: interface)
render_success(data: {
certificate: {
id: certificate.id,
common_name: certificate.common_name,
expires_at: certificate.expires_at,
interface: certificate.interface
}
})
end
private
def cert_params
params.require(:certificate).permit(:api_user_id, :interface)
end
end
end
end
end