mirror of
https://github.com/internetee/registry.git
synced 2025-08-26 19:13:40 +02:00
Merge e1794d95f9
into c8a0788366
This commit is contained in:
commit
31a90e802e
6 changed files with 96 additions and 4 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue