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