mirror of
https://github.com/internetee/registry.git
synced 2025-08-15 22:13:54 +02:00
refactoring
This commit is contained in:
parent
5f8660adec
commit
7fbbdcb5a3
3 changed files with 0 additions and 26 deletions
|
@ -24,13 +24,11 @@ module Repp
|
|||
|
||||
@certificate = @api_user.certificates.build(csr: csr)
|
||||
|
||||
# Проверяем наличие CSR
|
||||
if csr.blank?
|
||||
@certificate.errors.add(:base, I18n.t(:crt_or_csr_must_be_present))
|
||||
return handle_non_epp_errors(@certificate)
|
||||
end
|
||||
|
||||
# В тестах пропускаем валидацию CSR параметров, но только если CSR не 'invalid'
|
||||
if Rails.env.test? && cert_params[:csr][:body] != 'invalid'
|
||||
result = @certificate.save(validate: false)
|
||||
else
|
||||
|
|
|
@ -13,21 +13,9 @@ class ReppV1CertificatesCreateTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
def test_creates_new_api_user_certificate_and_informs_admins
|
||||
# Отладка - декодируем CSR и проверяем CN
|
||||
csr_base64 = request_body[:certificate][:csr][:body]
|
||||
csr_decoded = Base64.decode64(csr_base64)
|
||||
puts "Decoded CSR: #{csr_decoded}"
|
||||
puts "User username: #{@user.username}"
|
||||
|
||||
assert_difference('Certificate.count') do
|
||||
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
|
||||
post repp_v1_certificates_path, headers: @auth_headers, params: request_body
|
||||
|
||||
# Добавляем отладочный вывод
|
||||
if response.status != 200
|
||||
puts "Response status: #{response.status}"
|
||||
puts "Response body: #{response.body}"
|
||||
end
|
||||
end
|
||||
end
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
@ -49,11 +37,6 @@ class ReppV1CertificatesCreateTest < ActionDispatch::IntegrationTest
|
|||
}
|
||||
|
||||
post repp_v1_certificates_path, headers: @auth_headers, params: request_body
|
||||
|
||||
# Отладочный вывод
|
||||
puts "Response status: #{response.status}"
|
||||
puts "Response body: #{response.body}"
|
||||
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :bad_request
|
||||
|
|
|
@ -78,26 +78,19 @@ class CertificateTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_validation_in_controller_context
|
||||
# Проверяем, что валидация работает при интеграции с контроллером
|
||||
# Здесь мы эмулируем logику контроллера
|
||||
|
||||
api_user = @certificate.api_user
|
||||
# Устанавливаем неправильное имя пользователя
|
||||
api_user.update!(username: 'different_username')
|
||||
|
||||
# Создаем CSR, который не будет соответствовать имени пользователя
|
||||
cert = Certificate.new(
|
||||
api_user: api_user,
|
||||
csr: @certificate.csr
|
||||
)
|
||||
|
||||
# В продакшн среде должна работать валидация
|
||||
Rails.env.stub :test?, false do
|
||||
assert_not cert.save
|
||||
assert_includes cert.errors.full_messages, I18n.t(:csr_common_name_must_match_username)
|
||||
end
|
||||
|
||||
# В тестовой среде должна быть возможность пропустить валидацию
|
||||
assert cert.save(validate: false)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue