Refactor assertCommandAndResponse to be "fluent"

This is in preparation for automatic EPP consolidation.

The assertion will now look like:
assertThatCommand("file.xml"[, substitution])
    .atTime(time)
    .hasResponse("file2.xml"[, substitution]);

Also, added convenience functions for often reused commands (login and logout)

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=190617505
This commit is contained in:
guyben 2018-03-27 08:18:47 -07:00 committed by jianglai
parent c1ca88ac9e
commit 422ec9b97a
15 changed files with 892 additions and 1054 deletions

View file

@ -22,7 +22,6 @@ import static google.registry.testing.EppMetricSubject.assertThat;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import google.registry.testing.AppEngineRule; import google.registry.testing.AppEngineRule;
import org.joda.time.DateTime;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -40,13 +39,12 @@ public class EppLifecycleContactTest extends EppTestCase {
@Test @Test
public void testContactLifecycle() throws Exception { public void testContactLifecycle() throws Exception {
assertCommandAndResponse("login_valid.xml", "login_response.xml"); assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
assertCommandAndResponse( assertThatCommand("contact_create_sh8013.xml")
"contact_create_sh8013.xml", .atTime("2000-06-01T00:00:00Z")
ImmutableMap.of(), .hasResponse(
"contact_create_response_sh8013.xml", "contact_create_response_sh8013.xml",
ImmutableMap.of("CRDATE", "2000-06-01T00:00:00Z"), ImmutableMap.of("CRDATE", "2000-06-01T00:00:00Z"));
DateTime.parse("2000-06-01T00:00:00Z"));
assertThat(getRecordedEppMetric()) assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar") .hasClientId("NewRegistrar")
.and() .and()
@ -57,10 +55,9 @@ public class EppLifecycleContactTest extends EppTestCase {
.hasEppTarget("sh8013") .hasEppTarget("sh8013")
.and() .and()
.hasStatus(SUCCESS); .hasStatus(SUCCESS);
assertCommandAndResponse( assertThatCommand("contact_info.xml")
"contact_info.xml", .atTime("2000-06-01T00:01:00Z")
"contact_info_from_create_response.xml", .hasResponse("contact_info_from_create_response.xml");
DateTime.parse("2000-06-01T00:01:00Z"));
assertThat(getRecordedEppMetric()) assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar") .hasClientId("NewRegistrar")
.and() .and()
@ -69,7 +66,8 @@ public class EppLifecycleContactTest extends EppTestCase {
.hasEppTarget("sh8013") .hasEppTarget("sh8013")
.and() .and()
.hasStatus(SUCCESS); .hasStatus(SUCCESS);
assertCommandAndResponse("contact_delete_sh8013.xml", "contact_delete_response_sh8013.xml"); assertThatCommand("contact_delete_sh8013.xml")
.hasResponse("contact_delete_response_sh8013.xml");
assertThat(getRecordedEppMetric()) assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar") .hasClientId("NewRegistrar")
.and() .and()
@ -78,52 +76,46 @@ public class EppLifecycleContactTest extends EppTestCase {
.hasEppTarget("sh8013") .hasEppTarget("sh8013")
.and() .and()
.hasStatus(SUCCESS_WITH_ACTION_PENDING); .hasStatus(SUCCESS_WITH_ACTION_PENDING);
assertCommandAndResponse("logout.xml", "logout_response.xml"); assertThatLogoutSucceeds();
} }
@Test @Test
public void testContactTransferPollMessage() throws Exception { public void testContactTransferPollMessage() throws Exception {
assertCommandAndResponse("login_valid.xml", "login_response.xml"); assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
assertCommandAndResponse( assertThatCommand("contact_create_sh8013.xml")
"contact_create_sh8013.xml", .atTime("2000-06-01T00:00:00Z")
ImmutableMap.of(), .hasResponse(
"contact_create_response_sh8013.xml", "contact_create_response_sh8013.xml",
ImmutableMap.of("CRDATE", "2000-06-01T00:00:00Z"), ImmutableMap.of("CRDATE", "2000-06-01T00:00:00Z"));
DateTime.parse("2000-06-01T00:00:00Z")); assertThatLogoutSucceeds();
assertCommandAndResponse("logout.xml", "logout_response.xml");
// Initiate a transfer of the newly created contact. // Initiate a transfer of the newly created contact.
assertCommandAndResponse("login2_valid.xml", "login_response.xml"); assertThatLoginSucceeds("TheRegistrar", "password2");
assertCommandAndResponse( assertThatCommand("contact_transfer_request.xml")
"contact_transfer_request.xml", .atTime("2000-06-08T22:00:00Z")
"contact_transfer_request_response_alternate.xml", .hasResponse("contact_transfer_request_response_alternate.xml");
DateTime.parse("2000-06-08T22:00:00Z")); assertThatLogoutSucceeds();
assertCommandAndResponse("logout.xml", "logout_response.xml");
// Log back in with the losing registrar, read the poll message, and then ack it. // Log back in with the losing registrar, read the poll message, and then ack it.
assertCommandAndResponse("login_valid.xml", "login_response.xml"); assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
assertCommandAndResponse( assertThatCommand("poll.xml")
"poll.xml", .atTime("2000-06-08T22:01:00Z")
"poll_response_contact_transfer.xml", .hasResponse("poll_response_contact_transfer.xml");
DateTime.parse("2000-06-08T22:01:00Z"));
assertThat(getRecordedEppMetric()) assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar") .hasClientId("NewRegistrar")
.and() .and()
.hasCommandName("PollRequest") .hasCommandName("PollRequest")
.and() .and()
.hasStatus(SUCCESS_WITH_ACK_MESSAGE); .hasStatus(SUCCESS_WITH_ACK_MESSAGE);
assertCommandAndResponse( assertThatCommand("poll_ack.xml", ImmutableMap.of("ID", "2-1-ROID-3-6-2000"))
"poll_ack.xml", .atTime("2000-06-08T22:02:00Z")
ImmutableMap.of("ID", "2-1-ROID-3-6-2000"), .hasResponse("poll_ack_response_empty.xml");
"poll_ack_response_empty.xml",
ImmutableMap.of(),
DateTime.parse("2000-06-08T22:02:00Z"));
assertThat(getRecordedEppMetric()) assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar") .hasClientId("NewRegistrar")
.and() .and()
.hasCommandName("PollAck") .hasCommandName("PollAck")
.and() .and()
.hasStatus(SUCCESS_WITH_NO_MESSAGES); .hasStatus(SUCCESS_WITH_NO_MESSAGES);
assertCommandAndResponse("logout.xml", "logout_response.xml"); assertThatLogoutSucceeds();
} }
} }

View file

@ -50,83 +50,72 @@ public class EppLifecycleDomainApplicationTest extends EppTestCase {
/** Create the two administrative contacts and two hosts. */ /** Create the two administrative contacts and two hosts. */
void createContactsAndHosts() throws Exception { void createContactsAndHosts() throws Exception {
DateTime startTime = DateTime.parse("2000-06-01T00:00:00Z"); DateTime startTime = DateTime.parse("2000-06-01T00:00:00Z");
assertCommandAndResponse( assertThatCommand("contact_create_sh8013.xml")
"contact_create_sh8013.xml", .atTime(startTime)
ImmutableMap.of(), .hasResponse(
"contact_create_response_sh8013.xml", "contact_create_response_sh8013.xml",
ImmutableMap.of("CRDATE", "2000-06-01T00:00:00Z"), ImmutableMap.of("CRDATE", "2000-06-01T00:00:00Z"));
startTime); assertThatCommand("contact_create_jd1234.xml")
assertCommandAndResponse( .atTime(startTime.plusMinutes(1))
"contact_create_jd1234.xml", .hasResponse("contact_create_response_jd1234.xml");
"contact_create_response_jd1234.xml", assertThatCommand("host_create.xml", ImmutableMap.of("HOSTNAME", "ns1.example.external"))
startTime.plusMinutes(1)); .atTime(startTime.plusMinutes(2))
assertCommandAndResponse( .hasResponse(
"host_create.xml", "host_create_response.xml",
ImmutableMap.of("HOSTNAME", "ns1.example.external"), ImmutableMap.of(
"host_create_response.xml", "HOSTNAME", "ns1.example.external", "CRDATE", startTime.plusMinutes(2).toString()));
ImmutableMap.of( assertThatCommand("host_create.xml", ImmutableMap.of("HOSTNAME", "ns2.example.external"))
"HOSTNAME", "ns1.example.external", "CRDATE", startTime.plusMinutes(2).toString()), .atTime(startTime.plusMinutes(3))
startTime.plusMinutes(2)); .hasResponse(
assertCommandAndResponse( "host_create_response.xml",
"host_create.xml", ImmutableMap.of(
ImmutableMap.of("HOSTNAME", "ns2.example.external"), "HOSTNAME", "ns2.example.external", "CRDATE", startTime.plusMinutes(3).toString()));
"host_create_response.xml",
ImmutableMap.of(
"HOSTNAME", "ns2.example.external", "CRDATE", startTime.plusMinutes(3).toString()),
startTime.plusMinutes(3));
} }
@Test @Test
public void testApplicationDuringSunrise_doesntCreateDomainWithoutAllocation() throws Exception { public void testApplicationDuringSunrise_doesntCreateDomainWithoutAllocation() throws Exception {
assertCommandAndResponse("login_valid.xml", "login_response.xml"); assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
createContactsAndHosts(); createContactsAndHosts();
// Note that the trademark is valid from 2013-08-09 to 2017-07-23, hence the creation in 2014. // Note that the trademark is valid from 2013-08-09 to 2017-07-23, hence the creation in 2014.
assertCommandAndResponse( assertThatCommand("domain_create_sunrise_encoded_mark.xml")
"domain_create_sunrise_encoded_mark.xml", .atTime("2014-01-01T00:00:00Z")
"domain_create_sunrise_encoded_signed_mark_response.xml", .hasResponse("domain_create_sunrise_encoded_signed_mark_response.xml");
DateTime.parse("2014-01-01T00:00:00Z")); assertThatCommand("domain_info_testvalidate.xml")
assertCommandAndResponse( .atTime("2014-01-01T00:01:00Z")
"domain_info_testvalidate.xml", .hasResponse(
ImmutableMap.of(), "response_error.xml",
"response_error.xml", ImmutableMap.of(
ImmutableMap.of( "CODE", "2303",
"MSG", "The domain with given ID (test-validate.example) doesn't exist.", "MSG", "The domain with given ID (test-validate.example) doesn't exist."));
"CODE", "2303"), assertThatLogoutSucceeds();
DateTime.parse("2014-01-01T00:01:00Z"));
assertCommandAndResponse("logout.xml", "logout_response.xml");
} }
@Test @Test
public void testDomainAllocation_succeedsOnlyAsSuperuser() throws Exception { public void testDomainAllocation_succeedsOnlyAsSuperuser() throws Exception {
assertCommandAndResponse("login_valid.xml", "login_response.xml"); assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
createContactsAndHosts(); createContactsAndHosts();
assertCommandAndResponse( assertThatCommand("domain_create_sunrise_encoded_mark.xml")
"domain_create_sunrise_encoded_mark.xml", .atTime("2014-01-01T00:00:00Z")
"domain_create_sunrise_encoded_signed_mark_response.xml", .hasResponse("domain_create_sunrise_encoded_signed_mark_response.xml");
DateTime.parse("2014-01-01T00:00:00Z")); assertThatCommand("domain_info_testvalidate.xml")
assertCommandAndResponse( .atTime("2014-01-01T00:01:00Z")
"domain_info_testvalidate.xml", .hasResponse(
ImmutableMap.of(), "response_error.xml",
"response_error.xml", ImmutableMap.of(
ImmutableMap.of( "CODE", "2303",
"MSG", "The domain with given ID (test-validate.example) doesn't exist.", "MSG", "The domain with given ID (test-validate.example) doesn't exist."));
"CODE", "2303"), assertThatCommand("domain_allocate_testvalidate.xml")
DateTime.parse("2014-01-01T00:01:00Z")); .atTime(START_OF_GA.plusDays(1))
assertCommandAndResponse( .hasResponse(
"domain_allocate_testvalidate.xml", "response_error.xml",
ImmutableMap.of(), ImmutableMap.of("CODE", "2201", "MSG", "Only a superuser can allocate domains"));
"response_error.xml",
ImmutableMap.of("MSG", "Only a superuser can allocate domains", "CODE", "2201"),
START_OF_GA.plusDays(1));
setIsSuperuser(true); setIsSuperuser(true);
assertCommandAndResponse( assertThatCommand("domain_allocate_testvalidate.xml")
"domain_allocate_testvalidate.xml", .atTime(START_OF_GA.plusDays(1).plusMinutes(1))
"domain_allocate_response_testvalidate.xml", .hasResponse("domain_allocate_response_testvalidate.xml");
START_OF_GA.plusDays(1).plusMinutes(1));
setIsSuperuser(false); setIsSuperuser(false);
assertCommandAndResponse( assertThatCommand("domain_info_testvalidate.xml")
"domain_info_testvalidate.xml", .atTime(START_OF_GA.plusDays(1).plusMinutes(2))
"domain_info_response_testvalidate_ok.xml", .hasResponse("domain_info_response_testvalidate_ok.xml");
START_OF_GA.plusDays(1).plusMinutes(2));
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -46,13 +46,10 @@ public class EppLifecycleHostTest extends EppTestCase {
@Test @Test
public void testLifecycle() throws Exception { public void testLifecycle() throws Exception {
assertCommandAndResponse("login_valid.xml", "login_response.xml"); assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
assertCommandAndResponse( assertThatCommand("hello.xml")
"hello.xml", .atTime("2000-06-02T00:00:00Z")
ImmutableMap.of(), .hasResponse("greeting.xml", ImmutableMap.of("DATE", "2000-06-02T00:00:00Z"));
"greeting.xml",
ImmutableMap.of("DATE", "2000-06-02T00:00:00Z"),
DateTime.parse("2000-06-02T00:00:00Z"));
// Note that Hello commands don't set a status code on the response. // Note that Hello commands don't set a status code on the response.
assertThat(getRecordedEppMetric()) assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar") .hasClientId("NewRegistrar")
@ -60,12 +57,11 @@ public class EppLifecycleHostTest extends EppTestCase {
.hasCommandName("Hello") .hasCommandName("Hello")
.and() .and()
.hasNoStatus(); .hasNoStatus();
assertCommandAndResponse( assertThatCommand("host_create.xml", ImmutableMap.of("HOSTNAME", "ns1.example.tld"))
"host_create.xml", .atTime("2000-06-02T00:01:00Z")
ImmutableMap.of("HOSTNAME", "ns1.example.tld"), .hasResponse(
"host_create_response.xml", "host_create_response.xml",
ImmutableMap.of("HOSTNAME", "ns1.example.tld", "CRDATE", "2000-06-02T00:01:00Z"), ImmutableMap.of("HOSTNAME", "ns1.example.tld", "CRDATE", "2000-06-02T00:01:00Z"));
DateTime.parse("2000-06-02T00:01:00Z"));
assertThat(getRecordedEppMetric()) assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar") .hasClientId("NewRegistrar")
.and() .and()
@ -74,13 +70,12 @@ public class EppLifecycleHostTest extends EppTestCase {
.hasEppTarget("ns1.example.tld") .hasEppTarget("ns1.example.tld")
.and() .and()
.hasStatus(SUCCESS); .hasStatus(SUCCESS);
assertCommandAndResponse( assertThatCommand("host_info.xml", ImmutableMap.of("HOSTNAME", "ns1.example.tld"))
"host_info.xml", .atTime("2000-06-02T00:02:00Z")
ImmutableMap.of("HOSTNAME", "ns1.example.tld"), .hasResponse(
"host_info_response.xml", "host_info_response.xml",
ImmutableMap.of( ImmutableMap.of(
"HOSTNAME", "ns1.example.tld", "ROID", "1-ROID", "CRDATE", "2000-06-02T00:01:00Z"), "HOSTNAME", "ns1.example.tld", "ROID", "1-ROID", "CRDATE", "2000-06-02T00:01:00Z"));
DateTime.parse("2000-06-02T00:02:00Z"));
assertThat(getRecordedEppMetric()) assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar") .hasClientId("NewRegistrar")
.and() .and()
@ -89,12 +84,9 @@ public class EppLifecycleHostTest extends EppTestCase {
.hasEppTarget("ns1.example.tld") .hasEppTarget("ns1.example.tld")
.and() .and()
.hasStatus(SUCCESS); .hasStatus(SUCCESS);
assertCommandAndResponse( assertThatCommand("host_delete.xml", ImmutableMap.of("HOSTNAME", "ns1.example.tld"))
"host_delete.xml", .atTime("2000-06-02T00:03:00Z")
ImmutableMap.of("HOSTNAME", "ns1.example.tld"), .hasResponse("generic_success_action_pending_response.xml");
"generic_success_action_pending_response.xml",
ImmutableMap.of(),
DateTime.parse("2000-06-02T00:03:00Z"));
assertThat(getRecordedEppMetric()) assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar") .hasClientId("NewRegistrar")
.and() .and()
@ -103,140 +95,128 @@ public class EppLifecycleHostTest extends EppTestCase {
.hasEppTarget("ns1.example.tld") .hasEppTarget("ns1.example.tld")
.and() .and()
.hasStatus(SUCCESS_WITH_ACTION_PENDING); .hasStatus(SUCCESS_WITH_ACTION_PENDING);
assertCommandAndResponse("logout.xml", "logout_response.xml"); assertThatLogoutSucceeds();
} }
@Test @Test
public void testRenamingHostToExistingHost_fails() throws Exception { public void testRenamingHostToExistingHost_fails() throws Exception {
createTld("example"); createTld("example");
assertCommandAndResponse("login_valid.xml", "login_response.xml"); assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
// Create the fakesite domain. // Create the fakesite domain.
assertCommandAndResponse( assertThatCommand("contact_create_sh8013.xml")
"contact_create_sh8013.xml", .atTime("2000-06-01T00:00:00Z")
ImmutableMap.of(), .hasResponse(
"contact_create_response_sh8013.xml", "contact_create_response_sh8013.xml",
ImmutableMap.of("CRDATE", "2000-06-01T00:00:00Z"), ImmutableMap.of("CRDATE", "2000-06-01T00:00:00Z"));
DateTime.parse("2000-06-01T00:00:00Z")); assertThatCommand("contact_create_jd1234.xml")
assertCommandAndResponse( .atTime("2000-06-01T00:01:00Z")
"contact_create_jd1234.xml", .hasResponse("contact_create_response_jd1234.xml");
"contact_create_response_jd1234.xml", assertThatCommand("domain_create_fakesite_no_nameservers.xml")
DateTime.parse("2000-06-01T00:01:00Z")); .atTime("2000-06-01T00:04:00Z")
assertCommandAndResponse( .hasResponse(
"domain_create_fakesite_no_nameservers.xml", "domain_create_response.xml",
ImmutableMap.of(), ImmutableMap.of(
"domain_create_response.xml", "NAME", "fakesite.example",
ImmutableMap.of( "CRDATE", "2000-06-01T00:04:00.0Z",
"NAME", "fakesite.example", "EXDATE", "2002-06-01T00:04:00.0Z"));
"CRDATE", "2000-06-01T00:04:00.0Z", assertThatCommand("domain_info_fakesite.xml")
"EXDATE", "2002-06-01T00:04:00.0Z"), .atTime("2000-06-05T00:02:00Z")
DateTime.parse("2000-06-01T00:04:00Z")); .hasResponse("domain_info_response_fakesite_inactive.xml");
assertCommandAndResponse(
"domain_info_fakesite.xml",
"domain_info_response_fakesite_inactive.xml",
DateTime.parse("2000-06-05T00:02:00Z"));
// Add the fakesite subordinate host (requires that domain is already created). // Add the fakesite subordinate host (requires that domain is already created).
assertCommandAndResponse( assertThatCommand("host_create_fakesite.xml")
"host_create_fakesite.xml", .atTime("2000-06-06T00:01:00Z")
"host_create_response_fakesite.xml", .hasResponse("host_create_response_fakesite.xml");
DateTime.parse("2000-06-06T00:01:00Z"));
// Add the 2nd fakesite subordinate host. // Add the 2nd fakesite subordinate host.
assertCommandAndResponse( assertThatCommand("host_create_fakesite2.xml")
"host_create_fakesite2.xml", .atTime("2000-06-09T00:01:00Z")
"host_create_response_fakesite2.xml", .hasResponse("host_create_response_fakesite2.xml");
DateTime.parse("2000-06-09T00:01:00Z"));
// Attempt overwriting of 2nd fakesite subordinate host with the 1st. // Attempt overwriting of 2nd fakesite subordinate host with the 1st.
assertCommandAndResponse( assertThatCommand("host_update_fakesite1_to_fakesite2.xml")
"host_update_fakesite1_to_fakesite2.xml", .atTime("2000-06-10T00:01:00Z")
ImmutableMap.of(), .hasResponse(
"response_error.xml", "response_error.xml",
ImmutableMap.of( ImmutableMap.of(
"MSG", "Object with given ID (ns4.fakesite.example) already exists", "CODE", "2302"), "CODE", "2302",
DateTime.parse("2000-06-10T00:01:00Z")); "MSG", "Object with given ID (ns4.fakesite.example) already exists"));
// Verify that fakesite hosts still exist in their unmodified states. // Verify that fakesite hosts still exist in their unmodified states.
assertCommandAndResponse( assertThatCommand("host_info_fakesite.xml")
"host_info_fakesite.xml", .atTime("2000-06-11T00:07:00Z")
"host_info_response_fakesite_ok.xml", .hasResponse("host_info_response_fakesite_ok.xml");
DateTime.parse("2000-06-11T00:07:00Z")); assertThatCommand("host_info_fakesite2.xml")
assertCommandAndResponse( .atTime("2000-06-11T00:08:00Z")
"host_info_fakesite2.xml", .hasResponse("host_info_response_fakesite2.xml");
"host_info_response_fakesite2.xml", assertThatLogoutSucceeds();
DateTime.parse("2000-06-11T00:08:00Z"));
assertCommandAndResponse("logout.xml", "logout_response.xml");
} }
@Test @Test
public void testSuccess_multipartTldsWithSharedSuffixes() throws Exception { public void testSuccess_multipartTldsWithSharedSuffixes() throws Exception {
createTlds("bar.foo.tld", "foo.tld", "tld"); createTlds("bar.foo.tld", "foo.tld", "tld");
assertCommandAndResponse("login_valid.xml", "login_response.xml"); assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
assertCommandAndResponse( assertThatCommand("contact_create_sh8013.xml")
"contact_create_sh8013.xml", .atTime("2000-06-01T00:00:00Z")
ImmutableMap.of(), .hasResponse(
"contact_create_response_sh8013.xml", "contact_create_response_sh8013.xml",
ImmutableMap.of("CRDATE", "2000-06-01T00:00:00Z"), ImmutableMap.of("CRDATE", "2000-06-01T00:00:00Z"));
DateTime.parse("2000-06-01T00:00:00Z")); assertThatCommand("contact_create_jd1234.xml")
assertCommandAndResponse( .atTime("2000-06-01T00:01:00Z")
"contact_create_jd1234.xml", .hasResponse("contact_create_response_jd1234.xml");
"contact_create_response_jd1234.xml",
DateTime.parse("2000-06-01T00:01:00Z"));
// Create domain example.bar.foo.tld // Create domain example.bar.foo.tld
assertCommandAndResponse( assertThatCommand(
"domain_create_wildcard.xml", "domain_create_wildcard.xml", ImmutableMap.of("HOSTNAME", "example.bar.foo.tld"))
ImmutableMap.of("HOSTNAME", "example.bar.foo.tld"), .atTime("2000-06-01T00:02:00.000Z")
"domain_create_response.xml", .hasResponse(
ImmutableMap.of( "domain_create_response.xml",
"NAME", "example.bar.foo.tld", ImmutableMap.of(
"CRDATE", "2000-06-01T00:02:00Z", "NAME", "example.bar.foo.tld",
"EXDATE", "2002-06-01T00:02:00Z"), "CRDATE", "2000-06-01T00:02:00Z",
DateTime.parse("2000-06-01T00:02:00.000Z")); "EXDATE", "2002-06-01T00:02:00Z"));
// Create domain example.foo.tld // Create domain example.foo.tld
assertCommandAndResponse( assertThatCommand("domain_create_wildcard.xml", ImmutableMap.of("HOSTNAME", "example.foo.tld"))
"domain_create_wildcard.xml", .atTime("2000-06-01T00:02:00.001Z")
ImmutableMap.of("HOSTNAME", "example.foo.tld"), .hasResponse(
"domain_create_response.xml", "domain_create_response.xml",
ImmutableMap.of( ImmutableMap.of(
"NAME", "example.foo.tld", "NAME", "example.foo.tld",
"CRDATE", "2000-06-01T00:02:00Z", "CRDATE", "2000-06-01T00:02:00Z",
"EXDATE", "2002-06-01T00:02:00Z"), "EXDATE", "2002-06-01T00:02:00Z"));
DateTime.parse("2000-06-01T00:02:00.001Z"));
// Create domain example.tld // Create domain example.tld
assertCommandAndResponse( assertThatCommand("domain_create_wildcard.xml", ImmutableMap.of("HOSTNAME", "example.tld"))
"domain_create_wildcard.xml", .atTime("2000-06-01T00:02:00.002Z")
ImmutableMap.of("HOSTNAME", "example.tld"), .hasResponse(
"domain_create_response.xml", "domain_create_response.xml",
ImmutableMap.of( ImmutableMap.of(
"NAME", "example.tld", "NAME", "example.tld",
"CRDATE", "2000-06-01T00:02:00Z", "CRDATE", "2000-06-01T00:02:00Z",
"EXDATE", "2002-06-01T00:02:00Z"), "EXDATE", "2002-06-01T00:02:00Z"));
DateTime.parse("2000-06-01T00:02:00.002Z"));
// Create host ns1.example.bar.foo.tld // Create host ns1.example.bar.foo.tld
assertCommandAndResponse( assertThatCommand(
"host_create_with_ips.xml", "host_create_with_ips.xml", ImmutableMap.of("HOSTNAME", "ns1.example.bar.foo.tld"))
ImmutableMap.of("HOSTNAME", "ns1.example.bar.foo.tld"), .atTime("2000-06-01T00:03:00Z")
"host_create_response.xml", .hasResponse(
ImmutableMap.of("HOSTNAME", "ns1.example.bar.foo.tld", "CRDATE", "2000-06-01T00:03:00Z"), "host_create_response.xml",
DateTime.parse("2000-06-01T00:03:00Z")); ImmutableMap.of(
"HOSTNAME", "ns1.example.bar.foo.tld", "CRDATE", "2000-06-01T00:03:00Z"));
// Create host ns1.example.foo.tld // Create host ns1.example.foo.tld
assertCommandAndResponse( assertThatCommand(
"host_create_with_ips.xml", "host_create_with_ips.xml", ImmutableMap.of("HOSTNAME", "ns1.example.foo.tld"))
ImmutableMap.of("HOSTNAME", "ns1.example.foo.tld"), .atTime("2000-06-01T00:04:00Z")
"host_create_response.xml", .hasResponse(
ImmutableMap.of("HOSTNAME", "ns1.example.foo.tld", "CRDATE", "2000-06-01T00:04:00Z"), "host_create_response.xml",
DateTime.parse("2000-06-01T00:04:00Z")); ImmutableMap.of("HOSTNAME", "ns1.example.foo.tld", "CRDATE", "2000-06-01T00:04:00Z"));
// Create host ns1.example.tld // Create host ns1.example.tld
assertCommandAndResponse( assertThatCommand("host_create_with_ips.xml", ImmutableMap.of("HOSTNAME", "ns1.example.tld"))
"host_create_with_ips.xml", .atTime("2000-06-01T00:05:00Z")
ImmutableMap.of("HOSTNAME", "ns1.example.tld"), .hasResponse(
"host_create_response.xml", "host_create_response.xml",
ImmutableMap.of("HOSTNAME", "ns1.example.tld", "CRDATE", "2000-06-01T00:05:00Z"), ImmutableMap.of("HOSTNAME", "ns1.example.tld", "CRDATE", "2000-06-01T00:05:00Z"));
DateTime.parse("2000-06-01T00:05:00Z"));
DateTime timeAfterCreates = DateTime.parse("2000-06-01T00:06:00Z"); DateTime timeAfterCreates = DateTime.parse("2000-06-01T00:06:00Z");
@ -266,6 +246,6 @@ public class EppLifecycleHostTest extends EppTestCase {
assertAboutHosts().that(exampleTldHost).hasSuperordinateDomain(Key.create(exampleTldDomain)); assertAboutHosts().that(exampleTldHost).hasSuperordinateDomain(Key.create(exampleTldDomain));
assertThat(exampleTldDomain.getSubordinateHosts()).containsExactly("ns1.example.tld"); assertThat(exampleTldDomain.getSubordinateHosts()).containsExactly("ns1.example.tld");
assertCommandAndResponse("logout.xml", "logout_response.xml"); assertThatLogoutSucceeds();
} }
} }

View file

@ -34,14 +34,14 @@ public class EppLifecycleLoginTest extends EppTestCase {
@Test @Test
public void testLoginAndLogout_recordsEppMetric() throws Exception { public void testLoginAndLogout_recordsEppMetric() throws Exception {
assertCommandAndResponse("login_valid.xml", "login_response.xml"); assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
assertThat(getRecordedEppMetric()) assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar") .hasClientId("NewRegistrar")
.and() .and()
.hasCommandName("Login") .hasCommandName("Login")
.and() .and()
.hasStatus(SUCCESS); .hasStatus(SUCCESS);
assertCommandAndResponse("logout.xml", "logout_response.xml"); assertThatLogoutSucceeds();
assertThat(getRecordedEppMetric()) assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar") .hasClientId("NewRegistrar")
.and() .and()

View file

@ -37,25 +37,19 @@ public class EppLoggedOutTest extends EppTestCase {
@Test @Test
public void testHello() throws Exception { public void testHello() throws Exception {
DateTime now = DateTime.now(UTC); DateTime now = DateTime.now(UTC);
assertCommandAndResponse( assertThatCommand("hello.xml", null)
"hello.xml", .atTime(now)
null, .hasResponse("greeting.xml", ImmutableMap.of("DATE", now.toString(dateTimeNoMillis())));
"greeting.xml",
ImmutableMap.of("DATE", now.toString(dateTimeNoMillis())),
now);
} }
@Test @Test
public void testSyntaxError() throws Exception { public void testSyntaxError() throws Exception {
assertCommandAndResponse( assertThatCommand("syntax_error.xml")
"syntax_error.xml", .hasResponse(
ImmutableMap.of(), "response_error_no_cltrid.xml",
"response_error_no_cltrid.xml", ImmutableMap.of(
ImmutableMap.of( "CODE", "2001",
"MSG", "MSG", "Syntax error at line 4, column 65: cvc-complex-type.3.2.2: "
"Syntax error at line 4, column 65: cvc-complex-type.3.2.2: " + "Attribute 'xsi:schemaLocation' is not allowed to appear in element 'epp'."));
+ "Attribute 'xsi:schemaLocation' is not allowed to appear in element 'epp'.",
"CODE",
"2001"));
} }
} }

View file

@ -42,23 +42,23 @@ public class EppLoginAdminUserTest extends EppTestCase {
@Test @Test
public void testNonAuthedLogin_succeedsAsAdmin() throws Exception { public void testNonAuthedLogin_succeedsAsAdmin() throws Exception {
// Login succeeds even though this user isn't listed on the registrar. // Login succeeds even though this user isn't listed on the registrar.
assertCommandAndResponse("login2_valid.xml", "login_response.xml"); assertThatLoginSucceeds("TheRegistrar", "password2");
} }
@Test @Test
public void testLoginLogout_wrongPasswordStillWorks() throws Exception { public void testLoginLogout_wrongPasswordStillWorks() throws Exception {
// For user-based logins the password in the epp xml is ignored. // For user-based logins the password in the epp xml is ignored.
assertCommandAndResponse("login_invalid_wrong_password.xml", "login_response.xml"); assertThatLoginSucceeds("NewRegistrar", "incorrect");
assertCommandAndResponse("logout.xml", "logout_response.xml"); assertThatLogoutSucceeds();
} }
@Test @Test
public void testNonAuthedMultiLogin_succeedsAsAdmin() throws Exception { public void testNonAuthedMultiLogin_succeedsAsAdmin() throws Exception {
// The admin can log in as different registrars. // The admin can log in as different registrars.
assertCommandAndResponse("login_valid.xml", "login_response.xml"); assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
assertCommandAndResponse("logout.xml", "logout_response.xml"); assertThatLogoutSucceeds();
assertCommandAndResponse("login_valid.xml", "login_response.xml"); assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
assertCommandAndResponse("logout.xml", "logout_response.xml"); assertThatLogoutSucceeds();
assertCommandAndResponse("login2_valid.xml", "login_response.xml"); assertThatLoginSucceeds("TheRegistrar", "password2");
} }
} }

View file

@ -62,67 +62,62 @@ public class EppLoginTlsTest extends EppTestCase {
@Test @Test
public void testLoginLogout() throws Exception { public void testLoginLogout() throws Exception {
setClientCertificateHash(CertificateSamples.SAMPLE_CERT_HASH); setClientCertificateHash(CertificateSamples.SAMPLE_CERT_HASH);
assertCommandAndResponse("login_valid.xml", "login_response.xml"); assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
assertCommandAndResponse("logout.xml", "logout_response.xml"); assertThatLogoutSucceeds();
} }
@Test @Test
public void testLogin_wrongPasswordFails() throws Exception { public void testLogin_wrongPasswordFails() throws Exception {
setClientCertificateHash(CertificateSamples.SAMPLE_CERT_HASH); setClientCertificateHash(CertificateSamples.SAMPLE_CERT_HASH);
// For TLS login, we also check the epp xml password. // For TLS login, we also check the epp xml password.
assertCommandAndResponse( assertThatLogin("NewRegistrar", "incorrect")
"login_invalid_wrong_password.xml", .hasResponse(
ImmutableMap.of(), "response_error.xml",
"response_error.xml", ImmutableMap.of("CODE", "2200", "MSG", "Registrar password is incorrect"));
ImmutableMap.of("MSG", "Registrar password is incorrect", "CODE", "2200"));
} }
@Test @Test
public void testMultiLogin() throws Exception { public void testMultiLogin() throws Exception {
setClientCertificateHash(CertificateSamples.SAMPLE_CERT_HASH); setClientCertificateHash(CertificateSamples.SAMPLE_CERT_HASH);
assertCommandAndResponse("login_valid.xml", "login_response.xml"); assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
assertCommandAndResponse("logout.xml", "logout_response.xml"); assertThatLogoutSucceeds();
assertCommandAndResponse("login_valid.xml", "login_response.xml"); assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
assertCommandAndResponse("logout.xml", "logout_response.xml"); assertThatLogoutSucceeds();
assertCommandAndResponse( assertThatLogin("TheRegistrar", "password2")
"login2_valid.xml", .hasResponse(
ImmutableMap.of(), "response_error.xml",
"response_error.xml", ImmutableMap.of(
ImmutableMap.of( "CODE", "2200", "MSG", "Registrar certificate does not match stored certificate"));
"MSG", "Registrar certificate does not match stored certificate", "CODE", "2200"));
} }
@Test @Test
public void testNonAuthedLogin_fails() throws Exception { public void testNonAuthedLogin_fails() throws Exception {
setClientCertificateHash(CertificateSamples.SAMPLE_CERT_HASH); setClientCertificateHash(CertificateSamples.SAMPLE_CERT_HASH);
assertCommandAndResponse( assertThatLogin("TheRegistrar", "password2")
"login2_valid.xml", .hasResponse(
ImmutableMap.of(), "response_error.xml",
"response_error.xml", ImmutableMap.of(
ImmutableMap.of( "CODE", "2200", "MSG", "Registrar certificate does not match stored certificate"));
"MSG", "Registrar certificate does not match stored certificate", "CODE", "2200"));
} }
@Test @Test
public void testBadCertificate_failsBadCertificate2200() throws Exception { public void testBadCertificate_failsBadCertificate2200() throws Exception {
setClientCertificateHash("laffo"); setClientCertificateHash("laffo");
assertCommandAndResponse( assertThatLogin("NewRegistrar", "foo-BAR2")
"login_valid.xml", .hasResponse(
ImmutableMap.of(), "response_error.xml",
"response_error.xml", ImmutableMap.of(
ImmutableMap.of( "CODE", "2200", "MSG", "Registrar certificate does not match stored certificate"));
"MSG", "Registrar certificate does not match stored certificate", "CODE", "2200"));
} }
@Test @Test
public void testGfeDidntProvideClientCertificate_failsMissingCertificate2200() throws Exception { public void testGfeDidntProvideClientCertificate_failsMissingCertificate2200() throws Exception {
setClientCertificateHash(""); setClientCertificateHash("");
assertCommandAndResponse( assertThatLogin("NewRegistrar", "foo-BAR2")
"login_valid.xml", .hasResponse(
ImmutableMap.of(), "response_error.xml",
"response_error.xml", ImmutableMap.of("CODE", "2200", "MSG", "Registrar certificate not present"));
ImmutableMap.of("MSG", "Registrar certificate not present", "CODE", "2200"));
} }
@Test @Test
@ -135,7 +130,7 @@ public class EppLoginTlsTest extends EppTestCase {
.setClientCertificate(CertificateSamples.SAMPLE_CERT, now) .setClientCertificate(CertificateSamples.SAMPLE_CERT, now)
.setFailoverClientCertificate(CertificateSamples.SAMPLE_CERT2, now) .setFailoverClientCertificate(CertificateSamples.SAMPLE_CERT2, now)
.build()); .build());
assertCommandAndResponse("login_valid.xml", "login_response.xml"); assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
} }
@Test @Test
@ -148,7 +143,7 @@ public class EppLoginTlsTest extends EppTestCase {
.setClientCertificate(CertificateSamples.SAMPLE_CERT, now) .setClientCertificate(CertificateSamples.SAMPLE_CERT, now)
.setFailoverClientCertificate(CertificateSamples.SAMPLE_CERT2, now) .setFailoverClientCertificate(CertificateSamples.SAMPLE_CERT2, now)
.build()); .build());
assertCommandAndResponse("login_valid.xml", "login_response.xml"); assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
} }
@Test @Test
@ -161,7 +156,7 @@ public class EppLoginTlsTest extends EppTestCase {
.setClientCertificate(null, now) .setClientCertificate(null, now)
.setFailoverClientCertificate(CertificateSamples.SAMPLE_CERT2, now) .setFailoverClientCertificate(CertificateSamples.SAMPLE_CERT2, now)
.build()); .build());
assertCommandAndResponse("login_valid.xml", "login_response.xml"); assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
} }
@Test @Test
@ -174,6 +169,6 @@ public class EppLoginTlsTest extends EppTestCase {
.setClientCertificate(null, now) .setClientCertificate(null, now)
.setFailoverClientCertificate(null, now) .setFailoverClientCertificate(null, now)
.build()); .build());
assertCommandAndResponse("login_valid.xml", "login_response.xml"); assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
} }
} }

View file

@ -37,7 +37,7 @@ public class EppLoginUserTest extends EppTestCase {
@Rule @Rule
public final AppEngineRule appEngine = AppEngineRule.builder() public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore() .withDatastore()
.withUserService(UserInfo.create("person@example.com", "12345")) .withUserService(UserInfo.create("user@example.com", "12345"))
.build(); .build();
@Before @Before
@ -55,40 +55,38 @@ public class EppLoginUserTest extends EppTestCase {
@Test @Test
public void testLoginLogout() throws Exception { public void testLoginLogout() throws Exception {
assertCommandAndResponse("login_valid.xml", "login_response.xml"); assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
assertCommandAndResponse("logout.xml", "logout_response.xml"); assertThatLogoutSucceeds();
} }
@Test @Test
public void testNonAuthedLogin_fails() throws Exception { public void testNonAuthedLogin_fails() throws Exception {
assertCommandAndResponse( assertThatLogin("TheRegistrar", "password2")
"login2_valid.xml", .hasResponse(
ImmutableMap.of(), "response_error.xml",
"response_error.xml", ImmutableMap.of(
ImmutableMap.of( "CODE", "2200",
"MSG", "User id is not allowed to login as requested registrar: person@example.com", "MSG", "User id is not allowed to login as requested registrar: user@example.com"));
"CODE", "2200"));
} }
@Test @Test
public void testMultiLogin() throws Exception { public void testMultiLogin() throws Exception {
assertCommandAndResponse("login_valid.xml", "login_response.xml"); assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
assertCommandAndResponse("logout.xml", "logout_response.xml"); assertThatLogoutSucceeds();
assertCommandAndResponse("login_valid.xml", "login_response.xml"); assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
assertCommandAndResponse("logout.xml", "logout_response.xml"); assertThatLogoutSucceeds();
assertCommandAndResponse( assertThatLogin("TheRegistrar", "password2")
"login2_valid.xml", .hasResponse(
ImmutableMap.of(), "response_error.xml",
"response_error.xml", ImmutableMap.of(
ImmutableMap.of( "CODE", "2200",
"MSG", "User id is not allowed to login as requested registrar: person@example.com", "MSG", "User id is not allowed to login as requested registrar: user@example.com"));
"CODE", "2200"));
} }
@Test @Test
public void testLoginLogout_wrongPasswordStillWorks() throws Exception { public void testLoginLogout_wrongPasswordStillWorks() throws Exception {
// For user-based logins the password in the epp xml is ignored. // For user-based logins the password in the epp xml is ignored.
assertCommandAndResponse("login_invalid_wrong_password.xml", "login_response.xml"); assertThatLoginSucceeds("NewRegistrar", "incorrect");
assertCommandAndResponse("logout.xml", "logout_response.xml"); assertThatLogoutSucceeds();
} }
} }

View file

@ -22,6 +22,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
import static javax.servlet.http.HttpServletResponse.SC_OK; import static javax.servlet.http.HttpServletResponse.SC_OK;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
import com.google.common.collect.ImmutableMap;
import com.google.common.net.MediaType; import com.google.common.net.MediaType;
import google.registry.flows.EppTestComponent.FakesAndMocksModule; import google.registry.flows.EppTestComponent.FakesAndMocksModule;
import google.registry.model.ofy.Ofy; import google.registry.model.ofy.Ofy;
@ -32,6 +33,7 @@ import google.registry.testing.FakeResponse;
import google.registry.testing.InjectRule; import google.registry.testing.InjectRule;
import google.registry.testing.ShardableTestCase; import google.registry.testing.ShardableTestCase;
import java.util.Map; import java.util.Map;
import javax.annotation.Nullable;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
@ -72,30 +74,64 @@ public class EppTestCase extends ShardableTestCase {
this.isSuperuser = isSuperuser; this.isSuperuser = isSuperuser;
} }
String assertCommandAndResponse(String inputFilename, String outputFilename) throws Exception { class CommandAsserter {
return assertCommandAndResponse(inputFilename, null, outputFilename, null); private final String inputFilename;
private @Nullable final Map<String, String> inputSubstitutions;
private DateTime now;
private CommandAsserter(
String inputFilename, @Nullable Map<String, String> inputSubstitutions) {
this.inputFilename = inputFilename;
this.inputSubstitutions = inputSubstitutions;
this.now = DateTime.now(UTC);
}
CommandAsserter atTime(DateTime now) {
this.now = now;
return this;
}
CommandAsserter atTime(String now) {
return atTime(DateTime.parse(now));
}
String hasResponse(String outputFilename) throws Exception {
return hasResponse(outputFilename, null);
}
String hasResponse(String outputFilename, @Nullable Map<String, String> outputSubstitutions)
throws Exception {
return assertCommandAndResponse(
inputFilename, inputSubstitutions, outputFilename, outputSubstitutions, now);
}
} }
String assertCommandAndResponse(String inputFilename, String outputFilename, DateTime now) CommandAsserter assertThatCommand(String inputFilename) {
throws Exception { return assertThatCommand(inputFilename, null);
return assertCommandAndResponse(inputFilename, null, outputFilename, null, now);
} }
String assertCommandAndResponse( CommandAsserter assertThatCommand(
String inputFilename, @Nullable Map<String, String> inputSubstitutions) {
return new CommandAsserter(inputFilename, inputSubstitutions);
}
CommandAsserter assertThatLogin(String clientId, String password) throws Exception {
return assertThatCommand("login.xml", ImmutableMap.of("CLID", clientId, "PW", password));
}
void assertThatLoginSucceeds(String clientId, String password) throws Exception {
assertThatLogin(clientId, password).hasResponse("login_response.xml");
}
void assertThatLogoutSucceeds() throws Exception {
assertThatCommand("logout.xml").hasResponse("logout_response.xml");
}
private String assertCommandAndResponse(
String inputFilename, String inputFilename,
Map<String, String> inputSubstitutions, @Nullable Map<String, String> inputSubstitutions,
String outputFilename, String outputFilename,
Map<String, String> outputSubstitutions) @Nullable Map<String, String> outputSubstitutions,
throws Exception {
return assertCommandAndResponse(
inputFilename, inputSubstitutions, outputFilename, outputSubstitutions, DateTime.now(UTC));
}
String assertCommandAndResponse(
String inputFilename,
Map<String, String> inputSubstitutions,
String outputFilename,
Map<String, String> outputSubstitutions,
DateTime now) DateTime now)
throws Exception { throws Exception {
clock.setTo(now); clock.setTo(now);

View file

@ -35,49 +35,40 @@ public class EppXxeAttackTest extends EppTestCase {
@Test @Test
public void testRemoteXmlExternalEntity() throws Exception { public void testRemoteXmlExternalEntity() throws Exception {
assertCommandAndResponse("login_valid.xml", "login_response.xml"); assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
assertCommandAndResponse( assertThatCommand("contact_create_remote_xxe.xml")
"contact_create_remote_xxe.xml", .hasResponse(
ImmutableMap.of(), "response_error_no_cltrid.xml",
"response_error_no_cltrid.xml", ImmutableMap.of(
ImmutableMap.of( "CODE", "2001",
"MSG", "MSG", "Syntax error at line 11, column 34: "
"Syntax error at line 11, column 34: " + "The entity &quot;remote&quot; was referenced, but not declared."));
+ "The entity &quot;remote&quot; was referenced, but not declared.", assertThatLogoutSucceeds();
"CODE",
"2001"));
assertCommandAndResponse("logout.xml", "logout_response.xml");
} }
@Test @Test
public void testLocalXmlExtrernalEntity() throws Exception { public void testLocalXmlExtrernalEntity() throws Exception {
assertCommandAndResponse("login_valid.xml", "login_response.xml"); assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
assertCommandAndResponse( assertThatCommand("contact_create_local_xxe.xml")
"contact_create_local_xxe.xml", .hasResponse(
ImmutableMap.of(), "response_error_no_cltrid.xml",
"response_error_no_cltrid.xml", ImmutableMap.of(
ImmutableMap.of( "CODE", "2001",
"MSG", "MSG", "Syntax error at line 11, column 31: "
"Syntax error at line 11, column 31: " + "The entity &quot;ent&quot; was referenced, but not declared."));
+ "The entity &quot;ent&quot; was referenced, but not declared.", assertThatLogoutSucceeds();
"CODE",
"2001"));
assertCommandAndResponse("logout.xml", "logout_response.xml");
} }
@Test @Test
public void testBillionLaughsAttack() throws Exception { public void testBillionLaughsAttack() throws Exception {
assertCommandAndResponse("login_valid.xml", "login_response.xml"); assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
assertCommandAndResponse( assertThatCommand("contact_create_billion_laughs.xml")
"contact_create_billion_laughs.xml", .hasResponse(
ImmutableMap.of(), "response_error_no_cltrid.xml",
"response_error_no_cltrid.xml", ImmutableMap.of(
ImmutableMap.of( "CODE", "2001",
"MSG", "MSG", "Syntax error at line 20, column 32: "
"Syntax error at line 20, column 32: " + "The entity &quot;lol9&quot; was referenced, but not declared."));
+ "The entity &quot;lol9&quot; was referenced, but not declared.", assertThatLogoutSucceeds();
"CODE",
"2001"));
assertCommandAndResponse("logout.xml", "logout_response.xml");
} }
} }

View file

@ -1,8 +1,8 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0"> <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command> <command>
<login> <login>
<clID>NewRegistrar</clID> <clID>%CLID%</clID>
<pw>foo-BAR2</pw> <pw>%PW%</pw>
<options> <options>
<version>1.0</version> <version>1.0</version>
<lang>en</lang> <lang>en</lang>

View file

@ -1,22 +0,0 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<login>
<clID>TheRegistrar</clID>
<pw>password2</pw>
<options>
<version>1.0</version>
<lang>en</lang>
</options>
<svcs>
<objURI>urn:ietf:params:xml:ns:host-1.0</objURI>
<objURI>urn:ietf:params:xml:ns:domain-1.0</objURI>
<objURI>urn:ietf:params:xml:ns:contact-1.0</objURI>
<svcExtension>
<extURI>urn:ietf:params:xml:ns:launch-1.0</extURI>
<extURI>urn:ietf:params:xml:ns:rgp-1.0</extURI>
</svcExtension>
</svcs>
</login>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -1,22 +0,0 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<login>
<clID>NewRegistrar</clID>
<pw>incorrect</pw>
<options>
<version>1.0</version>
<lang>en</lang>
</options>
<svcs>
<objURI>urn:ietf:params:xml:ns:host-1.0</objURI>
<objURI>urn:ietf:params:xml:ns:domain-1.0</objURI>
<objURI>urn:ietf:params:xml:ns:contact-1.0</objURI>
<svcExtension>
<extURI>urn:ietf:params:xml:ns:launch-1.0</extURI>
<extURI>urn:ietf:params:xml:ns:rgp-1.0</extURI>
</svcExtension>
</svcs>
</login>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -23,6 +23,7 @@ import com.google.common.io.ByteSource;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Nullable;
/** Contains helper methods for dealing with test data. */ /** Contains helper methods for dealing with test data. */
public final class TestDataHelper { public final class TestDataHelper {
@ -56,7 +57,7 @@ public final class TestDataHelper {
* context class, and substitutes in values for placeholders of the form <code>%tagname%</code>. * context class, and substitutes in values for placeholders of the form <code>%tagname%</code>.
*/ */
public static String loadFile( public static String loadFile(
Class<?> context, String filename, Map<String, String> substitutions) { Class<?> context, String filename, @Nullable Map<String, String> substitutions) {
String fileContents = loadFile(context, filename); String fileContents = loadFile(context, filename);
for (Entry<String, String> entry : nullToEmpty(substitutions).entrySet()) { for (Entry<String, String> entry : nullToEmpty(substitutions).entrySet()) {
fileContents = fileContents.replaceAll("%" + entry.getKey() + "%", entry.getValue()); fileContents = fileContents.replaceAll("%" + entry.getKey() + "%", entry.getValue());