Add more EPP metric lifecycle tests

This also refactors some of the existing EPP XML testdata files
to use a consistent wildcard naming scheme.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=154569632
This commit is contained in:
mcilwain 2017-04-28 12:33:17 -07:00 committed by Ben McIlwain
parent 44546a3480
commit 876552f1ce
15 changed files with 200 additions and 56 deletions

View file

@ -14,6 +14,12 @@
package google.registry.flows; package google.registry.flows;
import static google.registry.model.eppoutput.Result.Code.SUCCESS;
import static google.registry.model.eppoutput.Result.Code.SUCCESS_WITH_ACK_MESSAGE;
import static google.registry.model.eppoutput.Result.Code.SUCCESS_WITH_ACTION_PENDING;
import static google.registry.model.eppoutput.Result.Code.SUCCESS_WITH_NO_MESSAGES;
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.joda.time.DateTime;
@ -41,11 +47,35 @@ public class EppLifecycleContactTest extends EppTestCase {
"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")); DateTime.parse("2000-06-01T00:00:00Z"));
assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar")
.and()
.hasCommandName("ContactCreate")
.and()
.hasEppTarget("sh8013")
.and()
.hasStatus(SUCCESS);
assertCommandAndResponse( assertCommandAndResponse(
"contact_info.xml", "contact_info.xml",
"contact_info_from_create_response.xml", "contact_info_from_create_response.xml",
DateTime.parse("2000-06-01T00:01:00Z")); DateTime.parse("2000-06-01T00:01:00Z"));
assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar")
.and()
.hasCommandName("ContactInfo")
.and()
.hasEppTarget("sh8013")
.and()
.hasStatus(SUCCESS);
assertCommandAndResponse("contact_delete_sh8013.xml", "contact_delete_response_sh8013.xml"); assertCommandAndResponse("contact_delete_sh8013.xml", "contact_delete_response_sh8013.xml");
assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar")
.and()
.hasCommandName("ContactDelete")
.and()
.hasEppTarget("sh8013")
.and()
.hasStatus(SUCCESS_WITH_ACTION_PENDING);
assertCommandAndResponse("logout.xml", "logout_response.xml"); assertCommandAndResponse("logout.xml", "logout_response.xml");
} }
@ -74,12 +104,24 @@ public class EppLifecycleContactTest extends EppTestCase {
"poll.xml", "poll.xml",
"poll_response_contact_transfer.xml", "poll_response_contact_transfer.xml",
DateTime.parse("2000-06-08T22:01:00Z")); DateTime.parse("2000-06-08T22:01:00Z"));
assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar")
.and()
.hasCommandName("PollRequest")
.and()
.hasStatus(SUCCESS_WITH_ACK_MESSAGE);
assertCommandAndResponse( assertCommandAndResponse(
"poll_ack.xml", "poll_ack.xml",
ImmutableMap.of("ID", "2-1-ROID-3-6"), ImmutableMap.of("ID", "2-1-ROID-3-6"),
"poll_ack_response_empty.xml", "poll_ack_response_empty.xml",
null, null,
DateTime.parse("2000-06-08T22:02:00Z")); DateTime.parse("2000-06-08T22:02:00Z"));
assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar")
.and()
.hasCommandName("PollAck")
.and()
.hasStatus(SUCCESS_WITH_NO_MESSAGES);
assertCommandAndResponse("logout.xml", "logout_response.xml"); assertCommandAndResponse("logout.xml", "logout_response.xml");
} }
} }

View file

@ -62,11 +62,17 @@ public class EppLifecycleDomainApplicationTest extends EppTestCase {
startTime.plusMinutes(1)); startTime.plusMinutes(1));
assertCommandAndResponse( assertCommandAndResponse(
"host_create.xml", "host_create.xml",
ImmutableMap.of("HOSTNAME", "ns1.example.external"),
"host_create_response.xml", "host_create_response.xml",
ImmutableMap.of(
"HOSTNAME", "ns1.example.external", "CRDATE", startTime.plusMinutes(2).toString()),
startTime.plusMinutes(2)); startTime.plusMinutes(2));
assertCommandAndResponse( assertCommandAndResponse(
"host_create2.xml", "host_create.xml",
"host_create2_response.xml", ImmutableMap.of("HOSTNAME", "ns2.example.external"),
"host_create_response.xml",
ImmutableMap.of(
"HOSTNAME", "ns2.example.external", "CRDATE", startTime.plusMinutes(3).toString()),
startTime.plusMinutes(3)); startTime.plusMinutes(3));
} }

View file

@ -62,9 +62,19 @@ public class EppLifecycleDomainTest extends EppTestCase {
"contact_create_response_jd1234.xml", "contact_create_response_jd1234.xml",
startTime.plusMinutes(1)); startTime.plusMinutes(1));
assertCommandAndResponse( assertCommandAndResponse(
"host_create.xml", "host_create_response.xml", startTime.plusMinutes(2)); "host_create.xml",
ImmutableMap.of("HOSTNAME", "ns1.example.external"),
"host_create_response.xml",
ImmutableMap.of(
"HOSTNAME", "ns1.example.external", "CRDATE", startTime.plusMinutes(2).toString()),
startTime.plusMinutes(2));
assertCommandAndResponse( assertCommandAndResponse(
"host_create2.xml", "host_create2_response.xml", startTime.plusMinutes(3)); "host_create.xml",
ImmutableMap.of("HOSTNAME", "ns2.example.external"),
"host_create_response.xml",
ImmutableMap.of(
"HOSTNAME", "ns2.example.external", "CRDATE", startTime.plusMinutes(3).toString()),
startTime.plusMinutes(3));
} }
/** Creates the domain fakesite.example with two nameservers on it. */ /** Creates the domain fakesite.example with two nameservers on it. */
@ -336,6 +346,14 @@ public class EppLifecycleDomainTest extends EppTestCase {
"domain_check_fee_premium.xml", "domain_check_fee_premium.xml",
"domain_check_fee_premium_response.xml", "domain_check_fee_premium_response.xml",
gaDate.plusDays(1)); gaDate.plusDays(1));
assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar")
.and()
.hasCommandName("DomainCheck")
.and()
.hasEppTarget("rich.example")
.and()
.hasStatus(SUCCESS);
assertCommandAndResponse("logout.xml", "logout_response.xml"); assertCommandAndResponse("logout.xml", "logout_response.xml");
} }
@ -481,7 +499,7 @@ public class EppLifecycleDomainTest extends EppTestCase {
"host_info_fakesite.xml", "host_info_fakesite.xml",
null, null,
"host_info_response_fakesite_post_transfer.xml", "host_info_response_fakesite_post_transfer.xml",
ImmutableMap.of("trDate", "2002-06-04T00:00:00Z"), ImmutableMap.of("TRDATE", "2002-06-04T00:00:00Z"),
DateTime.parse("2002-06-09T00:01:00Z")); DateTime.parse("2002-06-09T00:01:00Z"));
assertCommandAndResponse("logout.xml", "logout_response.xml"); assertCommandAndResponse("logout.xml", "logout_response.xml");
} }
@ -589,9 +607,9 @@ public class EppLifecycleDomainTest extends EppTestCase {
// Verify that the lastTransferTime now reflects the superordinate domain's transfer. // Verify that the lastTransferTime now reflects the superordinate domain's transfer.
assertCommandAndResponse( assertCommandAndResponse(
"host_info.xml", "host_info.xml",
ImmutableMap.of("hostname", "ns3.fakesite.example"), ImmutableMap.of("HOSTNAME", "ns3.fakesite.example"),
"host_info_response_fakesite_post_transfer.xml", "host_info_response_fakesite_post_transfer.xml",
ImmutableMap.of("trDate", "2001-01-06T00:00:00.000Z"), ImmutableMap.of("TRDATE", "2001-01-06T00:00:00.000Z"),
DateTime.parse("2001-01-07T00:00:00Z")); DateTime.parse("2001-01-07T00:00:00Z"));
assertCommandAndResponse( assertCommandAndResponse(
"domain_create_secondsite.xml", "domain_create_secondsite.xml",
@ -608,11 +626,11 @@ public class EppLifecycleDomainTest extends EppTestCase {
// The last transfer time on the host should still be what it was from the transfer. // The last transfer time on the host should still be what it was from the transfer.
assertCommandAndResponse( assertCommandAndResponse(
"host_info.xml", "host_info.xml",
ImmutableMap.of("hostname", "ns3.secondsite.example"), ImmutableMap.of("HOSTNAME", "ns3.secondsite.example"),
"host_info_response_fakesite_post_transfer_and_update.xml", "host_info_response_fakesite_post_transfer_and_update.xml",
ImmutableMap.of( ImmutableMap.of(
"hostname", "ns3.secondsite.example", "HOSTNAME", "ns3.secondsite.example",
"trDate", "2001-01-06T00:00:00.000Z"), "TRDATE", "2001-01-06T00:00:00.000Z"),
DateTime.parse("2003-01-07T00:00:00Z")); DateTime.parse("2003-01-07T00:00:00Z"));
assertCommandAndResponse("logout.xml", "logout_response.xml"); assertCommandAndResponse("logout.xml", "logout_response.xml");
} }
@ -644,7 +662,7 @@ public class EppLifecycleDomainTest extends EppTestCase {
"host_info_fakesite.xml", "host_info_fakesite.xml",
null, null,
"host_info_response_fakesite_post_transfer.xml", "host_info_response_fakesite_post_transfer.xml",
ImmutableMap.of("trDate", "2001-01-06T00:00:00.000Z"), ImmutableMap.of("TRDATE", "2001-01-06T00:00:00.000Z"),
DateTime.parse("2001-01-07T00:00:00Z")); DateTime.parse("2001-01-07T00:00:00Z"));
// Update the host to be external by renaming it to ns3.notarealsite.external // Update the host to be external by renaming it to ns3.notarealsite.external
assertCommandAndResponse( assertCommandAndResponse(
@ -658,11 +676,11 @@ public class EppLifecycleDomainTest extends EppTestCase {
// The last transfer time on the host should still be what it was from the transfer. // The last transfer time on the host should still be what it was from the transfer.
assertCommandAndResponse( assertCommandAndResponse(
"host_info.xml", "host_info.xml",
ImmutableMap.of("hostname", "ns3.notarealsite.external"), ImmutableMap.of("HOSTNAME", "ns3.notarealsite.external"),
"host_info_response_fakesite_post_transfer_and_update_no_addresses.xml", "host_info_response_fakesite_post_transfer_and_update_no_addresses.xml",
ImmutableMap.of( ImmutableMap.of(
"hostname", "ns3.notarealsite.external", "HOSTNAME", "ns3.notarealsite.external",
"trDate", "2001-01-06T00:00:00.000Z"), "TRDATE", "2001-01-06T00:00:00.000Z"),
DateTime.parse("2001-01-07T00:00:00Z")); DateTime.parse("2001-01-07T00:00:00Z"));
assertCommandAndResponse("logout.xml", "logout_response.xml"); assertCommandAndResponse("logout.xml", "logout_response.xml");
} }

View file

@ -14,7 +14,10 @@
package google.registry.flows; package google.registry.flows;
import static google.registry.model.eppoutput.Result.Code.SUCCESS;
import static google.registry.model.eppoutput.Result.Code.SUCCESS_WITH_ACTION_PENDING;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
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;
@ -34,6 +37,68 @@ public class EppLifecycleHostTest extends EppTestCase {
.withTaskQueue() .withTaskQueue()
.build(); .build();
@Test
public void testLifecycle() throws Exception {
assertCommandAndResponse("login_valid.xml", "login_response.xml");
assertCommandAndResponse(
"hello.xml",
ImmutableMap.<String, String>of(),
"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.
assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar")
.and()
.hasCommandName("Hello")
.and()
.hasNoStatus();
assertCommandAndResponse(
"host_create.xml",
ImmutableMap.of("HOSTNAME", "ns1.example.tld"),
"host_create_response.xml",
ImmutableMap.of("HOSTNAME", "ns1.example.tld", "CRDATE", "2000-06-02T00:01:00Z"),
DateTime.parse("2000-06-02T00:01:00Z"));
assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar")
.and()
.hasCommandName("HostCreate")
.and()
.hasEppTarget("ns1.example.tld")
.and()
.hasStatus(SUCCESS);
assertCommandAndResponse(
"host_info.xml",
ImmutableMap.of("HOSTNAME", "ns1.example.tld"),
"host_info_response.xml",
ImmutableMap.<String, String>of(
"HOSTNAME", "ns1.example.tld", "ROID", "1-ROID", "CRDATE", "2000-06-02T00:01:00Z"),
DateTime.parse("2000-06-02T00:02:00Z"));
assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar")
.and()
.hasCommandName("HostInfo")
.and()
.hasEppTarget("ns1.example.tld")
.and()
.hasStatus(SUCCESS);
assertCommandAndResponse(
"host_delete.xml",
ImmutableMap.of("HOSTNAME", "ns1.example.tld"),
"generic_success_action_pending_response.xml",
ImmutableMap.<String, String>of(),
DateTime.parse("2000-06-02T00:03:00Z"));
assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar")
.and()
.hasCommandName("HostDelete")
.and()
.hasEppTarget("ns1.example.tld")
.and()
.hasStatus(SUCCESS_WITH_ACTION_PENDING);
assertCommandAndResponse("logout.xml", "logout_response.xml");
}
@Test @Test
public void testRenamingHostToExistingHost_fails() throws Exception { public void testRenamingHostToExistingHost_fails() throws Exception {
createTld("example"); createTld("example");

View file

@ -2,7 +2,7 @@
<command> <command>
<create> <create>
<host:create xmlns:host="urn:ietf:params:xml:ns:host-1.0"> <host:create xmlns:host="urn:ietf:params:xml:ns:host-1.0">
<host:name>ns1.example.external</host:name> <host:name>%HOSTNAME%</host:name>
</host:create> </host:create>
</create> </create>
<clTRID>ABC-12345</clTRID> <clTRID>ABC-12345</clTRID>

View file

@ -1,10 +0,0 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<create>
<host:create xmlns:host="urn:ietf:params:xml:ns:host-1.0">
<host:name>ns2.example.external</host:name>
</host:create>
</create>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -1,17 +0,0 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<response>
<result code="1000">
<msg>Command completed successfully</msg>
</result>
<resData>
<host:creData xmlns:host="urn:ietf:params:xml:ns:host-1.0">
<host:name>ns2.example.external</host:name>
<host:crDate>2000-06-01T00:03:00Z</host:crDate>
</host:creData>
</resData>
<trID>
<clTRID>ABC-12345</clTRID>
<svTRID>54322-XYZ</svTRID>
</trID>
</response>
</epp>

View file

@ -5,13 +5,13 @@
</result> </result>
<resData> <resData>
<host:creData xmlns:host="urn:ietf:params:xml:ns:host-1.0"> <host:creData xmlns:host="urn:ietf:params:xml:ns:host-1.0">
<host:name>ns1.example.external</host:name> <host:name>%HOSTNAME%</host:name>
<host:crDate>2000-06-01T00:02:00Z</host:crDate> <host:crDate>%CRDATE%</host:crDate>
</host:creData> </host:creData>
</resData> </resData>
<trID> <trID>
<clTRID>ABC-12345</clTRID> <clTRID>ABC-12345</clTRID>
<svTRID>54322-XYZ</svTRID> <svTRID>server-trid</svTRID>
</trID> </trID>
</response> </response>
</epp> </epp>

View file

@ -0,0 +1,11 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<delete>
<host:delete
xmlns:host="urn:ietf:params:xml:ns:host-1.0">
<host:name>%HOSTNAME%</host:name>
</host:delete>
</delete>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -2,7 +2,7 @@
<command> <command>
<info> <info>
<host:info xmlns:host="urn:ietf:params:xml:ns:host-1.0"> <host:info xmlns:host="urn:ietf:params:xml:ns:host-1.0">
<host:name>%hostname%</host:name> <host:name>%HOSTNAME%</host:name>
</host:info> </host:info>
</info> </info>
<clTRID>ABC-12345</clTRID> <clTRID>ABC-12345</clTRID>

View file

@ -0,0 +1,22 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<response>
<result code="1000">
<msg>Command completed successfully</msg>
</result>
<resData>
<host:infData
xmlns:host="urn:ietf:params:xml:ns:host-1.0">
<host:name>%HOSTNAME%</host:name>
<host:roid>%ROID%</host:roid>
<host:status s="ok"/>
<host:clID>NewRegistrar</host:clID>
<host:crID>NewRegistrar</host:crID>
<host:crDate>%CRDATE%</host:crDate>
</host:infData>
</resData>
<trID>
<clTRID>ABC-12345</clTRID>
<svTRID>server-trid</svTRID>
</trID>
</response>
</epp>

View file

@ -16,7 +16,7 @@
<host:clID>TheRegistrar</host:clID> <host:clID>TheRegistrar</host:clID>
<host:crID>NewRegistrar</host:crID> <host:crID>NewRegistrar</host:crID>
<host:crDate>2000-06-06T00:01:00Z</host:crDate> <host:crDate>2000-06-06T00:01:00Z</host:crDate>
<host:trDate>%trDate%</host:trDate> <host:trDate>%TRDATE%</host:trDate>
</host:infData> </host:infData>
</resData> </resData>
<trID> <trID>

View file

@ -6,7 +6,7 @@
<resData> <resData>
<host:infData <host:infData
xmlns:host="urn:ietf:params:xml:ns:host-1.0"> xmlns:host="urn:ietf:params:xml:ns:host-1.0">
<host:name>%hostname%</host:name> <host:name>%HOSTNAME%</host:name>
<host:roid>NS1_EXAMPLE1-REP</host:roid> <host:roid>NS1_EXAMPLE1-REP</host:roid>
<host:status s="ok"/> <host:status s="ok"/>
<host:status s="linked"/> <host:status s="linked"/>
@ -18,7 +18,7 @@
<host:crDate>2000-06-06T00:01:00Z</host:crDate> <host:crDate>2000-06-06T00:01:00Z</host:crDate>
<host:upID>TheRegistrar</host:upID> <host:upID>TheRegistrar</host:upID>
<host:upDate>2002-05-30T01:01:00Z</host:upDate> <host:upDate>2002-05-30T01:01:00Z</host:upDate>
<host:trDate>%trDate%</host:trDate> <host:trDate>%TRDATE%</host:trDate>
</host:infData> </host:infData>
</resData> </resData>
<trID> <trID>

View file

@ -6,7 +6,7 @@
<resData> <resData>
<host:infData <host:infData
xmlns:host="urn:ietf:params:xml:ns:host-1.0"> xmlns:host="urn:ietf:params:xml:ns:host-1.0">
<host:name>%hostname%</host:name> <host:name>%HOSTNAME%</host:name>
<host:roid>NS1_EXAMPLE1-REP</host:roid> <host:roid>NS1_EXAMPLE1-REP</host:roid>
<host:status s="ok"/> <host:status s="ok"/>
<host:status s="linked"/> <host:status s="linked"/>
@ -15,7 +15,7 @@
<host:crDate>2000-06-06T00:01:00Z</host:crDate> <host:crDate>2000-06-06T00:01:00Z</host:crDate>
<host:upID>TheRegistrar</host:upID> <host:upID>TheRegistrar</host:upID>
<host:upDate>2002-05-30T01:01:00Z</host:upDate> <host:upDate>2002-05-30T01:01:00Z</host:upDate>
<host:trDate>%trDate%</host:trDate> <host:trDate>%TRDATE%</host:trDate>
</host:infData> </host:infData>
</resData> </resData>
<trID> <trID>

View file

@ -54,6 +54,13 @@ public class EppMetricSubject extends Subject<EppMetricSubject, EppMetric> {
return hasValue(status, actual().getStatus(), "has status"); return hasValue(status, actual().getStatus(), "has status");
} }
public And<EppMetricSubject> hasNoStatus() {
if (actual().getStatus().isPresent()) {
fail("has no status");
}
return new And<>(this);
}
private <E> And<EppMetricSubject> hasValue(E expected, Optional<E> actual, String verb) { private <E> And<EppMetricSubject> hasValue(E expected, Optional<E> actual, String verb) {
checkArgumentNotNull(expected, "Expected value cannot be null"); checkArgumentNotNull(expected, "Expected value cannot be null");
if (actual == null) { if (actual == null) {