Skip to content

Commit

Permalink
fix: update admin contact validation error code
Browse files Browse the repository at this point in the history
- Change error code from 2004 to 2306 for admin contact validation
- Add explicit validation check for required admin contacts
- Update tests to expect new error code

The error code 2306 better reflects the EPP standard for policy-based
validation failures. This change makes the error handling more consistent
with EPP specifications when validating admin contact requirements.
  • Loading branch information
OlegPhenomenon committed Feb 5, 2025
1 parent dc37223 commit a56237c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions app/models/epp/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ def validate_contacts
active_admins = admin_domain_contacts.select { |x| !x.marked_for_destruction? }
active_techs = tech_domain_contacts.select { |x| !x.marked_for_destruction? }

# Проверка количества админ контактов
if require_admin_contacts? && active_admins.empty?
add_epp_error('2306', 'contact', nil, 'Admin contacts are required')
ok = false
end

# validate registrant here as well
([Contact.find(registrant.id)] + active_admins + active_techs).each do |x|
unless x.valid?
Expand Down
8 changes: 4 additions & 4 deletions test/integration/repp/v1/domains/contacts_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def test_can_not_remove_one_and_only_contact

@domain.reload
assert_response :bad_request
assert_equal 2004, json[:code]
assert_equal 2306, json[:code]

assert @domain.admin_contacts.any?
end
Expand All @@ -159,7 +159,7 @@ def test_cannot_remove_admin_contact_for_legal_entity
json = JSON.parse(response.body, symbolize_names: true)

assert_response :bad_request
assert_equal 2004, json[:code]
assert_equal 2306, json[:code]
assert @domain.admin_contacts.any?
end

Expand All @@ -178,7 +178,7 @@ def test_cannot_remove_admin_contact_for_underage_private_registrant
json = JSON.parse(response.body, symbolize_names: true)

assert_response :bad_request
assert_equal 2004, json[:code]
assert_equal 2306, json[:code]
assert @domain.admin_contacts.any?
end

Expand Down Expand Up @@ -217,7 +217,7 @@ def test_cannot_remove_admin_contact_for_underage_estonian_id
json = JSON.parse(response.body, symbolize_names: true)

assert_response :bad_request
assert_equal 2004, json[:code]
assert_equal 2306, json[:code]
assert @domain.admin_contacts.any?
end

Expand Down

0 comments on commit a56237c

Please sign in to comment.