Re-add EppException marshalling assertions in application flow tests

Apologies for the reformatting, but this refactoring is quite rote and it's
definitely a bigger use of total time to perform the reformatting individually
than to simply do it file-wide.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=179221800
This commit is contained in:
mcilwain 2017-12-15 11:53:12 -08:00 committed by Ben McIlwain
parent da08baab92
commit 5e4a6b0235
4 changed files with 773 additions and 509 deletions

View file

@ -26,13 +26,14 @@ import static google.registry.testing.DatastoreHelper.newHostResource;
import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistActiveDomainApplication; import static google.registry.testing.DatastoreHelper.persistActiveDomainApplication;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows; import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.testing.JUnitBackports.expectThrows;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.flows.EppException;
import google.registry.flows.EppException.UnimplementedExtensionException; import google.registry.flows.EppException.UnimplementedExtensionException;
import google.registry.flows.ResourceFlowTestCase; import google.registry.flows.ResourceFlowTestCase;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException; import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
@ -77,8 +78,7 @@ public class DomainApplicationDeleteFlowTest
@Test @Test
public void testDryRun() throws Exception { public void testDryRun() throws Exception {
persistResource( persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
dryRunFlowAssertResponse(loadFile("domain_delete_response.xml")); dryRunFlowAssertResponse(loadFile("domain_delete_response.xml"));
} }
@ -88,38 +88,45 @@ public class DomainApplicationDeleteFlowTest
persistActiveContact("sh8013"); persistActiveContact("sh8013");
persistResource(newHostResource("ns1.example.net")); persistResource(newHostResource("ns1.example.net"));
// Create the DomainApplication to test. // Create the DomainApplication to test.
persistResource(newDomainApplication("example.tld").asBuilder() persistResource(
.setRepoId("1-TLD") newDomainApplication("example.tld")
.setRegistrant( .asBuilder()
Key.create( .setRepoId("1-TLD")
loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()))) .setRegistrant(
.setNameservers(ImmutableSet.of( Key.create(loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc())))
Key.create( .setNameservers(
loadByForeignKey(HostResource.class, "ns1.example.net", clock.nowUtc())))) ImmutableSet.of(
.build()); Key.create(
loadByForeignKey(HostResource.class, "ns1.example.net", clock.nowUtc()))))
.build());
doSuccessfulTest(); doSuccessfulTest();
for (Key<? extends EppResource> key : ImmutableList.of( for (Key<? extends EppResource> key :
loadAndGetKey(ContactResource.class, "sh8013", clock.nowUtc()), ImmutableList.of(
loadAndGetKey(HostResource.class, "ns1.example.net", clock.nowUtc()))) { loadAndGetKey(ContactResource.class, "sh8013", clock.nowUtc()),
loadAndGetKey(HostResource.class, "ns1.example.net", clock.nowUtc()))) {
assertThat(isLinked(key, clock.nowUtc())).isFalse(); assertThat(isLinked(key, clock.nowUtc())).isFalse();
} }
} }
@Test @Test
public void testSuccess_clientDeleteProhibited() throws Exception { public void testSuccess_clientDeleteProhibited() throws Exception {
persistResource(newDomainApplication("example.tld").asBuilder() persistResource(
.setRepoId("1-TLD") newDomainApplication("example.tld")
.addStatusValue(StatusValue.CLIENT_DELETE_PROHIBITED) .asBuilder()
.build()); .setRepoId("1-TLD")
.addStatusValue(StatusValue.CLIENT_DELETE_PROHIBITED)
.build());
doSuccessfulTest(); doSuccessfulTest();
} }
@Test @Test
public void testSuccess_serverDeleteProhibited() throws Exception { public void testSuccess_serverDeleteProhibited() throws Exception {
persistResource(newDomainApplication("example.tld").asBuilder() persistResource(
.setRepoId("1-TLD") newDomainApplication("example.tld")
.addStatusValue(StatusValue.SERVER_DELETE_PROHIBITED) .asBuilder()
.build()); .setRepoId("1-TLD")
.addStatusValue(StatusValue.SERVER_DELETE_PROHIBITED)
.build());
doSuccessfulTest(); doSuccessfulTest();
} }
@ -132,10 +139,12 @@ public class DomainApplicationDeleteFlowTest
@Test @Test
public void testFailure_existedButWasDeleted() throws Exception { public void testFailure_existedButWasDeleted() throws Exception {
persistResource(newDomainApplication("example.tld").asBuilder() persistResource(
.setRepoId("1-TLD") newDomainApplication("example.tld")
.setDeletionTime(clock.nowUtc().minusSeconds(1)) .asBuilder()
.build()); .setRepoId("1-TLD")
.setDeletionTime(clock.nowUtc().minusSeconds(1))
.build());
ResourceDoesNotExistException thrown = ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, this::runFlow); expectThrows(ResourceDoesNotExistException.class, this::runFlow);
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
@ -144,16 +153,15 @@ public class DomainApplicationDeleteFlowTest
@Test @Test
public void testFailure_unauthorizedClient() throws Exception { public void testFailure_unauthorizedClient() throws Exception {
sessionMetadata.setClientId("NewRegistrar"); sessionMetadata.setClientId("NewRegistrar");
persistResource( persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); EppException thrown = expectThrows(ResourceNotOwnedException.class, this::runFlow);
assertThrows(ResourceNotOwnedException.class, this::runFlow); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testSuccess_superuserUnauthorizedClient() throws Exception { public void testSuccess_superuserUnauthorizedClient() throws Exception {
sessionMetadata.setClientId("NewRegistrar"); sessionMetadata.setClientId("NewRegistrar");
persistResource( persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
clock.advanceOneMilli(); clock.advanceOneMilli();
runFlowAssertResponse( runFlowAssertResponse(
CommitMode.LIVE, UserPrivileges.SUPERUSER, loadFile("domain_delete_response.xml")); CommitMode.LIVE, UserPrivileges.SUPERUSER, loadFile("domain_delete_response.xml"));
@ -164,7 +172,8 @@ public class DomainApplicationDeleteFlowTest
persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
persistResource( persistResource(
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
assertThrows(NotAuthorizedForTldException.class, this::runFlow); EppException thrown = expectThrows(NotAuthorizedForTldException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -181,23 +190,27 @@ public class DomainApplicationDeleteFlowTest
public void testFailure_sunriseDuringLandrush() throws Exception { public void testFailure_sunriseDuringLandrush() throws Exception {
createTld("tld", TldState.LANDRUSH); createTld("tld", TldState.LANDRUSH);
setEppInput("domain_delete_application_landrush.xml", ImmutableMap.of("DOMAIN", "example.tld")); setEppInput("domain_delete_application_landrush.xml", ImmutableMap.of("DOMAIN", "example.tld"));
persistResource(newDomainApplication("example.tld") persistResource(
.asBuilder() newDomainApplication("example.tld")
.setRepoId("1-TLD") .asBuilder()
.setPhase(LaunchPhase.SUNRISE) .setRepoId("1-TLD")
.build()); .setPhase(LaunchPhase.SUNRISE)
assertThrows(SunriseApplicationCannotBeDeletedInLandrushException.class, this::runFlow); .build());
EppException thrown =
expectThrows(SunriseApplicationCannotBeDeletedInLandrushException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testSuccess_superuserSunriseDuringLandrush() throws Exception { public void testSuccess_superuserSunriseDuringLandrush() throws Exception {
createTld("tld", TldState.LANDRUSH); createTld("tld", TldState.LANDRUSH);
setEppInput("domain_delete_application_landrush.xml", ImmutableMap.of("DOMAIN", "example.tld")); setEppInput("domain_delete_application_landrush.xml", ImmutableMap.of("DOMAIN", "example.tld"));
persistResource(newDomainApplication("example.tld") persistResource(
.asBuilder() newDomainApplication("example.tld")
.setRepoId("1-TLD") .asBuilder()
.setPhase(LaunchPhase.SUNRISE) .setRepoId("1-TLD")
.build()); .setPhase(LaunchPhase.SUNRISE)
.build());
clock.advanceOneMilli(); clock.advanceOneMilli();
runFlowAssertResponse( runFlowAssertResponse(
CommitMode.LIVE, UserPrivileges.SUPERUSER, loadFile("domain_delete_response.xml")); CommitMode.LIVE, UserPrivileges.SUPERUSER, loadFile("domain_delete_response.xml"));
@ -207,11 +220,12 @@ public class DomainApplicationDeleteFlowTest
public void testSuccess_sunrushDuringLandrush() throws Exception { public void testSuccess_sunrushDuringLandrush() throws Exception {
createTld("tld", TldState.LANDRUSH); createTld("tld", TldState.LANDRUSH);
setEppInput("domain_delete_application_landrush.xml", ImmutableMap.of("DOMAIN", "example.tld")); setEppInput("domain_delete_application_landrush.xml", ImmutableMap.of("DOMAIN", "example.tld"));
persistResource(newDomainApplication("example.tld") persistResource(
.asBuilder() newDomainApplication("example.tld")
.setRepoId("1-TLD") .asBuilder()
.setPhase(LaunchPhase.SUNRUSH) .setRepoId("1-TLD")
.build()); .setPhase(LaunchPhase.SUNRUSH)
.build());
doSuccessfulTest(); doSuccessfulTest();
} }
@ -219,58 +233,59 @@ public class DomainApplicationDeleteFlowTest
public void testSuccess_sunriseDuringSunrush() throws Exception { public void testSuccess_sunriseDuringSunrush() throws Exception {
createTld("tld", TldState.SUNRUSH); createTld("tld", TldState.SUNRUSH);
setEppInput("domain_delete_application_sunrush.xml"); setEppInput("domain_delete_application_sunrush.xml");
persistResource(newDomainApplication("example.tld") persistResource(
.asBuilder() newDomainApplication("example.tld")
.setRepoId("1-TLD") .asBuilder()
.setPhase(LaunchPhase.SUNRISE) .setRepoId("1-TLD")
.build()); .setPhase(LaunchPhase.SUNRISE)
.build());
doSuccessfulTest(); doSuccessfulTest();
} }
@Test @Test
public void testFailure_mismatchedPhase() throws Exception { public void testFailure_mismatchedPhase() throws Exception {
setEppInput("domain_delete_application_landrush.xml", ImmutableMap.of("DOMAIN", "example.tld")); setEppInput("domain_delete_application_landrush.xml", ImmutableMap.of("DOMAIN", "example.tld"));
persistResource( persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); EppException thrown = expectThrows(LaunchPhaseMismatchException.class, this::runFlow);
assertThrows(LaunchPhaseMismatchException.class, this::runFlow); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_wrongExtension() throws Exception { public void testFailure_wrongExtension() throws Exception {
setEppInput("domain_delete_application_wrong_extension.xml"); setEppInput("domain_delete_application_wrong_extension.xml");
persistActiveDomainApplication("example.tld"); persistActiveDomainApplication("example.tld");
assertThrows(UnimplementedExtensionException.class, this::runFlow); EppException thrown = expectThrows(UnimplementedExtensionException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_predelegation() throws Exception { public void testFailure_predelegation() throws Exception {
createTld("tld", TldState.PREDELEGATION); createTld("tld", TldState.PREDELEGATION);
persistResource( persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); EppException thrown = expectThrows(BadCommandForRegistryPhaseException.class, this::runFlow);
assertThrows(BadCommandForRegistryPhaseException.class, this::runFlow); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_quietPeriod() throws Exception { public void testFailure_quietPeriod() throws Exception {
createTld("tld", TldState.QUIET_PERIOD); createTld("tld", TldState.QUIET_PERIOD);
persistResource( persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); EppException thrown = expectThrows(BadCommandForRegistryPhaseException.class, this::runFlow);
assertThrows(BadCommandForRegistryPhaseException.class, this::runFlow); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_generalAvailability() throws Exception { public void testFailure_generalAvailability() throws Exception {
createTld("tld", TldState.GENERAL_AVAILABILITY); createTld("tld", TldState.GENERAL_AVAILABILITY);
persistResource( persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); EppException thrown = expectThrows(BadCommandForRegistryPhaseException.class, this::runFlow);
assertThrows(BadCommandForRegistryPhaseException.class, this::runFlow); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testSuccess_superuserQuietPeriod() throws Exception { public void testSuccess_superuserQuietPeriod() throws Exception {
createTld("tld", TldState.QUIET_PERIOD); createTld("tld", TldState.QUIET_PERIOD);
persistResource( persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
clock.advanceOneMilli(); clock.advanceOneMilli();
runFlowAssertResponse( runFlowAssertResponse(
CommitMode.LIVE, UserPrivileges.SUPERUSER, loadFile("domain_delete_response.xml")); CommitMode.LIVE, UserPrivileges.SUPERUSER, loadFile("domain_delete_response.xml"));
@ -279,8 +294,7 @@ public class DomainApplicationDeleteFlowTest
@Test @Test
public void testSuccess_superuserPredelegation() throws Exception { public void testSuccess_superuserPredelegation() throws Exception {
createTld("tld", TldState.PREDELEGATION); createTld("tld", TldState.PREDELEGATION);
persistResource( persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
clock.advanceOneMilli(); clock.advanceOneMilli();
runFlowAssertResponse( runFlowAssertResponse(
CommitMode.LIVE, UserPrivileges.SUPERUSER, loadFile("domain_delete_response.xml")); CommitMode.LIVE, UserPrivileges.SUPERUSER, loadFile("domain_delete_response.xml"));
@ -289,8 +303,7 @@ public class DomainApplicationDeleteFlowTest
@Test @Test
public void testSuccess_superuserGeneralAvailability() throws Exception { public void testSuccess_superuserGeneralAvailability() throws Exception {
createTld("tld", TldState.GENERAL_AVAILABILITY); createTld("tld", TldState.GENERAL_AVAILABILITY);
persistResource( persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
clock.advanceOneMilli(); clock.advanceOneMilli();
runFlowAssertResponse( runFlowAssertResponse(
CommitMode.LIVE, UserPrivileges.SUPERUSER, loadFile("domain_delete_response.xml")); CommitMode.LIVE, UserPrivileges.SUPERUSER, loadFile("domain_delete_response.xml"));
@ -298,15 +311,14 @@ public class DomainApplicationDeleteFlowTest
@Test @Test
public void testFailure_applicationIdForDifferentDomain() throws Exception { public void testFailure_applicationIdForDifferentDomain() throws Exception {
persistResource( persistResource(newDomainApplication("invalid.tld").asBuilder().setRepoId("1-TLD").build());
newDomainApplication("invalid.tld").asBuilder().setRepoId("1-TLD").build()); EppException thrown = expectThrows(ApplicationDomainNameMismatchException.class, this::runFlow);
assertThrows(ApplicationDomainNameMismatchException.class, this::runFlow); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testIcannActivityReportField_getsLogged() throws Exception { public void testIcannActivityReportField_getsLogged() throws Exception {
persistResource( persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
clock.advanceOneMilli(); clock.advanceOneMilli();
runFlow(); runFlow();
assertIcannReportingActivityFieldLogged("srs-dom-delete"); assertIcannReportingActivityFieldLogged("srs-dom-delete");

View file

@ -22,7 +22,7 @@ import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows; import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.testing.JUnitBackports.expectThrows;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
@ -30,6 +30,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.flows.EppException;
import google.registry.flows.ResourceFlowTestCase; import google.registry.flows.ResourceFlowTestCase;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException; import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
import google.registry.flows.ResourceFlowUtils.ResourceNotOwnedException; import google.registry.flows.ResourceFlowUtils.ResourceNotOwnedException;
@ -67,8 +68,15 @@ public class DomainApplicationInfoFlowTest
private HostResource host2; private HostResource host2;
private DomainApplication application; private DomainApplication application;
private enum MarksState { MARKS_EXIST, NO_MARKS_EXIST } private enum MarksState {
private enum HostsState { HOSTS_EXIST, NO_HOSTS_EXIST } MARKS_EXIST,
NO_MARKS_EXIST
}
private enum HostsState {
HOSTS_EXIST,
NO_HOSTS_EXIST
}
@Before @Before
public void resetClientId() { public void resetClientId() {
@ -82,33 +90,42 @@ public class DomainApplicationInfoFlowTest
contact = persistActiveContact("sh8013"); contact = persistActiveContact("sh8013");
host1 = persistActiveHost("ns1.example.net"); host1 = persistActiveHost("ns1.example.net");
host2 = persistActiveHost("ns1.example.tld"); host2 = persistActiveHost("ns1.example.tld");
application = persistResource(new DomainApplication.Builder() application =
.setRepoId("123-TLD") persistResource(
.setFullyQualifiedDomainName("example.tld") new DomainApplication.Builder()
.setPhase(LaunchPhase.SUNRUSH) .setRepoId("123-TLD")
.setPersistedCurrentSponsorClientId("NewRegistrar") .setFullyQualifiedDomainName("example.tld")
.setCreationClientId("TheRegistrar") .setPhase(LaunchPhase.SUNRUSH)
.setLastEppUpdateClientId("NewRegistrar") .setPersistedCurrentSponsorClientId("NewRegistrar")
.setCreationTimeForTest(DateTime.parse("1999-04-03T22:00:00.0Z")) .setCreationClientId("TheRegistrar")
.setLastEppUpdateTime(DateTime.parse("1999-12-03T09:00:00.0Z")) .setLastEppUpdateClientId("NewRegistrar")
.setRegistrant(Key.create(registrant)) .setCreationTimeForTest(DateTime.parse("1999-04-03T22:00:00.0Z"))
.setContacts(ImmutableSet.of( .setLastEppUpdateTime(DateTime.parse("1999-12-03T09:00:00.0Z"))
DesignatedContact.create(Type.ADMIN, Key.create(contact)), .setRegistrant(Key.create(registrant))
DesignatedContact.create(Type.TECH, Key.create(contact)))) .setContacts(
.setNameservers(hostsState.equals(HostsState.HOSTS_EXIST) ? ImmutableSet.of( ImmutableSet.of(
Key.create(host1), Key.create(host2)) : null) DesignatedContact.create(Type.ADMIN, Key.create(contact)),
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("2fooBAR"))) DesignatedContact.create(Type.TECH, Key.create(contact))))
.addStatusValue(StatusValue.PENDING_CREATE) .setNameservers(
.setApplicationStatus(ApplicationStatus.PENDING_VALIDATION) hostsState.equals(HostsState.HOSTS_EXIST)
.setEncodedSignedMarks(marksState.equals(MarksState.MARKS_EXIST) ? ImmutableSet.of(Key.create(host1), Key.create(host2))
// If we need to include an encoded signed mark, pull it out of the create xml. : null)
? ImmutableList.of((EncodedSignedMark) .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("2fooBAR")))
new EppLoader(this, "domain_create_sunrise_encoded_signed_mark.xml") .addStatusValue(StatusValue.PENDING_CREATE)
.getEpp() .setApplicationStatus(ApplicationStatus.PENDING_VALIDATION)
.getSingleExtension(LaunchCreateExtension.class) .setEncodedSignedMarks(
.getSignedMarks().get(0)) marksState.equals(MarksState.MARKS_EXIST)
: null) // If we need to include an encoded signed mark, pull it out of the create
.build()); // xml.
? ImmutableList.of(
(EncodedSignedMark)
new EppLoader(this, "domain_create_sunrise_encoded_signed_mark.xml")
.getEpp()
.getSingleExtension(LaunchCreateExtension.class)
.getSignedMarks()
.get(0))
: null)
.build());
} }
private void doSuccessfulTest(String expectedXmlFilename, HostsState hostsState) private void doSuccessfulTest(String expectedXmlFilename, HostsState hostsState)
@ -241,12 +258,15 @@ public class DomainApplicationInfoFlowTest
public void testSuccess_secDns() throws Exception { public void testSuccess_secDns() throws Exception {
persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST); persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST);
// Add the dsData to the saved resource and change the nameservers to match the sample xml. // Add the dsData to the saved resource and change the nameservers to match the sample xml.
persistResource(application.asBuilder() persistResource(
.setDsData(ImmutableSet.of(DelegationSignerData.create( application
12345, 3, 1, base16().decode("49FD46E6C4B45C55D4AC")))) .asBuilder()
.setNameservers(ImmutableSet.of( .setDsData(
Key.create(host1), Key.create(host2))) ImmutableSet.of(
.build()); DelegationSignerData.create(
12345, 3, 1, base16().decode("49FD46E6C4B45C55D4AC"))))
.setNameservers(ImmutableSet.of(Key.create(host1), Key.create(host2)))
.build());
doSuccessfulTest("domain_info_sunrise_response_dsdata.xml", HostsState.NO_HOSTS_EXIST); doSuccessfulTest("domain_info_sunrise_response_dsdata.xml", HostsState.NO_HOSTS_EXIST);
} }
@ -254,10 +274,12 @@ public class DomainApplicationInfoFlowTest
public void testSuccess_allocated() throws Exception { public void testSuccess_allocated() throws Exception {
persistTestEntities(HostsState.HOSTS_EXIST, MarksState.NO_MARKS_EXIST); persistTestEntities(HostsState.HOSTS_EXIST, MarksState.NO_MARKS_EXIST);
// Update the application status of the saved resource. // Update the application status of the saved resource.
persistResource(application.asBuilder() persistResource(
.removeStatusValue(StatusValue.PENDING_CREATE) application
.setApplicationStatus(ApplicationStatus.ALLOCATED) .asBuilder()
.build()); .removeStatusValue(StatusValue.PENDING_CREATE)
.setApplicationStatus(ApplicationStatus.ALLOCATED)
.build());
doSuccessfulTest("domain_info_sunrise_allocated.xml", HostsState.HOSTS_EXIST); doSuccessfulTest("domain_info_sunrise_allocated.xml", HostsState.HOSTS_EXIST);
} }
@ -270,12 +292,13 @@ public class DomainApplicationInfoFlowTest
@Test @Test
public void testFailure_existedButWasDeleted() throws Exception { public void testFailure_existedButWasDeleted() throws Exception {
persistResource(new DomainApplication.Builder() persistResource(
.setRepoId("123-COM") new DomainApplication.Builder()
.setFullyQualifiedDomainName("timber.com") .setRepoId("123-COM")
.setDeletionTime(clock.nowUtc().minusDays(1)) .setFullyQualifiedDomainName("timber.com")
.setRegistrant(Key.create(persistActiveContact("jd1234"))) .setDeletionTime(clock.nowUtc().minusDays(1))
.build()); .setRegistrant(Key.create(persistActiveContact("jd1234")))
.build());
ResourceDoesNotExistException thrown = ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, this::runFlow); expectThrows(ResourceDoesNotExistException.class, this::runFlow);
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
@ -283,37 +306,41 @@ public class DomainApplicationInfoFlowTest
@Test @Test
public void testFailure_unauthorized() throws Exception { public void testFailure_unauthorized() throws Exception {
persistResource( persistResource(AppEngineRule.makeRegistrar1().asBuilder().setClientId("ClientZ").build());
AppEngineRule.makeRegistrar1().asBuilder().setClientId("ClientZ").build());
sessionMetadata.setClientId("ClientZ"); sessionMetadata.setClientId("ClientZ");
persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST); persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST);
assertThrows(ResourceNotOwnedException.class, this::runFlow); EppException thrown = expectThrows(ResourceNotOwnedException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_applicationIdForDifferentDomain() throws Exception { public void testFailure_applicationIdForDifferentDomain() throws Exception {
persistResource(new DomainApplication.Builder() persistResource(
.setRepoId("123-TLD") new DomainApplication.Builder()
.setFullyQualifiedDomainName("invalid.tld") .setRepoId("123-TLD")
.setRegistrant(Key.create(persistActiveContact("jd1234"))) .setFullyQualifiedDomainName("invalid.tld")
.setPhase(LaunchPhase.SUNRUSH) .setRegistrant(Key.create(persistActiveContact("jd1234")))
.build()); .setPhase(LaunchPhase.SUNRUSH)
assertThrows(ApplicationDomainNameMismatchException.class, this::runFlow); .build());
EppException thrown = expectThrows(ApplicationDomainNameMismatchException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_noApplicationId() throws Exception { public void testFailure_noApplicationId() throws Exception {
setEppInput("domain_info_sunrise_no_application_id.xml"); setEppInput("domain_info_sunrise_no_application_id.xml");
persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST); persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST);
assertThrows(MissingApplicationIdException.class, this::runFlow); EppException thrown = expectThrows(MissingApplicationIdException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_mismatchedLaunchPhase() throws Exception { public void testFailure_mismatchedLaunchPhase() throws Exception {
persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST); persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST);
application = persistResource( application = persistResource(application.asBuilder().setPhase(LaunchPhase.SUNRISE).build());
application.asBuilder().setPhase(LaunchPhase.SUNRISE).build()); EppException thrown =
assertThrows(ApplicationLaunchPhaseMismatchException.class, this::runFlow); expectThrows(ApplicationLaunchPhaseMismatchException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
/** Test that we load contacts and hosts as a batch rather than individually. */ /** Test that we load contacts and hosts as a batch rather than individually. */

View file

@ -28,13 +28,14 @@ import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistReservedList; import static google.registry.testing.DatastoreHelper.persistReservedList;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainApplicationSubject.assertAboutApplications; import static google.registry.testing.DomainApplicationSubject.assertAboutApplications;
import static google.registry.testing.JUnitBackports.assertThrows; import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.flows.EppException;
import google.registry.flows.EppException.UnimplementedExtensionException; import google.registry.flows.EppException.UnimplementedExtensionException;
import google.registry.flows.ResourceFlowTestCase; import google.registry.flows.ResourceFlowTestCase;
import google.registry.flows.ResourceFlowUtils.AddRemoveSameValueException; import google.registry.flows.ResourceFlowUtils.AddRemoveSameValueException;
@ -83,7 +84,7 @@ public class DomainApplicationUpdateFlowTest
extends ResourceFlowTestCase<DomainApplicationUpdateFlow, DomainApplication> { extends ResourceFlowTestCase<DomainApplicationUpdateFlow, DomainApplication> {
private static final DelegationSignerData SOME_DSDATA = private static final DelegationSignerData SOME_DSDATA =
DelegationSignerData.create(1, 2, 3, new byte[]{0, 1, 2}); DelegationSignerData.create(1, 2, 3, new byte[] {0, 1, 2});
ContactResource sh8013Contact; ContactResource sh8013Contact;
ContactResource mak21Contact; ContactResource mak21Contact;
@ -111,13 +112,17 @@ public class DomainApplicationUpdateFlowTest
} }
private DomainApplication persistApplication() throws Exception { private DomainApplication persistApplication() throws Exception {
return persistResource(newApplicationBuilder() return persistResource(
.setContacts(ImmutableSet.of( newApplicationBuilder()
DesignatedContact.create(Type.TECH, Key.create(sh8013Contact)), .setContacts(
DesignatedContact.create(Type.ADMIN, Key.create(unusedContact)))) ImmutableSet.of(
.setNameservers(ImmutableSet.of(Key.create( DesignatedContact.create(Type.TECH, Key.create(sh8013Contact)),
loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc())))) DesignatedContact.create(Type.ADMIN, Key.create(unusedContact))))
.build()); .setNameservers(
ImmutableSet.of(
Key.create(
loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc()))))
.build());
} }
private Builder newApplicationBuilder() throws Exception { private Builder newApplicationBuilder() throws Exception {
@ -134,8 +139,10 @@ public class DomainApplicationUpdateFlowTest
runFlowAssertResponse(loadFile("domain_update_response.xml")); runFlowAssertResponse(loadFile("domain_update_response.xml"));
// Check that the application was updated. These values came from the xml. // Check that the application was updated. These values came from the xml.
DomainApplication application = reloadDomainApplication(); DomainApplication application = reloadDomainApplication();
assertAboutApplications().that(application) assertAboutApplications()
.hasStatusValue(StatusValue.CLIENT_HOLD).and() .that(application)
.hasStatusValue(StatusValue.CLIENT_HOLD)
.and()
.hasOnlyOneHistoryEntryWhich() .hasOnlyOneHistoryEntryWhich()
.hasType(HistoryEntry.Type.DOMAIN_APPLICATION_UPDATE); .hasType(HistoryEntry.Type.DOMAIN_APPLICATION_UPDATE);
assertThat(application.getAuthInfo().getPw().getValue()).isEqualTo("2BARfoo"); assertThat(application.getAuthInfo().getPw().getValue()).isEqualTo("2BARfoo");
@ -178,8 +185,7 @@ public class DomainApplicationUpdateFlowTest
setEppInput("domain_update_sunrise_registrant_to_tech.xml"); setEppInput("domain_update_sunrise_registrant_to_tech.xml");
persistReferencedEntities(); persistReferencedEntities();
ContactResource sh8013 = loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()); ContactResource sh8013 = loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc());
persistResource( persistResource(newApplicationBuilder().setRegistrant(Key.create(sh8013)).build());
newApplicationBuilder().setRegistrant(Key.create(sh8013)).build());
clock.advanceOneMilli(); clock.advanceOneMilli();
runFlowAssertResponse(loadFile("domain_update_response.xml")); runFlowAssertResponse(loadFile("domain_update_response.xml"));
} }
@ -190,13 +196,15 @@ public class DomainApplicationUpdateFlowTest
persistReferencedEntities(); persistReferencedEntities();
ContactResource sh8013 = loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()); ContactResource sh8013 = loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc());
Key<ContactResource> sh8013Key = Key.create(sh8013); Key<ContactResource> sh8013Key = Key.create(sh8013);
persistResource(newApplicationBuilder() persistResource(
.setRegistrant(sh8013Key) newApplicationBuilder()
.setContacts(ImmutableSet.of( .setRegistrant(sh8013Key)
DesignatedContact.create(Type.ADMIN, sh8013Key), .setContacts(
DesignatedContact.create(Type.BILLING, sh8013Key), ImmutableSet.of(
DesignatedContact.create(Type.TECH, sh8013Key))) DesignatedContact.create(Type.ADMIN, sh8013Key),
.build()); DesignatedContact.create(Type.BILLING, sh8013Key),
DesignatedContact.create(Type.TECH, sh8013Key)))
.build());
clock.advanceOneMilli(); clock.advanceOneMilli();
runFlowAssertResponse(loadFile("domain_update_response.xml")); runFlowAssertResponse(loadFile("domain_update_response.xml"));
} }
@ -204,11 +212,15 @@ public class DomainApplicationUpdateFlowTest
@Test @Test
public void testSuccess_removeClientUpdateProhibited() throws Exception { public void testSuccess_removeClientUpdateProhibited() throws Exception {
persistReferencedEntities(); persistReferencedEntities();
persistResource(persistApplication().asBuilder().setStatusValues( persistResource(
ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED)).build()); persistApplication()
.asBuilder()
.setStatusValues(ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED))
.build());
clock.advanceOneMilli(); clock.advanceOneMilli();
runFlow(); runFlow();
assertAboutApplications().that(reloadDomainApplication()) assertAboutApplications()
.that(reloadDomainApplication())
.doesNotHaveStatusValue(StatusValue.CLIENT_UPDATE_PROHIBITED); .doesNotHaveStatusValue(StatusValue.CLIENT_UPDATE_PROHIBITED);
} }
@ -222,8 +234,10 @@ public class DomainApplicationUpdateFlowTest
assertTransactionalFlow(true); assertTransactionalFlow(true);
clock.advanceOneMilli(); clock.advanceOneMilli();
runFlowAssertResponse(loadFile("domain_update_response.xml")); runFlowAssertResponse(loadFile("domain_update_response.xml"));
assertAboutApplications().that(reloadDomainApplication()) assertAboutApplications()
.hasExactlyDsData(expectedDsData).and() .that(reloadDomainApplication())
.hasExactlyDsData(expectedDsData)
.and()
.hasOnlyOneHistoryEntryWhich() .hasOnlyOneHistoryEntryWhich()
.hasType(HistoryEntry.Type.DOMAIN_APPLICATION_UPDATE); .hasType(HistoryEntry.Type.DOMAIN_APPLICATION_UPDATE);
} }
@ -233,25 +247,25 @@ public class DomainApplicationUpdateFlowTest
doSecDnsSuccessfulTest( doSecDnsSuccessfulTest(
"domain_update_sunrise_dsdata_add.xml", "domain_update_sunrise_dsdata_add.xml",
null, null,
ImmutableSet.of(DelegationSignerData.create( ImmutableSet.of(
12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B")))); DelegationSignerData.create(12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B"))));
} }
@Test @Test
public void testSuccess_secDnsAddPreservesExisting() throws Exception { public void testSuccess_secDnsAddPreservesExisting() throws Exception {
doSecDnsSuccessfulTest( doSecDnsSuccessfulTest(
"domain_update_sunrise_dsdata_add.xml", "domain_update_sunrise_dsdata_add.xml",
ImmutableSet.of(SOME_DSDATA), ImmutableSet.of(SOME_DSDATA),
ImmutableSet.of(SOME_DSDATA, DelegationSignerData.create( ImmutableSet.of(
12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B")))); SOME_DSDATA,
DelegationSignerData.create(12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B"))));
} }
@Test @Test
public void testSuccess_secDnsAddToMaxRecords() throws Exception { public void testSuccess_secDnsAddToMaxRecords() throws Exception {
ImmutableSet.Builder<DelegationSignerData> builder = new ImmutableSet.Builder<>(); ImmutableSet.Builder<DelegationSignerData> builder = new ImmutableSet.Builder<>();
for (int i = 0; i < 7; ++i) { for (int i = 0; i < 7; ++i) {
builder.add(DelegationSignerData.create(i, 2, 3, new byte[]{0, 1, 2})); builder.add(DelegationSignerData.create(i, 2, 3, new byte[] {0, 1, 2}));
} }
ImmutableSet<DelegationSignerData> commonDsData = builder.build(); ImmutableSet<DelegationSignerData> commonDsData = builder.build();
@ -259,16 +273,20 @@ public class DomainApplicationUpdateFlowTest
"domain_update_sunrise_dsdata_add.xml", "domain_update_sunrise_dsdata_add.xml",
commonDsData, commonDsData,
ImmutableSet.copyOf( ImmutableSet.copyOf(
union(commonDsData, ImmutableSet.of(DelegationSignerData.create( union(
12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B")))))); commonDsData,
ImmutableSet.of(
DelegationSignerData.create(
12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B"))))));
} }
@Test @Test
public void testSuccess_secDnsRemove() throws Exception { public void testSuccess_secDnsRemove() throws Exception {
doSecDnsSuccessfulTest( doSecDnsSuccessfulTest(
"domain_update_sunrise_dsdata_rem.xml", "domain_update_sunrise_dsdata_rem.xml",
ImmutableSet.of(SOME_DSDATA, DelegationSignerData.create( ImmutableSet.of(
12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B"))), SOME_DSDATA,
DelegationSignerData.create(12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B"))),
ImmutableSet.of(SOME_DSDATA)); ImmutableSet.of(SOME_DSDATA));
} }
@ -277,8 +295,9 @@ public class DomainApplicationUpdateFlowTest
// As an aside, this test also validates that it's ok to set the 'urgent' attribute to false. // As an aside, this test also validates that it's ok to set the 'urgent' attribute to false.
doSecDnsSuccessfulTest( doSecDnsSuccessfulTest(
"domain_update_sunrise_dsdata_rem_all.xml", "domain_update_sunrise_dsdata_rem_all.xml",
ImmutableSet.of(SOME_DSDATA, DelegationSignerData.create( ImmutableSet.of(
12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B"))), SOME_DSDATA,
DelegationSignerData.create(12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B"))),
ImmutableSet.of()); ImmutableSet.of());
} }
@ -286,28 +305,36 @@ public class DomainApplicationUpdateFlowTest
public void testSuccess_secDnsAddRemove() throws Exception { public void testSuccess_secDnsAddRemove() throws Exception {
doSecDnsSuccessfulTest( doSecDnsSuccessfulTest(
"domain_update_sunrise_dsdata_add_rem.xml", "domain_update_sunrise_dsdata_add_rem.xml",
ImmutableSet.of(SOME_DSDATA, DelegationSignerData.create( ImmutableSet.of(
12345, 3, 1, base16().decode("38EC35D5B3A34B33C99B"))), SOME_DSDATA,
ImmutableSet.of(SOME_DSDATA, DelegationSignerData.create( DelegationSignerData.create(12345, 3, 1, base16().decode("38EC35D5B3A34B33C99B"))),
12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B")))); ImmutableSet.of(
SOME_DSDATA,
DelegationSignerData.create(12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B"))));
} }
@Test @Test
public void testSuccess_secDnsAddRemoveToMaxRecords() throws Exception { public void testSuccess_secDnsAddRemoveToMaxRecords() throws Exception {
ImmutableSet.Builder<DelegationSignerData> builder = new ImmutableSet.Builder<>(); ImmutableSet.Builder<DelegationSignerData> builder = new ImmutableSet.Builder<>();
for (int i = 0; i < 7; ++i) { for (int i = 0; i < 7; ++i) {
builder.add(DelegationSignerData.create(i, 2, 3, new byte[]{0, 1, 2})); builder.add(DelegationSignerData.create(i, 2, 3, new byte[] {0, 1, 2}));
} }
ImmutableSet<DelegationSignerData> commonDsData = builder.build(); ImmutableSet<DelegationSignerData> commonDsData = builder.build();
doSecDnsSuccessfulTest( doSecDnsSuccessfulTest(
"domain_update_sunrise_dsdata_add_rem.xml", "domain_update_sunrise_dsdata_add_rem.xml",
ImmutableSet.copyOf( ImmutableSet.copyOf(
union(commonDsData, ImmutableSet.of(DelegationSignerData.create( union(
12345, 3, 1, base16().decode("38EC35D5B3A34B33C99B"))))), commonDsData,
ImmutableSet.of(
DelegationSignerData.create(
12345, 3, 1, base16().decode("38EC35D5B3A34B33C99B"))))),
ImmutableSet.copyOf( ImmutableSet.copyOf(
union(commonDsData, ImmutableSet.of(DelegationSignerData.create( union(
12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B")))))); commonDsData,
ImmutableSet.of(
DelegationSignerData.create(
12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B"))))));
} }
@Test @Test
@ -315,10 +342,12 @@ public class DomainApplicationUpdateFlowTest
// Adding and removing the same dsData is a no-op because removes are processed first. // Adding and removing the same dsData is a no-op because removes are processed first.
doSecDnsSuccessfulTest( doSecDnsSuccessfulTest(
"domain_update_sunrise_dsdata_add_rem_same.xml", "domain_update_sunrise_dsdata_add_rem_same.xml",
ImmutableSet.of(SOME_DSDATA, DelegationSignerData.create( ImmutableSet.of(
12345, 3, 1, base16().decode("38EC35D5B3A34B33C99B"))), SOME_DSDATA,
ImmutableSet.of(SOME_DSDATA, DelegationSignerData.create( DelegationSignerData.create(12345, 3, 1, base16().decode("38EC35D5B3A34B33C99B"))),
12345, 3, 1, base16().decode("38EC35D5B3A34B33C99B")))); ImmutableSet.of(
SOME_DSDATA,
DelegationSignerData.create(12345, 3, 1, base16().decode("38EC35D5B3A34B33C99B"))));
} }
@Test @Test
@ -330,12 +359,13 @@ public class DomainApplicationUpdateFlowTest
ImmutableSet.of(SOME_DSDATA)); ImmutableSet.of(SOME_DSDATA));
} }
private void doSecDnsFailingTest(Class<? extends Exception> expectedException, String xmlFilename) private void doSecDnsFailingTest(
throws Exception { Class<? extends EppException> expectedException, String xmlFilename) throws Exception {
setEppInput(xmlFilename); setEppInput(xmlFilename);
persistReferencedEntities(); persistReferencedEntities();
persistNewApplication(); persistNewApplication();
assertThrows(expectedException, this::runFlow); EppException thrown = expectThrows(expectedException, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -352,40 +382,40 @@ public class DomainApplicationUpdateFlowTest
@Test @Test
public void testFailure_secDnsUrgentNotSupported() throws Exception { public void testFailure_secDnsUrgentNotSupported() throws Exception {
doSecDnsFailingTest( doSecDnsFailingTest(
UrgentAttributeNotSupportedException.class, UrgentAttributeNotSupportedException.class, "domain_update_sunrise_dsdata_urgent.xml");
"domain_update_sunrise_dsdata_urgent.xml");
} }
@Test @Test
public void testFailure_secDnsChangeNotSupported() throws Exception { public void testFailure_secDnsChangeNotSupported() throws Exception {
doSecDnsFailingTest( doSecDnsFailingTest(
MaxSigLifeChangeNotSupportedException.class, MaxSigLifeChangeNotSupportedException.class, "domain_update_sunrise_maxsiglife.xml");
"domain_update_sunrise_maxsiglife.xml");
} }
@Test @Test
public void testFailure_secDnsTooManyDsRecords() throws Exception { public void testFailure_secDnsTooManyDsRecords() throws Exception {
ImmutableSet.Builder<DelegationSignerData> builder = new ImmutableSet.Builder<>(); ImmutableSet.Builder<DelegationSignerData> builder = new ImmutableSet.Builder<>();
for (int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
builder.add(DelegationSignerData.create(i, 2, 3, new byte[]{0, 1, 2})); builder.add(DelegationSignerData.create(i, 2, 3, new byte[] {0, 1, 2}));
} }
setEppInput("domain_update_sunrise_dsdata_add.xml"); setEppInput("domain_update_sunrise_dsdata_add.xml");
persistResource(newApplicationBuilder().setDsData(builder.build()).build()); persistResource(newApplicationBuilder().setDsData(builder.build()).build());
assertThrows(TooManyDsRecordsException.class, this::runFlow); EppException thrown = expectThrows(TooManyDsRecordsException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
private void modifyApplicationToHave13Nameservers() throws Exception { private void modifyApplicationToHave13Nameservers() throws Exception {
ImmutableSet.Builder<Key<HostResource>> nameservers = new ImmutableSet.Builder<>(); ImmutableSet.Builder<Key<HostResource>> nameservers = new ImmutableSet.Builder<>();
for (int i = 1; i < 15; i++) { for (int i = 1; i < 15; i++) {
if (i != 2) { // Skip 2 since that's the one that the tests will add. if (i != 2) { // Skip 2 since that's the one that the tests will add.
nameservers.add(Key.create(loadByForeignKey( nameservers.add(
HostResource.class, String.format("ns%d.example.tld", i), clock.nowUtc()))); Key.create(
loadByForeignKey(
HostResource.class, String.format("ns%d.example.tld", i), clock.nowUtc())));
} }
} }
persistResource(reloadDomainApplication().asBuilder() persistResource(
.setNameservers(nameservers.build()) reloadDomainApplication().asBuilder().setNameservers(nameservers.build()).build());
.build());
} }
@Test @Test
@ -395,20 +425,23 @@ public class DomainApplicationUpdateFlowTest
// Modify application to have 13 nameservers. We will then remove one and add one in the test. // Modify application to have 13 nameservers. We will then remove one and add one in the test.
modifyApplicationToHave13Nameservers(); modifyApplicationToHave13Nameservers();
setEppInput("domain_update_sunrise_add_nameserver.xml"); setEppInput("domain_update_sunrise_add_nameserver.xml");
assertThrows(TooManyNameserversException.class, this::runFlow); EppException thrown = expectThrows(TooManyNameserversException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_wrongExtension() throws Exception { public void testFailure_wrongExtension() throws Exception {
setEppInput("domain_update_sunrise_wrong_extension.xml"); setEppInput("domain_update_sunrise_wrong_extension.xml");
assertThrows(UnimplementedExtensionException.class, this::runFlow); EppException thrown = expectThrows(UnimplementedExtensionException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_applicationDomainNameMismatch() throws Exception { public void testFailure_applicationDomainNameMismatch() throws Exception {
persistReferencedEntities(); persistReferencedEntities();
persistResource(newApplicationBuilder().setFullyQualifiedDomainName("something.tld").build()); persistResource(newApplicationBuilder().setFullyQualifiedDomainName("something.tld").build());
assertThrows(ApplicationDomainNameMismatchException.class, this::runFlow); EppException thrown = expectThrows(ApplicationDomainNameMismatchException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -432,16 +465,22 @@ public class DomainApplicationUpdateFlowTest
public void testFailure_clientUpdateProhibited() throws Exception { public void testFailure_clientUpdateProhibited() throws Exception {
setEppInput("domain_update_sunrise_authinfo.xml"); setEppInput("domain_update_sunrise_authinfo.xml");
persistReferencedEntities(); persistReferencedEntities();
persistResource(newApplicationBuilder().setStatusValues( persistResource(
ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED)).build()); newApplicationBuilder()
assertThrows(ResourceHasClientUpdateProhibitedException.class, this::runFlow); .setStatusValues(ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED))
.build());
EppException thrown =
expectThrows(ResourceHasClientUpdateProhibitedException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_serverUpdateProhibited() throws Exception { public void testFailure_serverUpdateProhibited() throws Exception {
persistReferencedEntities(); persistReferencedEntities();
persistResource(newApplicationBuilder().setStatusValues( persistResource(
ImmutableSet.of(StatusValue.SERVER_UPDATE_PROHIBITED)).build()); newApplicationBuilder()
.setStatusValues(ImmutableSet.of(StatusValue.SERVER_UPDATE_PROHIBITED))
.build());
ResourceStatusProhibitsOperationException thrown = ResourceStatusProhibitsOperationException thrown =
expectThrows(ResourceStatusProhibitsOperationException.class, this::runFlow); expectThrows(ResourceStatusProhibitsOperationException.class, this::runFlow);
assertThat(thrown).hasMessageThat().contains("serverUpdateProhibited"); assertThat(thrown).hasMessageThat().contains("serverUpdateProhibited");
@ -450,7 +489,9 @@ public class DomainApplicationUpdateFlowTest
private void doIllegalApplicationStatusTest(ApplicationStatus status) throws Exception { private void doIllegalApplicationStatusTest(ApplicationStatus status) throws Exception {
persistReferencedEntities(); persistReferencedEntities();
persistResource(newApplicationBuilder().setApplicationStatus(status).build()); persistResource(newApplicationBuilder().setApplicationStatus(status).build());
assertThrows(ApplicationStatusProhibitsUpdateException.class, this::runFlow); EppException thrown =
expectThrows(ApplicationStatusProhibitsUpdateException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -497,10 +538,18 @@ public class DomainApplicationUpdateFlowTest
persistNewApplication(); persistNewApplication();
// Add a tech contact to the persisted entity, which should cause the flow to fail when it tries // Add a tech contact to the persisted entity, which should cause the flow to fail when it tries
// to add "mak21" as a second tech contact. // to add "mak21" as a second tech contact.
persistResource(reloadDomainApplication().asBuilder().setContacts(ImmutableSet.of( persistResource(
DesignatedContact.create(Type.TECH, Key.create( reloadDomainApplication()
loadByForeignKey(ContactResource.class, "foo", clock.nowUtc()))))).build()); .asBuilder()
assertThrows(DuplicateContactForRoleException.class, this::runFlow); .setContacts(
ImmutableSet.of(
DesignatedContact.create(
Type.TECH,
Key.create(
loadByForeignKey(ContactResource.class, "foo", clock.nowUtc())))))
.build());
EppException thrown = expectThrows(DuplicateContactForRoleException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -508,10 +557,10 @@ public class DomainApplicationUpdateFlowTest
setEppInput("domain_update_sunrise_prohibited_status.xml"); setEppInput("domain_update_sunrise_prohibited_status.xml");
persistReferencedEntities(); persistReferencedEntities();
persistNewApplication(); persistNewApplication();
assertThrows(StatusNotClientSettableException.class, this::runFlow); EppException thrown = expectThrows(StatusNotClientSettableException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testSuccess_superuserProhibitedStatusValue() throws Exception { public void testSuccess_superuserProhibitedStatusValue() throws Exception {
setEppInput("domain_update_sunrise_prohibited_status.xml"); setEppInput("domain_update_sunrise_prohibited_status.xml");
@ -519,9 +568,7 @@ public class DomainApplicationUpdateFlowTest
persistNewApplication(); persistNewApplication();
clock.advanceOneMilli(); clock.advanceOneMilli();
runFlowAssertResponse( runFlowAssertResponse(
CommitMode.LIVE, CommitMode.LIVE, UserPrivileges.SUPERUSER, loadFile("domain_update_response.xml"));
UserPrivileges.SUPERUSER,
loadFile("domain_update_response.xml"));
} }
@Test @Test
@ -529,7 +576,8 @@ public class DomainApplicationUpdateFlowTest
setEppInput("domain_update_sunrise_duplicate_contact.xml"); setEppInput("domain_update_sunrise_duplicate_contact.xml");
persistReferencedEntities(); persistReferencedEntities();
persistNewApplication(); persistNewApplication();
assertThrows(DuplicateContactForRoleException.class, this::runFlow); EppException thrown = expectThrows(DuplicateContactForRoleException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -538,7 +586,8 @@ public class DomainApplicationUpdateFlowTest
persistReferencedEntities(); persistReferencedEntities();
persistNewApplication(); persistNewApplication();
// We need to test for missing type, but not for invalid - the schema enforces that for us. // We need to test for missing type, but not for invalid - the schema enforces that for us.
assertThrows(MissingContactTypeException.class, this::runFlow); EppException thrown = expectThrows(MissingContactTypeException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -546,7 +595,8 @@ public class DomainApplicationUpdateFlowTest
sessionMetadata.setClientId("NewRegistrar"); sessionMetadata.setClientId("NewRegistrar");
persistReferencedEntities(); persistReferencedEntities();
persistApplication(); persistApplication();
assertThrows(ResourceNotOwnedException.class, this::runFlow); EppException thrown = expectThrows(ResourceNotOwnedException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -565,7 +615,8 @@ public class DomainApplicationUpdateFlowTest
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
persistReferencedEntities(); persistReferencedEntities();
persistApplication(); persistApplication();
assertThrows(NotAuthorizedForTldException.class, this::runFlow); EppException thrown = expectThrows(NotAuthorizedForTldException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -583,48 +634,62 @@ public class DomainApplicationUpdateFlowTest
public void testFailure_sameNameserverAddedAndRemoved() throws Exception { public void testFailure_sameNameserverAddedAndRemoved() throws Exception {
setEppInput("domain_update_sunrise_add_remove_same_host.xml"); setEppInput("domain_update_sunrise_add_remove_same_host.xml");
persistReferencedEntities(); persistReferencedEntities();
persistResource(newApplicationBuilder() persistResource(
.setNameservers(ImmutableSet.of(Key.create( newApplicationBuilder()
loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc())))) .setNameservers(
.build()); ImmutableSet.of(
assertThrows(AddRemoveSameValueException.class, this::runFlow); Key.create(
loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc()))))
.build());
EppException thrown = expectThrows(AddRemoveSameValueException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_sameContactAddedAndRemoved() throws Exception { public void testFailure_sameContactAddedAndRemoved() throws Exception {
setEppInput("domain_update_sunrise_add_remove_same_contact.xml"); setEppInput("domain_update_sunrise_add_remove_same_contact.xml");
persistReferencedEntities(); persistReferencedEntities();
persistResource(newApplicationBuilder() persistResource(
.setContacts(ImmutableSet.of(DesignatedContact.create( newApplicationBuilder()
Type.TECH, .setContacts(
Key.create( ImmutableSet.of(
loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()))))) DesignatedContact.create(
.build()); Type.TECH,
assertThrows(AddRemoveSameValueException.class, this::runFlow); Key.create(
loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc())))))
.build());
EppException thrown = expectThrows(AddRemoveSameValueException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_removeAdmin() throws Exception { public void testFailure_removeAdmin() throws Exception {
setEppInput("domain_update_sunrise_remove_admin.xml"); setEppInput("domain_update_sunrise_remove_admin.xml");
persistReferencedEntities(); persistReferencedEntities();
persistResource(newApplicationBuilder() persistResource(
.setContacts(ImmutableSet.of( newApplicationBuilder()
DesignatedContact.create(Type.ADMIN, Key.create(sh8013Contact)), .setContacts(
DesignatedContact.create(Type.TECH, Key.create(sh8013Contact)))) ImmutableSet.of(
.build()); DesignatedContact.create(Type.ADMIN, Key.create(sh8013Contact)),
assertThrows(MissingAdminContactException.class, this::runFlow); DesignatedContact.create(Type.TECH, Key.create(sh8013Contact))))
.build());
EppException thrown = expectThrows(MissingAdminContactException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_removeTech() throws Exception { public void testFailure_removeTech() throws Exception {
setEppInput("domain_update_sunrise_remove_tech.xml"); setEppInput("domain_update_sunrise_remove_tech.xml");
persistReferencedEntities(); persistReferencedEntities();
persistResource(newApplicationBuilder() persistResource(
.setContacts(ImmutableSet.of( newApplicationBuilder()
DesignatedContact.create(Type.ADMIN, Key.create(sh8013Contact)), .setContacts(
DesignatedContact.create(Type.TECH, Key.create(sh8013Contact)))) ImmutableSet.of(
.build()); DesignatedContact.create(Type.ADMIN, Key.create(sh8013Contact)),
assertThrows(MissingTechnicalContactException.class, this::runFlow); DesignatedContact.create(Type.TECH, Key.create(sh8013Contact))))
.build());
EppException thrown = expectThrows(MissingTechnicalContactException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -632,11 +697,13 @@ public class DomainApplicationUpdateFlowTest
persistReferencedEntities(); persistReferencedEntities();
persistApplication(); persistApplication();
persistResource( persistResource(
Registry.get("tld").asBuilder() Registry.get("tld")
.asBuilder()
.setAllowedRegistrantContactIds(ImmutableSet.of("contact1234")) .setAllowedRegistrantContactIds(ImmutableSet.of("contact1234"))
.build()); .build());
clock.advanceOneMilli(); clock.advanceOneMilli();
assertThrows(RegistrantNotAllowedException.class, this::runFlow); EppException thrown = expectThrows(RegistrantNotAllowedException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -644,17 +711,20 @@ public class DomainApplicationUpdateFlowTest
persistReferencedEntities(); persistReferencedEntities();
persistApplication(); persistApplication();
persistResource( persistResource(
Registry.get("tld").asBuilder() Registry.get("tld")
.asBuilder()
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.example.foo")) .setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.example.foo"))
.build()); .build());
clock.advanceOneMilli(); clock.advanceOneMilli();
assertThrows(NameserversNotAllowedForTldException.class, this::runFlow); EppException thrown = expectThrows(NameserversNotAllowedForTldException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testSuccess_nameserverAndRegistrantWhitelisted() throws Exception { public void testSuccess_nameserverAndRegistrantWhitelisted() throws Exception {
persistResource( persistResource(
Registry.get("tld").asBuilder() Registry.get("tld")
.asBuilder()
.setAllowedRegistrantContactIds(ImmutableSet.of("sh8013")) .setAllowedRegistrantContactIds(ImmutableSet.of("sh8013"))
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns2.example.tld")) .setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns2.example.tld"))
.build()); .build());
@ -675,8 +745,10 @@ public class DomainApplicationUpdateFlowTest
ImmutableSet.of("ns1.example.tld", "ns2.example.tld")) ImmutableSet.of("ns1.example.tld", "ns2.example.tld"))
.build()); .build());
clock.advanceOneMilli(); clock.advanceOneMilli();
assertThrows( EppException thrown =
NameserversNotSpecifiedForTldWithNameserverWhitelistException.class, this::runFlow); expectThrows(
NameserversNotSpecifiedForTldWithNameserverWhitelistException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -747,8 +819,10 @@ public class DomainApplicationUpdateFlowTest
"reserved", "example,NAMESERVER_RESTRICTED,ns1.example.tld:ns2.example.tld")) "reserved", "example,NAMESERVER_RESTRICTED,ns1.example.tld:ns2.example.tld"))
.build()); .build());
clock.advanceOneMilli(); clock.advanceOneMilli();
assertThrows( EppException thrown =
NameserversNotSpecifiedForNameserverRestrictedDomainException.class, this::runFlow); expectThrows(
NameserversNotSpecifiedForNameserverRestrictedDomainException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -842,7 +916,8 @@ public class DomainApplicationUpdateFlowTest
"domain_update_sunrise_fee.xml", "domain_update_sunrise_fee.xml",
ImmutableMap.of("DOMAIN", "non-free-update.tld", "AMOUNT", "12.00")); ImmutableMap.of("DOMAIN", "non-free-update.tld", "AMOUNT", "12.00"));
clock.advanceOneMilli(); clock.advanceOneMilli();
assertThrows(FeesMismatchException.class, this::runFlow); EppException thrown = expectThrows(FeesMismatchException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test