This commit is contained in:
OlegPhenomenon 2025-08-10 02:07:10 +00:00 committed by GitHub
commit 31a90e802e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 96 additions and 4 deletions

View file

@ -41,4 +41,56 @@ class CertificateTest < ActiveSupport::TestCase
@certificate.update!(interface: Certificate::REGISTRAR, crt: nil)
assert_not @certificate.revokable?
end
def test_csr_common_name_must_match_username
api_user = @certificate.api_user
new_cert = Certificate.new(
api_user: api_user,
csr: @certificate.csr
)
api_user.update!(username: 'different_username')
new_cert.send(:validate_csr_parameters)
assert_includes new_cert.errors.full_messages, I18n.t(:csr_common_name_must_match_username)
end
def test_csr_country_validation
api_user = @certificate.api_user
csr_content = @certificate.csr
new_cert = Certificate.new(
api_user: api_user,
csr: csr_content
)
api_user.registrar.update!(address_country_code: 'EE', vat_rate: 22)
new_cert.send(:validate_csr_parameters)
assert_not_includes new_cert.errors.full_messages, I18n.t(:csr_country_must_match_registrar_country)
new_cert.errors.clear
api_user.registrar.update!(address_country_code: 'US', vat_rate: nil)
new_cert.send(:validate_csr_parameters)
assert_includes new_cert.errors.full_messages, I18n.t(:csr_country_must_match_registrar_country)
end
def test_validation_in_controller_context
api_user = @certificate.api_user
api_user.update!(username: 'different_username')
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