Forbid contacts earlier in the domain EPP parsing process (#2962)

This will make testing easier, as well as allow us to remove contact
code from other parts of the codebase.
This commit is contained in:
gbrodman
2026-02-19 21:33:29 +00:00
committed by GitHub
parent 6747cc894d
commit c7f2db177b
7 changed files with 119 additions and 88 deletions
@@ -14,9 +14,11 @@
package google.registry.model.domain;
import static google.registry.testing.DatabaseHelper.persistActiveContact;
import static google.registry.testing.DatabaseHelper.persistActiveHost;
import static org.junit.Assert.assertThrows;
import google.registry.flows.domain.DomainFlowUtils.RegistrantProhibitedException;
import google.registry.flows.exceptions.ContactsProhibitedException;
import google.registry.model.ResourceCommandTestCase;
import google.registry.model.eppinput.EppInput;
import google.registry.model.eppinput.EppInput.ResourceCommandWrapper;
@@ -29,6 +31,7 @@ class DomainCommandTest extends ResourceCommandTestCase {
@Test
void testCreate() throws Exception {
// This EPP command wouldn't be allowed for policy reasons, but should marshal/unmarshal fine.
doXmlRoundtripTest("domain_create.xml");
}
@@ -64,42 +67,48 @@ class DomainCommandTest extends ResourceCommandTestCase {
@Test
void testCreate_emptyCommand() throws Exception {
// This EPP command wouldn't be allowed for policy reasons, but should marshal/unmarshal fine.
doXmlRoundtripTest("domain_create_empty.xml");
}
@Test
void testCreate_missingNonRegistrantContacts() throws Exception {
// This EPP command wouldn't be allowed for policy reasons, but should marshal/unmarshal fine.
doXmlRoundtripTest("domain_create_missing_non_registrant_contacts.xml");
}
@Test
void testCreate_cloneAndLinkReferences() throws Exception {
void testCreate_cloneAndLinkReferences_withHosts() throws Exception {
persistActiveHost("ns1.example.net");
persistActiveHost("ns2.example.net");
persistActiveContact("sh8013");
persistActiveContact("jd1234");
DomainCommand.Create create =
(DomainCommand.Create) loadEppResourceCommand("domain_create.xml");
create.cloneAndLinkReferences(fakeClock.nowUtc());
}
@Test
void testCreate_emptyCommand_cloneAndLinkReferences() throws Exception {
// This EPP command wouldn't be allowed for policy reasons, but should clone-and-link fine.
void testCreate_cloneAndLinkReferences_failsWithContacts() throws Exception {
persistActiveHost("ns1.example.net");
persistActiveHost("ns2.example.net");
DomainCommand.Create create =
(DomainCommand.Create) loadEppResourceCommand("domain_create_empty.xml");
create.cloneAndLinkReferences(fakeClock.nowUtc());
(DomainCommand.Create) loadEppResourceCommand("domain_create_with_contacts.xml");
assertThrows(
RegistrantProhibitedException.class,
() -> create.cloneAndLinkReferences(fakeClock.nowUtc()));
}
@Test
void testCreate_missingNonRegistrantContacts_cloneAndLinkReferences() throws Exception {
persistActiveContact("jd1234");
// This EPP command wouldn't be allowed for policy reasons, but should clone-and-link fine.
void testCreate_cloneAndLinkReferences_failsWithRegistrant() throws Exception {
DomainCommand.Create create =
(DomainCommand.Create)
loadEppResourceCommand("domain_create_missing_non_registrant_contacts.xml");
assertThrows(
RegistrantProhibitedException.class,
() -> create.cloneAndLinkReferences(fakeClock.nowUtc()));
}
@Test
void testCreate_emptyCommand_cloneAndLinkReferences() throws Exception {
DomainCommand.Create create =
(DomainCommand.Create) loadEppResourceCommand("domain_create_empty.xml");
create.cloneAndLinkReferences(fakeClock.nowUtc());
}
@@ -120,16 +129,24 @@ class DomainCommandTest extends ResourceCommandTestCase {
}
@Test
void testUpdate_cloneAndLinkReferences() throws Exception {
void testUpdate_cloneAndLinkReferences_hosts() throws Exception {
persistActiveHost("ns1.example.com");
persistActiveHost("ns2.example.com");
persistActiveContact("mak21");
persistActiveContact("sh8013");
DomainCommand.Update update =
(DomainCommand.Update) loadEppResourceCommand("domain_update.xml");
update.cloneAndLinkReferences(fakeClock.nowUtc());
}
@Test
void testUpdate_cloneAndLinkReferences_failsWithContacts() throws Exception {
persistActiveHost("ns1.example.com");
persistActiveHost("ns2.example.com");
DomainCommand.Update update =
(DomainCommand.Update) loadEppResourceCommand("domain_update_with_contacts.xml");
assertThrows(
ContactsProhibitedException.class, () -> update.cloneAndLinkReferences(fakeClock.nowUtc()));
}
@Test
void testUpdate_emptyCommand_cloneAndLinkReferences() throws Exception {
// This EPP command wouldn't be allowed for policy reasons, but should clone-and-link fine.
@@ -9,9 +9,6 @@
<domain:hostObj>ns1.example.net</domain:hostObj>
<domain:hostObj>ns2.example.net</domain:hostObj>
</domain:ns>
<domain:registrant>jd1234</domain:registrant>
<domain:contact type="admin">sh8013</domain:contact>
<domain:contact type="tech">sh8013</domain:contact>
<domain:authInfo>
<domain:pw>2fooBAR</domain:pw>
</domain:authInfo>
@@ -0,0 +1,22 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<create>
<domain:create
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.com</domain:name>
<domain:period unit="y">2</domain:period>
<domain:ns>
<domain:hostObj>ns1.example.net</domain:hostObj>
<domain:hostObj>ns2.example.net</domain:hostObj>
</domain:ns>
<domain:registrant>jd1234</domain:registrant>
<domain:contact type="admin">sh8013</domain:contact>
<domain:contact type="tech">sh8013</domain:contact>
<domain:authInfo>
<domain:pw>2fooBAR</domain:pw>
</domain:authInfo>
</domain:create>
</create>
<clTRID>ABC-12345</clTRID>
</command>
</epp>
@@ -8,18 +8,15 @@
<domain:ns>
<domain:hostObj>ns2.example.com</domain:hostObj>
</domain:ns>
<domain:contact type="tech">mak21</domain:contact>
<domain:status s="clientHold"/>
</domain:add>
<domain:rem>
<domain:ns>
<domain:hostObj>ns1.example.com</domain:hostObj>
</domain:ns>
<domain:contact type="tech">sh8013</domain:contact>
<domain:status s="clientUpdateProhibited"/>
</domain:rem>
<domain:chg>
<domain:registrant>sh8013</domain:registrant>
<domain:authInfo>
<domain:pw>2BARfoo</domain:pw>
</domain:authInfo>
@@ -0,0 +1,31 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<update>
<domain:update
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.com</domain:name>
<domain:add>
<domain:ns>
<domain:hostObj>ns2.example.com</domain:hostObj>
</domain:ns>
<domain:contact type="tech">mak21</domain:contact>
<domain:status s="clientHold"/>
</domain:add>
<domain:rem>
<domain:ns>
<domain:hostObj>ns1.example.com</domain:hostObj>
</domain:ns>
<domain:contact type="tech">sh8013</domain:contact>
<domain:status s="clientUpdateProhibited"/>
</domain:rem>
<domain:chg>
<domain:registrant>sh8013</domain:registrant>
<domain:authInfo>
<domain:pw>2BARfoo</domain:pw>
</domain:authInfo>
</domain:chg>
</domain:update>
</update>
<clTRID>ABC-12345</clTRID>
</command>
</epp>