Re-add assertions that EppExceptions marshal correctly

These checks were removed in [] and re-adding them is the last
step of the migration to using expectThrows/assertThrows globally.

Note that this is roughly half of them. More to come in a follow-up CL.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=179216707
This commit is contained in:
mcilwain 2017-12-15 11:15:15 -08:00 committed by Ben McIlwain
parent 16a1d6d196
commit da08baab92
17 changed files with 529 additions and 316 deletions

View file

@ -15,7 +15,8 @@
package google.registry.flows;
import static com.google.common.truth.Truth.assertThat;
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.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
@ -50,25 +51,28 @@ public class ExtensionManagerTest {
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
@Test
public void testDuplicateExtensionsForbidden() throws Exception {
ExtensionManager manager = new TestInstanceBuilder()
ExtensionManager manager =
new TestInstanceBuilder()
.setEppRequestSource(EppRequestSource.TOOL)
.setDeclaredUris()
.setSuppliedExtensions(
MetadataExtension.class,
LaunchCreateExtension.class,
MetadataExtension.class)
MetadataExtension.class, LaunchCreateExtension.class, MetadataExtension.class)
.build();
manager.register(MetadataExtension.class, LaunchCreateExtension.class);
assertThrows(UnsupportedRepeatedExtensionException.class, () -> manager.validate());
EppException thrown =
expectThrows(UnsupportedRepeatedExtensionException.class, manager::validate);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testUndeclaredExtensionsLogged() throws Exception {
TestLogHandler handler = new TestLogHandler();
Logger.getLogger(ExtensionManager.class.getCanonicalName()).addHandler(handler);
ExtensionManager manager = new TestInstanceBuilder()
ExtensionManager manager =
new TestInstanceBuilder()
.setEppRequestSource(EppRequestSource.TOOL)
.setDeclaredUris()
.setSuppliedExtensions(MetadataExtension.class)
@ -79,25 +83,30 @@ public class ExtensionManagerTest {
for (LogRecord record : handler.getStoredLogRecords()) {
logMessages.add(record.getMessage());
}
assertThat(logMessages.build()).contains(
assertThat(logMessages.build())
.contains(
"Client clientId is attempting to run HelloFlow without declaring "
+ "URIs [urn:google:params:xml:ns:metadata-1.0] on login");
}
@Test
public void testBlacklistedExtensions_forbiddenWhenUndeclared() throws Exception {
ExtensionManager manager = new TestInstanceBuilder()
ExtensionManager manager =
new TestInstanceBuilder()
.setEppRequestSource(EppRequestSource.TOOL)
.setDeclaredUris()
.setSuppliedExtensions(FeeInfoCommandExtensionV06.class)
.build();
manager.register(FeeInfoCommandExtensionV06.class);
assertThrows(UndeclaredServiceExtensionException.class, () -> manager.validate());
EppException thrown =
expectThrows(UndeclaredServiceExtensionException.class, manager::validate);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testBlacklistedExtensions_allowedWhenDeclared() throws Exception {
ExtensionManager manager = new TestInstanceBuilder()
ExtensionManager manager =
new TestInstanceBuilder()
.setEppRequestSource(EppRequestSource.TOOL)
.setDeclaredUris(ServiceExtension.FEE_0_6.getUri())
.setSuppliedExtensions(FeeInfoCommandExtensionV06.class)
@ -108,7 +117,8 @@ public class ExtensionManagerTest {
@Test
public void testMetadataExtension_allowedForToolSource() throws Exception {
ExtensionManager manager = new TestInstanceBuilder()
ExtensionManager manager =
new TestInstanceBuilder()
.setEppRequestSource(EppRequestSource.TOOL)
.setDeclaredUris()
.setSuppliedExtensions(MetadataExtension.class)
@ -119,18 +129,21 @@ public class ExtensionManagerTest {
@Test
public void testMetadataExtension_forbiddenWhenNotToolSource() throws Exception {
ExtensionManager manager = new TestInstanceBuilder()
ExtensionManager manager =
new TestInstanceBuilder()
.setEppRequestSource(EppRequestSource.CONSOLE)
.setDeclaredUris()
.setSuppliedExtensions(MetadataExtension.class)
.build();
manager.register(MetadataExtension.class);
assertThrows(OnlyToolCanPassMetadataException.class, () -> manager.validate());
EppException thrown = expectThrows(OnlyToolCanPassMetadataException.class, manager::validate);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testSuperuserExtension_allowedForToolSource() throws Exception {
ExtensionManager manager = new TestInstanceBuilder()
ExtensionManager manager =
new TestInstanceBuilder()
.setEppRequestSource(EppRequestSource.TOOL)
.setDeclaredUris()
.setSuppliedExtensions(DomainTransferRequestSuperuserExtension.class)
@ -142,36 +155,44 @@ public class ExtensionManagerTest {
@Test
public void testSuperuserExtension_forbiddenWhenNotSuperuser() throws Exception {
ExtensionManager manager = new TestInstanceBuilder()
ExtensionManager manager =
new TestInstanceBuilder()
.setEppRequestSource(EppRequestSource.TOOL)
.setDeclaredUris()
.setSuppliedExtensions(DomainTransferRequestSuperuserExtension.class)
.setIsSuperuser(false)
.build();
manager.register(DomainTransferRequestSuperuserExtension.class);
assertThrows(UnauthorizedForSuperuserExtensionException.class, () -> manager.validate());
EppException thrown =
expectThrows(UnauthorizedForSuperuserExtensionException.class, manager::validate);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testSuperuserExtension_forbiddenWhenNotToolSource() throws Exception {
ExtensionManager manager = new TestInstanceBuilder()
ExtensionManager manager =
new TestInstanceBuilder()
.setEppRequestSource(EppRequestSource.CONSOLE)
.setDeclaredUris()
.setSuppliedExtensions(DomainTransferRequestSuperuserExtension.class)
.setIsSuperuser(true)
.build();
manager.register(DomainTransferRequestSuperuserExtension.class);
assertThrows(UnauthorizedForSuperuserExtensionException.class, () -> manager.validate());
EppException thrown =
expectThrows(UnauthorizedForSuperuserExtensionException.class, manager::validate);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testUnimplementedExtensionsForbidden() throws Exception {
ExtensionManager manager = new TestInstanceBuilder()
ExtensionManager manager =
new TestInstanceBuilder()
.setEppRequestSource(EppRequestSource.TOOL)
.setDeclaredUris()
.setSuppliedExtensions(LaunchCreateExtension.class)
.build();
assertThrows(UnimplementedExtensionException.class, () -> manager.validate());
EppException thrown = expectThrows(UnimplementedExtensionException.class, manager::validate);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
/** A builder for a test-ready {@link ExtensionManager} instance. */

View file

@ -19,7 +19,8 @@ import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.tmch.ClaimsListShardTest.createTestClaimsListShard;
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.LogsSubject.assertAboutLogs;
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
@ -132,7 +133,8 @@ public abstract class ResourceFlowTestCase<F extends Flow, R extends EppResource
@Test
public void testRequiresLogin() throws Exception {
sessionMetadata.setClientId(null);
assertThrows(NotLoggedInException.class, this::runFlow);
EppException thrown = expectThrows(NotLoggedInException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
/**

View file

@ -17,8 +17,10 @@ package google.registry.flows.contact;
import static google.registry.model.eppoutput.CheckData.ContactCheck.create;
import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistDeletedContact;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
import static google.registry.testing.JUnitBackports.expectThrows;
import google.registry.flows.EppException;
import google.registry.flows.ResourceCheckFlowTestCase;
import google.registry.flows.exceptions.TooManyResourceChecksException;
import google.registry.model.contact.ContactResource;
@ -77,7 +79,8 @@ public class ContactCheckFlowTest
@Test
public void testTooManyIds() throws Exception {
setEppInput("contact_check_51.xml");
assertThrows(TooManyResourceChecksException.class, this::runFlow);
EppException thrown = expectThrows(TooManyResourceChecksException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test

View file

@ -19,9 +19,10 @@ import static google.registry.testing.ContactResourceSubject.assertAboutContacts
import static google.registry.testing.DatastoreHelper.assertNoBillingEvents;
import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistDeletedContact;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
import static google.registry.testing.JUnitBackports.expectThrows;
import google.registry.flows.EppException;
import google.registry.flows.ResourceFlowTestCase;
import google.registry.flows.contact.ContactFlowUtils.BadInternationalizedPostalInfoException;
import google.registry.flows.contact.ContactFlowUtils.DeclineContactDisclosureFieldDisallowedPolicyException;
@ -75,6 +76,7 @@ public class ContactCreateFlowTest
.hasMessageThat()
.contains(
String.format("Object with given ID (%s) already exists", getUniqueIdFromCommand()));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -86,13 +88,17 @@ public class ContactCreateFlowTest
@Test
public void testFailure_nonAsciiInIntAddress() throws Exception {
setEppInput("contact_create_hebrew_int.xml");
assertThrows(BadInternationalizedPostalInfoException.class, this::runFlow);
EppException thrown =
expectThrows(BadInternationalizedPostalInfoException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_declineDisclosure() throws Exception {
setEppInput("contact_create_decline_disclosure.xml");
assertThrows(DeclineContactDisclosureFieldDisallowedPolicyException.class, this::runFlow);
EppException thrown =
expectThrows(DeclineContactDisclosureFieldDisallowedPolicyException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test

View file

@ -23,10 +23,11 @@ import static google.registry.testing.DatastoreHelper.newDomainResource;
import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistDeletedContact;
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.collect.ImmutableSet;
import google.registry.flows.EppException;
import google.registry.flows.ResourceFlowTestCase;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
import google.registry.flows.ResourceFlowUtils.ResourceNotOwnedException;
@ -75,6 +76,7 @@ public class ContactDeleteFlowTest
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, this::runFlow);
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -83,6 +85,7 @@ public class ContactDeleteFlowTest
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, this::runFlow);
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -103,21 +106,23 @@ public class ContactDeleteFlowTest
StatusValue.PENDING_DELETE, ResourceStatusProhibitsOperationException.class);
}
private void doFailingStatusTest(StatusValue statusValue, Class<? extends Exception> exception)
private void doFailingStatusTest(StatusValue statusValue, Class<? extends EppException> exception)
throws Exception {
persistResource(
newContactResource(getUniqueIdFromCommand()).asBuilder()
.setStatusValues(ImmutableSet.of(statusValue))
.build());
Exception e = expectThrows(exception, this::runFlow);
assertThat(e).hasMessageThat().contains(statusValue.getXmlName());
EppException thrown = expectThrows(exception, this::runFlow);
assertThat(thrown).hasMessageThat().contains(statusValue.getXmlName());
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_unauthorizedClient() throws Exception {
sessionMetadata.setClientId("NewRegistrar");
persistActiveContact(getUniqueIdFromCommand());
assertThrows(ResourceNotOwnedException.class, this::runFlow);
EppException thrown = expectThrows(ResourceNotOwnedException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -131,7 +136,8 @@ public class ContactDeleteFlowTest
assertAboutContacts().that(deletedContact).hasStatusValue(StatusValue.PENDING_DELETE);
assertAsyncDeletionTaskEnqueued(
deletedContact, "NewRegistrar", Trid.create("ABC-12345", "server-trid"), true);
assertAboutContacts().that(deletedContact)
assertAboutContacts()
.that(deletedContact)
.hasOnlyOneHistoryEntryWhich()
.hasType(HistoryEntry.Type.CONTACT_PENDING_DELETE);
assertNoBillingEvents();
@ -142,7 +148,8 @@ public class ContactDeleteFlowTest
createTld("tld");
persistResource(
newDomainResource("example.tld", persistActiveContact(getUniqueIdFromCommand())));
assertThrows(ResourceToDeleteIsReferencedException.class, this::runFlow);
EppException thrown = expectThrows(ResourceToDeleteIsReferencedException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -150,7 +157,8 @@ public class ContactDeleteFlowTest
createTld("tld");
persistResource(
newDomainResource("example.tld", persistActiveContact(getUniqueIdFromCommand())));
assertThrows(ResourceToDeleteIsReferencedException.class, this::runFlow);
EppException thrown = expectThrows(ResourceToDeleteIsReferencedException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test

View file

@ -20,6 +20,7 @@ import static google.registry.testing.DatastoreHelper.assertNoBillingEvents;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.newDomainResource;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
import static google.registry.testing.JUnitBackports.expectThrows;
import com.google.common.collect.ImmutableList;
@ -167,6 +168,7 @@ public class ContactInfoFlowTest extends ResourceFlowTestCase<ContactInfoFlow, C
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, this::runFlow);
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -175,6 +177,7 @@ public class ContactInfoFlowTest extends ResourceFlowTestCase<ContactInfoFlow, C
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, this::runFlow);
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test

View file

@ -23,9 +23,10 @@ import static google.registry.testing.DatastoreHelper.deleteResource;
import static google.registry.testing.DatastoreHelper.getOnlyPollMessage;
import static google.registry.testing.DatastoreHelper.getPollMessages;
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 google.registry.flows.EppException;
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
import google.registry.flows.ResourceFlowUtils.ResourceNotOwnedException;
@ -144,65 +145,82 @@ public class ContactTransferApproveFlowTest
contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
assertThrows(
EppException thrown = expectThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("contact_transfer_approve_with_authinfo.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_neverBeenTransferred() throws Exception {
changeTransferStatus(null);
assertThrows(
EppException thrown =
expectThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_approve.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_clientApproved() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_APPROVED);
assertThrows(
EppException thrown =
expectThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_approve.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_clientRejected() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_REJECTED);
assertThrows(
EppException thrown =
expectThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_approve.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_clientCancelled() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
assertThrows(
EppException thrown =
expectThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_approve.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_serverApproved() throws Exception {
changeTransferStatus(TransferStatus.SERVER_APPROVED);
assertThrows(
EppException thrown =
expectThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_approve.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_serverCancelled() throws Exception {
changeTransferStatus(TransferStatus.SERVER_CANCELLED);
assertThrows(
EppException thrown =
expectThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_approve.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_gainingClient() throws Exception {
setClientIdForFlow("NewRegistrar");
assertThrows(
EppException thrown =
expectThrows(
ResourceNotOwnedException.class, () -> doFailingTest("contact_transfer_approve.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_unrelatedClient() throws Exception {
setClientIdForFlow("ClientZ");
assertThrows(
EppException thrown =
expectThrows(
ResourceNotOwnedException.class, () -> doFailingTest("contact_transfer_approve.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -214,6 +232,7 @@ public class ContactTransferApproveFlowTest
ResourceDoesNotExistException.class,
() -> doFailingTest("contact_transfer_approve.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -226,6 +245,7 @@ public class ContactTransferApproveFlowTest
ResourceDoesNotExistException.class,
() -> doFailingTest("contact_transfer_approve.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test

View file

@ -22,9 +22,10 @@ import static google.registry.testing.DatastoreHelper.deleteResource;
import static google.registry.testing.DatastoreHelper.getOnlyPollMessage;
import static google.registry.testing.DatastoreHelper.getPollMessages;
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 google.registry.flows.EppException;
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
import google.registry.flows.exceptions.NotPendingTransferException;
@ -124,80 +125,103 @@ public class ContactTransferCancelFlowTest
@Test
public void testFailure_badContactPassword() throws Exception {
// Change the contact's password so it does not match the password in the file.
contact = persistResource(
contact.asBuilder()
contact =
persistResource(
contact
.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
assertThrows(
EppException thrown =
expectThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("contact_transfer_cancel_with_authinfo.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_neverBeenTransferred() throws Exception {
changeTransferStatus(null);
assertThrows(
EppException thrown =
expectThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_cancel.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_clientApproved() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_APPROVED);
assertThrows(
EppException thrown =
expectThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_cancel.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_clientRejected() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_REJECTED);
assertThrows(
EppException thrown =
expectThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_cancel.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_clientCancelled() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
assertThrows(
EppException thrown =
expectThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_cancel.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_serverApproved() throws Exception {
changeTransferStatus(TransferStatus.SERVER_APPROVED);
assertThrows(
EppException thrown =
expectThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_cancel.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_serverCancelled() throws Exception {
changeTransferStatus(TransferStatus.SERVER_CANCELLED);
assertThrows(
EppException thrown =
expectThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_cancel.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_sponsoringClient() throws Exception {
setClientIdForFlow("TheRegistrar");
assertThrows(
NotTransferInitiatorException.class, () -> doFailingTest("contact_transfer_cancel.xml"));
EppException thrown =
expectThrows(
NotTransferInitiatorException.class,
() -> doFailingTest("contact_transfer_cancel.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_unrelatedClient() throws Exception {
setClientIdForFlow("ClientZ");
assertThrows(
NotTransferInitiatorException.class, () -> doFailingTest("contact_transfer_cancel.xml"));
EppException thrown =
expectThrows(
NotTransferInitiatorException.class,
() -> doFailingTest("contact_transfer_cancel.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_deletedContact() throws Exception {
contact = persistResource(
contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
contact =
persistResource(contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
ResourceDoesNotExistException thrown =
expectThrows(
ResourceDoesNotExistException.class,
() -> doFailingTest("contact_transfer_cancel.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -208,6 +232,7 @@ public class ContactTransferCancelFlowTest
ResourceDoesNotExistException.class,
() -> doFailingTest("contact_transfer_cancel.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test

View file

@ -19,9 +19,10 @@ import static google.registry.testing.ContactResourceSubject.assertAboutContacts
import static google.registry.testing.DatastoreHelper.assertNoBillingEvents;
import static google.registry.testing.DatastoreHelper.deleteResource;
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 google.registry.flows.EppException;
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
import google.registry.flows.exceptions.NoTransferHistoryToQueryException;
@ -137,13 +138,17 @@ public class ContactTransferQueryFlowTest
@Test
public void testFailure_badContactPassword() throws Exception {
// Change the contact's password so it does not match the password in the file.
contact = persistResource(
contact.asBuilder()
contact =
persistResource(
contact
.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
assertThrows(
EppException thrown =
expectThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("contact_transfer_query_with_authinfo.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -151,34 +156,42 @@ public class ContactTransferQueryFlowTest
// Set the contact to a different ROID, but don't persist it; this is just so the substitution
// code above will write the wrong ROID into the file.
contact = contact.asBuilder().setRepoId("DEADBEEF_TLD-ROID").build();
assertThrows(
EppException thrown =
expectThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("contact_transfer_query_with_roid.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_neverBeenTransferred() throws Exception {
changeTransferStatus(null);
assertThrows(
NoTransferHistoryToQueryException.class, () -> doFailingTest("contact_transfer_query.xml"));
EppException thrown =
expectThrows(
NoTransferHistoryToQueryException.class,
() -> doFailingTest("contact_transfer_query.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_unrelatedClient() throws Exception {
setClientIdForFlow("ClientZ");
assertThrows(
EppException thrown =
expectThrows(
NotAuthorizedToViewTransferException.class,
() -> doFailingTest("contact_transfer_query.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_deletedContact() throws Exception {
contact = persistResource(
contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
contact =
persistResource(contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
ResourceDoesNotExistException thrown =
expectThrows(
ResourceDoesNotExistException.class, () -> doFailingTest("contact_transfer_query.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -188,6 +201,7 @@ public class ContactTransferQueryFlowTest
expectThrows(
ResourceDoesNotExistException.class, () -> doFailingTest("contact_transfer_query.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test

View file

@ -22,9 +22,10 @@ import static google.registry.testing.DatastoreHelper.deleteResource;
import static google.registry.testing.DatastoreHelper.getOnlyPollMessage;
import static google.registry.testing.DatastoreHelper.getPollMessages;
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 google.registry.flows.EppException;
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
import google.registry.flows.ResourceFlowUtils.ResourceNotOwnedException;
@ -139,80 +140,101 @@ public class ContactTransferRejectFlowTest
@Test
public void testFailure_badPassword() throws Exception {
// Change the contact's password so it does not match the password in the file.
contact = persistResource(
contact.asBuilder()
contact =
persistResource(
contact
.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
assertThrows(
EppException thrown =
expectThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("contact_transfer_reject_with_authinfo.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_neverBeenTransferred() throws Exception {
changeTransferStatus(null);
assertThrows(
EppException thrown =
expectThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_reject.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_clientApproved() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_APPROVED);
assertThrows(
EppException thrown =
expectThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_reject.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_clientRejected() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_REJECTED);
assertThrows(
EppException thrown =
expectThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_reject.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_clientCancelled() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
assertThrows(
EppException thrown =
expectThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_reject.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_serverApproved() throws Exception {
changeTransferStatus(TransferStatus.SERVER_APPROVED);
assertThrows(
EppException thrown =
expectThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_reject.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_serverCancelled() throws Exception {
changeTransferStatus(TransferStatus.SERVER_CANCELLED);
assertThrows(
EppException thrown =
expectThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_reject.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_gainingClient() throws Exception {
setClientIdForFlow("NewRegistrar");
assertThrows(
EppException thrown =
expectThrows(
ResourceNotOwnedException.class, () -> doFailingTest("contact_transfer_reject.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_unrelatedClient() throws Exception {
setClientIdForFlow("ClientZ");
assertThrows(
EppException thrown =
expectThrows(
ResourceNotOwnedException.class, () -> doFailingTest("contact_transfer_reject.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_deletedContact() throws Exception {
contact = persistResource(
contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
contact =
persistResource(contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
ResourceDoesNotExistException thrown =
expectThrows(
ResourceDoesNotExistException.class,
() -> doFailingTest("contact_transfer_reject.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -223,6 +245,7 @@ public class ContactTransferRejectFlowTest
ResourceDoesNotExistException.class,
() -> doFailingTest("contact_transfer_reject.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test

View file

@ -28,12 +28,13 @@ import static google.registry.testing.DatastoreHelper.deleteResource;
import static google.registry.testing.DatastoreHelper.getPollMessages;
import static google.registry.testing.DatastoreHelper.persistActiveContact;
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.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.googlecode.objectify.Key;
import google.registry.flows.EppException;
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
import google.registry.flows.exceptions.AlreadyPendingTransferException;
@ -156,20 +157,27 @@ public class ContactTransferRequestFlowTest
@Test
public void testFailure_noAuthInfo() throws Exception {
assertThrows(
EppException thrown =
expectThrows(
MissingTransferRequestAuthInfoException.class,
() -> doFailingTest("contact_transfer_request_no_authinfo.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_badPassword() throws Exception {
// Change the contact's password so it does not match the password in the file.
contact = persistResource(
contact.asBuilder()
contact =
persistResource(
contact
.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
assertThrows(
BadAuthInfoForResourceException.class, () -> doFailingTest("contact_transfer_request.xml"));
EppException thrown =
expectThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("contact_transfer_request.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -204,33 +212,45 @@ public class ContactTransferRequestFlowTest
@Test
public void testFailure_pending() throws Exception {
contact = persistResource(
contact.asBuilder()
.setTransferData(contact.getTransferData().asBuilder()
contact =
persistResource(
contact
.asBuilder()
.setTransferData(
contact
.getTransferData()
.asBuilder()
.setTransferStatus(TransferStatus.PENDING)
.setPendingTransferExpirationTime(clock.nowUtc().plusDays(1))
.build())
.build());
assertThrows(
AlreadyPendingTransferException.class, () -> doFailingTest("contact_transfer_request.xml"));
EppException thrown =
expectThrows(
AlreadyPendingTransferException.class,
() -> doFailingTest("contact_transfer_request.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_sponsoringClient() throws Exception {
setClientIdForFlow("TheRegistrar");
assertThrows(
ObjectAlreadySponsoredException.class, () -> doFailingTest("contact_transfer_request.xml"));
EppException thrown =
expectThrows(
ObjectAlreadySponsoredException.class,
() -> doFailingTest("contact_transfer_request.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_deletedContact() throws Exception {
contact = persistResource(
contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
contact =
persistResource(contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
ResourceDoesNotExistException thrown =
expectThrows(
ResourceDoesNotExistException.class,
() -> doFailingTest("contact_transfer_request.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -241,39 +261,45 @@ public class ContactTransferRequestFlowTest
ResourceDoesNotExistException.class,
() -> doFailingTest("contact_transfer_request.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_clientTransferProhibited() throws Exception {
contact = persistResource(
contact =
persistResource(
contact.asBuilder().addStatusValue(StatusValue.CLIENT_TRANSFER_PROHIBITED).build());
ResourceStatusProhibitsOperationException thrown =
expectThrows(
ResourceStatusProhibitsOperationException.class,
() -> doFailingTest("contact_transfer_request.xml"));
assertThat(thrown).hasMessageThat().contains("clientTransferProhibited");
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_serverTransferProhibited() throws Exception {
contact = persistResource(
contact =
persistResource(
contact.asBuilder().addStatusValue(StatusValue.SERVER_TRANSFER_PROHIBITED).build());
ResourceStatusProhibitsOperationException thrown =
expectThrows(
ResourceStatusProhibitsOperationException.class,
() -> doFailingTest("contact_transfer_request.xml"));
assertThat(thrown).hasMessageThat().contains("serverTransferProhibited");
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_pendingDelete() throws Exception {
contact = persistResource(
contact.asBuilder().addStatusValue(StatusValue.PENDING_DELETE).build());
contact =
persistResource(contact.asBuilder().addStatusValue(StatusValue.PENDING_DELETE).build());
ResourceStatusProhibitsOperationException thrown =
expectThrows(
ResourceStatusProhibitsOperationException.class,
() -> doFailingTest("contact_transfer_request.xml"));
assertThat(thrown).hasMessageThat().contains("pendingDelete");
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test

View file

@ -21,11 +21,12 @@ import static google.registry.testing.DatastoreHelper.newContactResource;
import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistDeletedContact;
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.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import google.registry.flows.EppException;
import google.registry.flows.ResourceFlowTestCase;
import google.registry.flows.ResourceFlowUtils.AddRemoveSameValueException;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
@ -259,6 +260,7 @@ public class ContactUpdateFlowTest
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, this::runFlow);
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -267,13 +269,15 @@ public class ContactUpdateFlowTest
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, this::runFlow);
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_statusValueNotClientSettable() throws Exception {
setEppInput("contact_update_prohibited_status.xml");
persistActiveContact(getUniqueIdFromCommand());
assertThrows(StatusNotClientSettableException.class, this::runFlow);
EppException thrown = expectThrows(StatusNotClientSettableException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -282,16 +286,15 @@ public class ContactUpdateFlowTest
persistActiveContact(getUniqueIdFromCommand());
clock.advanceOneMilli();
runFlowAssertResponse(
CommitMode.LIVE,
UserPrivileges.SUPERUSER,
loadFile("contact_update_response.xml"));
CommitMode.LIVE, UserPrivileges.SUPERUSER, loadFile("contact_update_response.xml"));
}
@Test
public void testFailure_unauthorizedClient() throws Exception {
sessionMetadata.setClientId("NewRegistrar");
persistActiveContact(getUniqueIdFromCommand());
assertThrows(ResourceNotOwnedException.class, this::runFlow);
EppException thrown = expectThrows(ResourceNotOwnedException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -307,11 +310,13 @@ public class ContactUpdateFlowTest
public void testSuccess_clientUpdateProhibited_removed() throws Exception {
setEppInput("contact_update_remove_client_update_prohibited.xml");
persistResource(
newContactResource(getUniqueIdFromCommand()).asBuilder()
newContactResource(getUniqueIdFromCommand())
.asBuilder()
.setStatusValues(ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED))
.build());
doSuccessfulTest();
assertAboutContacts().that(reloadResourceByForeignKey())
assertAboutContacts()
.that(reloadResourceByForeignKey())
.doesNotHaveStatusValue(StatusValue.CLIENT_UPDATE_PROHIBITED);
}
@ -319,48 +324,56 @@ public class ContactUpdateFlowTest
public void testSuccess_superuserClientUpdateProhibited_notRemoved() throws Exception {
setEppInput("contact_update_prohibited_status.xml");
persistResource(
newContactResource(getUniqueIdFromCommand()).asBuilder()
newContactResource(getUniqueIdFromCommand())
.asBuilder()
.setStatusValues(ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED))
.build());
clock.advanceOneMilli();
runFlowAssertResponse(
CommitMode.LIVE,
UserPrivileges.SUPERUSER,
loadFile("contact_update_response.xml"));
assertAboutContacts().that(reloadResourceByForeignKey())
.hasStatusValue(StatusValue.CLIENT_UPDATE_PROHIBITED).and()
CommitMode.LIVE, UserPrivileges.SUPERUSER, loadFile("contact_update_response.xml"));
assertAboutContacts()
.that(reloadResourceByForeignKey())
.hasStatusValue(StatusValue.CLIENT_UPDATE_PROHIBITED)
.and()
.hasStatusValue(StatusValue.SERVER_DELETE_PROHIBITED);
}
@Test
public void testFailure_clientUpdateProhibited_notRemoved() throws Exception {
persistResource(
newContactResource(getUniqueIdFromCommand()).asBuilder()
newContactResource(getUniqueIdFromCommand())
.asBuilder()
.setStatusValues(ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED))
.build());
assertThrows(ResourceHasClientUpdateProhibitedException.class, this::runFlow);
EppException thrown =
expectThrows(ResourceHasClientUpdateProhibitedException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_serverUpdateProhibited() throws Exception {
persistResource(
newContactResource(getUniqueIdFromCommand()).asBuilder()
newContactResource(getUniqueIdFromCommand())
.asBuilder()
.setStatusValues(ImmutableSet.of(StatusValue.SERVER_UPDATE_PROHIBITED))
.build());
ResourceStatusProhibitsOperationException thrown =
expectThrows(ResourceStatusProhibitsOperationException.class, this::runFlow);
assertThat(thrown).hasMessageThat().contains("serverUpdateProhibited");
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_pendingDeleteProhibited() throws Exception {
persistResource(
newContactResource(getUniqueIdFromCommand()).asBuilder()
newContactResource(getUniqueIdFromCommand())
.asBuilder()
.setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE))
.build());
ResourceStatusProhibitsOperationException thrown =
expectThrows(ResourceStatusProhibitsOperationException.class, this::runFlow);
assertThat(thrown).hasMessageThat().contains("pendingDelete");
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -373,21 +386,26 @@ public class ContactUpdateFlowTest
public void testFailure_nonAsciiInIntAddress() throws Exception {
setEppInput("contact_update_hebrew_int.xml");
persistActiveContact(getUniqueIdFromCommand());
assertThrows(BadInternationalizedPostalInfoException.class, this::runFlow);
EppException thrown =
expectThrows(BadInternationalizedPostalInfoException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_declineDisclosure() throws Exception {
setEppInput("contact_update_decline_disclosure.xml");
persistActiveContact(getUniqueIdFromCommand());
assertThrows(DeclineContactDisclosureFieldDisallowedPolicyException.class, this::runFlow);
EppException thrown =
expectThrows(DeclineContactDisclosureFieldDisallowedPolicyException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_addRemoveSameValue() throws Exception {
setEppInput("contact_update_add_remove_same.xml");
persistActiveContact(getUniqueIdFromCommand());
assertThrows(AddRemoveSameValueException.class, this::runFlow);
EppException thrown = expectThrows(AddRemoveSameValueException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test

View file

@ -30,7 +30,7 @@ import static google.registry.testing.DatastoreHelper.persistReservedList;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainApplicationSubject.assertAboutApplications;
import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
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.TaskQueueHelper.assertDnsTasksEnqueued;
import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued;
@ -43,6 +43,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.domain.DomainAllocateFlow.HasFinalStatusException;
import google.registry.flows.domain.DomainAllocateFlow.MissingApplicationException;
@ -258,6 +259,7 @@ public class DomainAllocateFlowTest
NameserversNotAllowedForTldException thrown =
expectThrows(NameserversNotAllowedForTldException.class, this::runFlowAsSuperuser);
assertThat(thrown).hasMessageThat().contains("ns1.example.net");
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -273,6 +275,7 @@ public class DomainAllocateFlowTest
RegistrantNotAllowedException thrown =
expectThrows(RegistrantNotAllowedException.class, this::runFlowAsSuperuser);
assertThat(thrown).hasMessageThat().contains("jd1234");
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -285,9 +288,11 @@ public class DomainAllocateFlowTest
.setAllowedRegistrantContactIds(ImmutableSet.of("jd1234"))
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.example.net, ns2.example.net"))
.build());
assertThrows(
EppException thrown =
expectThrows(
NameserversNotSpecifiedForTldWithNameserverWhitelistException.class,
this::runFlowAsSuperuser);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -319,6 +324,7 @@ public class DomainAllocateFlowTest
NameserversNotAllowedForDomainException thrown =
expectThrows(NameserversNotAllowedForDomainException.class, this::runFlowAsSuperuser);
assertThat(thrown).hasMessageThat().contains("ns1.example.net");
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -333,9 +339,11 @@ public class DomainAllocateFlowTest
"reserved",
"example-one,NAMESERVER_RESTRICTED," + "ns2.example.net:ns3.example.net"))
.build());
assertThrows(
EppException thrown =
expectThrows(
NameserversNotSpecifiedForNameserverRestrictedDomainException.class,
this::runFlowAsSuperuser);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -373,6 +381,7 @@ public class DomainAllocateFlowTest
NameserversNotAllowedForDomainException thrown =
expectThrows(NameserversNotAllowedForDomainException.class, this::runFlowAsSuperuser);
assertThat(thrown).hasMessageThat().contains("ns1.example.net");
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -392,6 +401,7 @@ public class DomainAllocateFlowTest
NameserversNotAllowedForTldException thrown =
expectThrows(NameserversNotAllowedForTldException.class, this::runFlowAsSuperuser);
assertThat(thrown).hasMessageThat().contains("ns1.example.net");
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -404,7 +414,9 @@ public class DomainAllocateFlowTest
@Test
public void testSuccess_nonDefaultAddGracePeriod() throws Exception {
setupDomainApplication("tld", TldState.QUIET_PERIOD);
persistResource(Registry.get("tld").asBuilder()
persistResource(
Registry.get("tld")
.asBuilder()
.setAddGracePeriodLength(Duration.standardMinutes(6))
.build());
doSuccessfulTest(2);
@ -413,7 +425,9 @@ public class DomainAllocateFlowTest
@Test
public void testSuccess_nonDefaultSunrushAddGracePeriod() throws Exception {
setupDomainApplication("tld", TldState.QUIET_PERIOD);
persistResource(Registry.get("tld").asBuilder()
persistResource(
Registry.get("tld")
.asBuilder()
.setSunrushAddGracePeriodLength(Duration.standardMinutes(9))
.build());
doSuccessfulTest(2);
@ -439,9 +453,10 @@ public class DomainAllocateFlowTest
setupDomainApplication("tld", TldState.QUIET_PERIOD);
setEppInput("domain_allocate_dsdata.xml");
doSuccessfulTest(2);
assertAboutDomains().that(reloadResourceByForeignKey())
.hasExactlyDsData(DelegationSignerData.create(
12345, 3, 1, base16().decode("49FD46E6C4B45C55D4AC")));
assertAboutDomains()
.that(reloadResourceByForeignKey())
.hasExactlyDsData(
DelegationSignerData.create(12345, 3, 1, base16().decode("49FD46E6C4B45C55D4AC")));
}
@Test
@ -466,8 +481,10 @@ public class DomainAllocateFlowTest
private void doSuccessfulClaimsNoticeTest() throws Exception {
setEppInput("domain_allocate_claims_notice.xml");
runFlowAsSuperuser();
assertAboutDomains().that(getOnlyGlobalResource(DomainResource.class))
.hasLaunchNotice(LaunchNotice.create(
assertAboutDomains()
.that(getOnlyGlobalResource(DomainResource.class))
.hasLaunchNotice(
LaunchNotice.create(
"370d0b7c9223372036854775807",
"tmch",
DateTime.parse("2011-08-16T09:00:00.0Z"),
@ -478,12 +495,12 @@ public class DomainAllocateFlowTest
public void testSuccess_claimsNotice() throws Exception {
setupDomainApplication("tld", TldState.QUIET_PERIOD);
doSuccessfulClaimsNoticeTest();
String expectedCsv = String.format(
String expectedCsv =
String.format(
"%s,example-one.tld,370d0b7c9223372036854775807,1,"
+ "2010-09-16T10:00:00.000Z,2010-07-16T09:00:00.000Z,2010-08-16T10:00:00.000Z",
reloadResourceByForeignKey().getRepoId());
assertTasksEnqueued(
"lordn-claims", new TaskMatcher().payload(expectedCsv).tag("tld"));
assertTasksEnqueued("lordn-claims", new TaskMatcher().payload(expectedCsv).tag("tld"));
}
@Test
@ -491,7 +508,8 @@ public class DomainAllocateFlowTest
setupDomainApplication("tld", TldState.QUIET_PERIOD);
clock.setTo(DateTime.parse("2011-08-17T09:00:00.0Z"));
doSuccessfulClaimsNoticeTest();
String expectedCsv = String.format(
String expectedCsv =
String.format(
"%s,example-one.tld,370d0b7c9223372036854775807,1,"
+ "2011-08-17T09:00:00.000Z,2010-07-16T09:00:00.000Z,2010-08-16T10:00:00.000Z",
reloadResourceByForeignKey().getRepoId());
@ -505,11 +523,11 @@ public class DomainAllocateFlowTest
doSuccessfulTest(2);
DomainResource domain = getOnlyGlobalResource(DomainResource.class);
assertThat(domain.getSmdId()).isEqualTo(SMD_ID);
String expectedCsv = String.format(
String expectedCsv =
String.format(
"%s,example-one.tld,1-1,1,2010-09-16T10:00:00.000Z,2010-08-16T10:00:00.000Z",
domain.getRepoId());
assertTasksEnqueued(
"lordn-sunrise", new TaskMatcher().payload(expectedCsv).tag("tld"));
assertTasksEnqueued("lordn-sunrise", new TaskMatcher().payload(expectedCsv).tag("tld"));
}
@Test
@ -575,7 +593,9 @@ public class DomainAllocateFlowTest
public void testFailure_alreadyExists() throws Exception {
setupDomainApplication("tld", TldState.QUIET_PERIOD);
persistActiveDomain(getUniqueIdFromCommand());
assertThrows(ResourceAlreadyExistsException.class, this::runFlowAsSuperuser);
EppException thrown =
expectThrows(ResourceAlreadyExistsException.class, this::runFlowAsSuperuser);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -610,32 +630,34 @@ public class DomainAllocateFlowTest
public void testFailure_applicationDeleted() throws Exception {
setupDomainApplication("tld", TldState.QUIET_PERIOD);
persistResource(application.asBuilder().setDeletionTime(clock.nowUtc()).build());
assertThrows(MissingApplicationException.class, this::runFlowAsSuperuser);
EppException thrown = expectThrows(MissingApplicationException.class, this::runFlowAsSuperuser);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_applicationRejected() throws Exception {
setupDomainApplication("tld", TldState.QUIET_PERIOD);
persistResource(application.asBuilder()
.setApplicationStatus(ApplicationStatus.REJECTED)
.build());
assertThrows(HasFinalStatusException.class, this::runFlowAsSuperuser);
persistResource(
application.asBuilder().setApplicationStatus(ApplicationStatus.REJECTED).build());
EppException thrown = expectThrows(HasFinalStatusException.class, this::runFlowAsSuperuser);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_applicationAllocated() throws Exception {
setupDomainApplication("tld", TldState.QUIET_PERIOD);
persistResource(application.asBuilder()
.setApplicationStatus(ApplicationStatus.ALLOCATED)
.build());
assertThrows(HasFinalStatusException.class, this::runFlowAsSuperuser);
persistResource(
application.asBuilder().setApplicationStatus(ApplicationStatus.ALLOCATED).build());
EppException thrown = expectThrows(HasFinalStatusException.class, this::runFlowAsSuperuser);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_applicationDoesNotExist() throws Exception {
setupDomainApplication("tld", TldState.QUIET_PERIOD);
setEppInput("domain_allocate_bad_application_roid.xml");
assertThrows(MissingApplicationException.class, this::runFlowAsSuperuser);
EppException thrown = expectThrows(MissingApplicationException.class, this::runFlowAsSuperuser);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -644,16 +666,20 @@ public class DomainAllocateFlowTest
clock.advanceOneMilli();
setEppInput("domain_allocate_no_nameservers.xml");
assertTransactionalFlow(true);
assertThrows(
EppException thrown =
expectThrows(
OnlySuperuserCanAllocateException.class,
() -> runFlow(CommitMode.LIVE, UserPrivileges.NORMAL));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_max10Years() throws Exception {
setupDomainApplication("tld", TldState.QUIET_PERIOD);
setEppInput("domain_allocate_11_years.xml");
assertThrows(ExceedsMaxRegistrationYearsException.class, this::runFlowAsSuperuser);
EppException thrown =
expectThrows(ExceedsMaxRegistrationYearsException.class, this::runFlowAsSuperuser);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -678,7 +704,8 @@ public class DomainAllocateFlowTest
DomainResource domain = reloadResourceByForeignKey();
HistoryEntry historyEntry =
getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_ALLOCATE);
assertThat(historyEntry.getDomainTransactionRecords()).containsExactly(
assertThat(historyEntry.getDomainTransactionRecords())
.containsExactly(
DomainTransactionRecord.create(
"tld",
historyEntry.getModificationTime().plusMinutes(9),

View file

@ -20,9 +20,11 @@ import static google.registry.testing.DatastoreHelper.newDomainResource;
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.collect.ImmutableList;
import google.registry.flows.EppException;
import google.registry.flows.FlowTestCase;
import google.registry.flows.poll.PollRequestFlow.UnexpectedMessageIdException;
import google.registry.model.contact.ContactResource;
@ -221,6 +223,7 @@ public class PollRequestFlowTest extends FlowTestCase<PollRequestFlow> {
public void testFailure_messageIdProvided() throws Exception {
setEppInput("poll_with_id.xml");
assertTransactionalFlow(false);
assertThrows(UnexpectedMessageIdException.class, this::runFlow);
EppException thrown = expectThrows(UnexpectedMessageIdException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
}

View file

@ -17,8 +17,10 @@ package google.registry.flows.session;
import static google.registry.testing.DatastoreHelper.deleteResource;
import static google.registry.testing.DatastoreHelper.loadRegistrar;
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 google.registry.flows.EppException;
import google.registry.flows.EppException.UnimplementedExtensionException;
import google.registry.flows.EppException.UnimplementedObjectServiceException;
import google.registry.flows.EppException.UnimplementedProtocolVersionException;
@ -61,9 +63,10 @@ public abstract class LoginFlowTestCase extends FlowTestCase<LoginFlow> {
}
// Also called in subclasses.
void doFailingTest(String xmlFilename, Class<? extends Exception> exception) throws Exception {
void doFailingTest(String xmlFilename, Class<? extends EppException> exception) throws Exception {
setEppInput(xmlFilename);
assertThrows(exception, this::runFlow);
EppException thrown = expectThrows(exception, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test

View file

@ -15,8 +15,10 @@
package google.registry.flows.session;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
import static google.registry.testing.JUnitBackports.expectThrows;
import google.registry.flows.EppException;
import google.registry.flows.FlowTestCase;
import google.registry.flows.FlowUtils.NotLoggedInException;
import org.junit.Before;
@ -44,6 +46,7 @@ public class LogoutFlowTest extends FlowTestCase<LogoutFlow> {
@Test
public void testFailure() throws Exception {
sessionMetadata.setClientId(null); // Turn off the implicit login
assertThrows(NotLoggedInException.class, this::runFlow);
EppException thrown = expectThrows(NotLoggedInException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
}

View file

@ -18,7 +18,9 @@ import static google.registry.model.registrar.Registrar.State.ACTIVE;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import com.beust.jcommander.ParameterException;
import com.google.common.collect.ImmutableList;
@ -63,7 +65,8 @@ public class ValidateLoginCredentialsCommandTest
@Test
public void testFailure_loginWithBadPassword() throws Exception {
assertThrows(
EppException thrown =
expectThrows(
BadRegistrarPasswordException.class,
() ->
runCommand(
@ -71,11 +74,13 @@ public class ValidateLoginCredentialsCommandTest
"--password=" + new StringBuilder(PASSWORD).reverse(),
"--cert_hash=" + CERT_HASH,
"--ip_address=" + CLIENT_IP));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_loginWithBadCertificateHash() throws Exception {
assertThrows(
EppException thrown =
expectThrows(
EppException.class,
() ->
runCommand(
@ -83,11 +88,13 @@ public class ValidateLoginCredentialsCommandTest
"--password=" + PASSWORD,
"--cert_hash=" + new StringBuilder(CERT_HASH).reverse(),
"--ip_address=" + CLIENT_IP));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_loginWithBadIp() throws Exception {
assertThrows(
EppException thrown =
expectThrows(
EppException.class,
() ->
runCommand(
@ -95,6 +102,7 @@ public class ValidateLoginCredentialsCommandTest
"--password=" + PASSWORD,
"--cert_hash=" + CERT_HASH,
"--ip_address=" + new StringBuilder(CLIENT_IP).reverse()));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test