mirror of
https://github.com/google/nomulus.git
synced 2025-08-06 01:35:17 +02:00
Append event year to poll message external IDs
This solves the problem of external poll message IDs not being globally unique by simply appending the event year. This means that autorenew poll messages will increment by one every year, so they will always be unique. This also requires no data schema changes, and thus most importantly, no data migration. Incoming requests lacking this new year field will continue to work for now for backwards compatibility reasons. This is possible because we don't actually use the year for anything. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=178012685
This commit is contained in:
parent
8e33bc898f
commit
931156fdd7
26 changed files with 270 additions and 127 deletions
|
@ -114,7 +114,7 @@ public class EppLifecycleContactTest extends EppTestCase {
|
|||
.hasStatus(SUCCESS_WITH_ACK_MESSAGE);
|
||||
assertCommandAndResponse(
|
||||
"poll_ack.xml",
|
||||
ImmutableMap.of("ID", "2-1-ROID-3-6"),
|
||||
ImmutableMap.of("ID", "2-1-ROID-3-6-2000"),
|
||||
"poll_ack_response_empty.xml",
|
||||
null,
|
||||
DateTime.parse("2000-06-08T22:02:00Z"));
|
||||
|
|
|
@ -364,6 +364,61 @@ public class EppLifecycleDomainTest extends EppTestCase {
|
|||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDomainCreate_annualAutoRenewPollMessages_haveUniqueIds() throws Exception {
|
||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||
// Create the domain.
|
||||
createFakesite();
|
||||
|
||||
// The first autorenew poll message isn't seen until after the initial two years of registration
|
||||
// are up.
|
||||
assertCommandAndResponse(
|
||||
"poll.xml", "poll_response_empty.xml", DateTime.parse("2001-01-01T00:01:00Z"));
|
||||
assertCommandAndResponse(
|
||||
"poll.xml",
|
||||
ImmutableMap.of(),
|
||||
"poll_response_autorenew.xml",
|
||||
ImmutableMap.of(
|
||||
"ID", "1-C-EXAMPLE-13-16-2002",
|
||||
"QDATE", "2002-06-01T00:04:00Z",
|
||||
"DOMAIN", "fakesite.example",
|
||||
"EXDATE", "2003-06-01T00:04:00Z"),
|
||||
DateTime.parse("2002-07-01T00:01:00Z"));
|
||||
assertCommandAndResponse(
|
||||
"poll_ack.xml",
|
||||
ImmutableMap.of("ID", "1-C-EXAMPLE-13-16-2002"),
|
||||
"poll_ack_response_empty.xml",
|
||||
null,
|
||||
DateTime.parse("2002-07-01T00:02:00Z"));
|
||||
|
||||
// The second autorenew poll message isn't seen until after another year, and it should have a
|
||||
// different ID.
|
||||
assertCommandAndResponse(
|
||||
"poll.xml", "poll_response_empty.xml", DateTime.parse("2002-07-01T00:05:00Z"));
|
||||
assertCommandAndResponse(
|
||||
"poll.xml",
|
||||
ImmutableMap.of(),
|
||||
"poll_response_autorenew.xml",
|
||||
ImmutableMap.of(
|
||||
"ID", "1-C-EXAMPLE-13-16-2003", // Note -- Year is different from previous ID.
|
||||
"QDATE", "2003-06-01T00:04:00Z",
|
||||
"DOMAIN", "fakesite.example",
|
||||
"EXDATE", "2004-06-01T00:04:00Z"),
|
||||
DateTime.parse("2003-07-01T00:05:00Z"));
|
||||
|
||||
// Ack the second poll message and verify that none remain.
|
||||
assertCommandAndResponse(
|
||||
"poll_ack.xml",
|
||||
ImmutableMap.of("ID", "1-C-EXAMPLE-13-16-2003"),
|
||||
"poll_ack_response_empty.xml",
|
||||
null,
|
||||
DateTime.parse("2003-07-01T00:05:05Z"));
|
||||
assertCommandAndResponse(
|
||||
"poll.xml", "poll_response_empty.xml", DateTime.parse("2003-07-01T00:05:10Z"));
|
||||
|
||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDomainTransferPollMessage_serverApproved() throws Exception {
|
||||
// As the losing registrar, create the domain.
|
||||
|
@ -391,7 +446,7 @@ public class EppLifecycleDomainTest extends EppTestCase {
|
|||
DateTime.parse("2001-01-01T00:01:00Z"));
|
||||
assertCommandAndResponse(
|
||||
"poll_ack.xml",
|
||||
ImmutableMap.of("ID", "1-C-EXAMPLE-17-23"),
|
||||
ImmutableMap.of("ID", "1-C-EXAMPLE-17-23-2001"),
|
||||
"poll_ack_response_empty.xml",
|
||||
null,
|
||||
DateTime.parse("2001-01-01T00:01:00Z"));
|
||||
|
@ -403,7 +458,7 @@ public class EppLifecycleDomainTest extends EppTestCase {
|
|||
DateTime.parse("2001-01-06T00:01:00Z"));
|
||||
assertCommandAndResponse(
|
||||
"poll_ack.xml",
|
||||
ImmutableMap.of("ID", "1-C-EXAMPLE-17-22"),
|
||||
ImmutableMap.of("ID", "1-C-EXAMPLE-17-22-2001"),
|
||||
"poll_ack_response_empty.xml",
|
||||
null,
|
||||
DateTime.parse("2001-01-06T00:01:00Z"));
|
||||
|
@ -419,7 +474,7 @@ public class EppLifecycleDomainTest extends EppTestCase {
|
|||
DateTime.parse("2001-01-06T00:02:00Z"));
|
||||
assertCommandAndResponse(
|
||||
"poll_ack.xml",
|
||||
ImmutableMap.of("ID", "1-C-EXAMPLE-17-21"),
|
||||
ImmutableMap.of("ID", "1-C-EXAMPLE-17-21-2001"),
|
||||
"poll_ack_response_empty.xml",
|
||||
null,
|
||||
DateTime.parse("2001-01-06T00:02:00Z"));
|
||||
|
|
|
@ -14,13 +14,17 @@
|
|||
|
||||
package google.registry.flows.poll;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.DatastoreHelper.createHistoryEntryForEppResource;
|
||||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.newDomainResource;
|
||||
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.JUnitBackports.expectThrows;
|
||||
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.flows.FlowTestCase;
|
||||
import google.registry.flows.poll.PollAckFlow.InvalidMessageIdException;
|
||||
import google.registry.flows.poll.PollAckFlow.MessageDoesNotExistException;
|
||||
|
@ -36,7 +40,7 @@ import org.junit.Test;
|
|||
/** Unit tests for {@link PollAckFlow}. */
|
||||
public class PollAckFlowTest extends FlowTestCase<PollAckFlow> {
|
||||
|
||||
/** This is the message id contained in the "poll_ack.xml" test data file. */
|
||||
/** This is the message id being sent in the ACK request. */
|
||||
private static final long MESSAGE_ID = 3;
|
||||
|
||||
private DomainResource domain;
|
||||
|
@ -44,7 +48,7 @@ public class PollAckFlowTest extends FlowTestCase<PollAckFlow> {
|
|||
|
||||
@Before
|
||||
public void setUp() {
|
||||
setEppInput("poll_ack.xml");
|
||||
setEppInput("poll_ack.xml", ImmutableMap.of("MSGID", "1-3-EXAMPLE-4-3-2011"));
|
||||
setClientIdForFlow("NewRegistrar");
|
||||
clock.setTo(DateTime.parse("2011-01-02T01:01:01Z"));
|
||||
createTld("example");
|
||||
|
@ -87,7 +91,38 @@ public class PollAckFlowTest extends FlowTestCase<PollAckFlow> {
|
|||
|
||||
@Test
|
||||
public void testSuccess_contactPollMessage() throws Exception {
|
||||
setEppInput("poll_ack_contact.xml");
|
||||
setEppInput("poll_ack.xml", ImmutableMap.of("MSGID", "2-2-ROID-4-3-2011"));
|
||||
persistResource(
|
||||
new PollMessage.OneTime.Builder()
|
||||
.setId(MESSAGE_ID)
|
||||
.setClientId(getClientIdForFlow())
|
||||
.setEventTime(clock.nowUtc().minusDays(1))
|
||||
.setMsg("Some poll message.")
|
||||
.setParent(createHistoryEntryForEppResource(contact))
|
||||
.build());
|
||||
assertTransactionalFlow(true);
|
||||
runFlowAssertResponse(loadFile("poll_ack_response_empty.xml"));
|
||||
}
|
||||
|
||||
// TODO(b/68953444): Remove test when missing year field backwards compatibility no longer needed.
|
||||
@Test
|
||||
public void testSuccess_contactPollMessage_withMissingYearField() throws Exception {
|
||||
setEppInput("poll_ack.xml", ImmutableMap.of("MSGID", "2-2-ROID-4-3"));
|
||||
persistResource(
|
||||
new PollMessage.OneTime.Builder()
|
||||
.setId(MESSAGE_ID)
|
||||
.setClientId(getClientIdForFlow())
|
||||
.setEventTime(clock.nowUtc().minusDays(1))
|
||||
.setMsg("Some poll message.")
|
||||
.setParent(createHistoryEntryForEppResource(contact))
|
||||
.build());
|
||||
assertTransactionalFlow(true);
|
||||
runFlowAssertResponse(loadFile("poll_ack_response_empty.xml"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_contactPollMessage_withIncorrectYearField() throws Exception {
|
||||
setEppInput("poll_ack.xml", ImmutableMap.of("MSGID", "2-2-ROID-4-3-1999"));
|
||||
persistResource(
|
||||
new PollMessage.OneTime.Builder()
|
||||
.setId(MESSAGE_ID)
|
||||
|
@ -146,42 +181,45 @@ public class PollAckFlowTest extends FlowTestCase<PollAckFlow> {
|
|||
@Test
|
||||
public void testFailure_noSuchMessage() throws Exception {
|
||||
assertTransactionalFlow(true);
|
||||
thrown.expect(
|
||||
MessageDoesNotExistException.class,
|
||||
String.format("(1-3-EXAMPLE-4-%d)", MESSAGE_ID));
|
||||
runFlow();
|
||||
Exception e = expectThrows(MessageDoesNotExistException.class, this::runFlow);
|
||||
assertThat(e)
|
||||
.hasMessageThat()
|
||||
.containsMatch(String.format("(1-3-EXAMPLE-4-%d-2011)", MESSAGE_ID));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_invalidId_wrongNumberOfComponents() throws Exception {
|
||||
setEppInput("poll_ack_invalid_id.xml");
|
||||
public void testFailure_invalidId_tooFewComponents() throws Exception {
|
||||
setEppInput("poll_ack.xml", ImmutableMap.of("MSGID", "1-2-3"));
|
||||
assertTransactionalFlow(true);
|
||||
thrown.expect(InvalidMessageIdException.class);
|
||||
runFlow();
|
||||
assertThrows(InvalidMessageIdException.class, this::runFlow);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_invalidId_tooManyComponents() throws Exception {
|
||||
setEppInput("poll_ack.xml", ImmutableMap.of("MSGID", "2-2-ROID-4-3-1999-2007"));
|
||||
assertTransactionalFlow(true);
|
||||
assertThrows(InvalidMessageIdException.class, this::runFlow);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_invalidId_stringInsteadOfNumeric() throws Exception {
|
||||
setEppInput("poll_ack_invalid_string_id.xml");
|
||||
setEppInput("poll_ack.xml", ImmutableMap.of("MSGID", "ABC-12345"));
|
||||
assertTransactionalFlow(true);
|
||||
thrown.expect(InvalidMessageIdException.class);
|
||||
runFlow();
|
||||
assertThrows(InvalidMessageIdException.class, this::runFlow);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_invalidEppResourceClassId() throws Exception {
|
||||
setEppInput("poll_ack_invalid_eppresource_id.xml");
|
||||
setEppInput("poll_ack.xml", ImmutableMap.of("MSGID", "999-1-1-1"));
|
||||
assertTransactionalFlow(true);
|
||||
thrown.expect(InvalidMessageIdException.class);
|
||||
runFlow();
|
||||
assertThrows(InvalidMessageIdException.class, this::runFlow);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_missingId() throws Exception {
|
||||
setEppInput("poll_ack_missing_id.xml");
|
||||
assertTransactionalFlow(true);
|
||||
thrown.expect(MissingMessageIdException.class);
|
||||
runFlow();
|
||||
assertThrows(MissingMessageIdException.class, this::runFlow);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -195,8 +233,7 @@ public class PollAckFlowTest extends FlowTestCase<PollAckFlow> {
|
|||
.setParent(createHistoryEntryForEppResource(domain))
|
||||
.build());
|
||||
assertTransactionalFlow(true);
|
||||
thrown.expect(NotAuthorizedToAckMessageException.class);
|
||||
runFlow();
|
||||
assertThrows(NotAuthorizedToAckMessageException.class, this::runFlow);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -210,9 +247,9 @@ public class PollAckFlowTest extends FlowTestCase<PollAckFlow> {
|
|||
.setParent(createHistoryEntryForEppResource(domain))
|
||||
.build());
|
||||
assertTransactionalFlow(true);
|
||||
thrown.expect(
|
||||
MessageDoesNotExistException.class,
|
||||
String.format("(1-3-EXAMPLE-4-%d)", MESSAGE_ID));
|
||||
runFlow();
|
||||
Exception e = expectThrows(MessageDoesNotExistException.class, this::runFlow);
|
||||
assertThat(e)
|
||||
.hasMessageThat()
|
||||
.containsMatch(String.format("(1-3-EXAMPLE-4-%d-2011)", MESSAGE_ID));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<command>
|
||||
<poll op="ack" msgID="1-3-EXAMPLE-4-3"/>
|
||||
<poll op="ack" msgID="%MSGID%"/>
|
||||
<clTRID>ABC-12346</clTRID>
|
||||
</command>
|
||||
</epp>
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<command>
|
||||
<poll op="ack" msgID="2-2-ROID-4-3"/>
|
||||
<clTRID>ABC-12346</clTRID>
|
||||
</command>
|
||||
</epp>
|
|
@ -1,6 +0,0 @@
|
|||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<command>
|
||||
<poll op="ack" msgID="999-1-1-1"/>
|
||||
<clTRID>ABC-12346</clTRID>
|
||||
</command>
|
||||
</epp>
|
|
@ -1,6 +0,0 @@
|
|||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<command>
|
||||
<poll op="ack" msgID="1-2-3"/>
|
||||
<clTRID>ABC-12346</clTRID>
|
||||
</command>
|
||||
</epp>
|
|
@ -1,6 +0,0 @@
|
|||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<command>
|
||||
<poll op="ack" msgID="ABC-12345"/>
|
||||
<clTRID>ABC-12346</clTRID>
|
||||
</command>
|
||||
</epp>
|
|
@ -3,7 +3,7 @@
|
|||
<result code="1000">
|
||||
<msg>Command completed successfully</msg>
|
||||
</result>
|
||||
<msgQ count="4" id="1-3-EXAMPLE-4-3"/>
|
||||
<msgQ count="4" id="1-3-EXAMPLE-4-3-2011"/>
|
||||
<trID>
|
||||
<clTRID>ABC-12346</clTRID>
|
||||
<svTRID>server-trid</svTRID>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<result code="1301">
|
||||
<msg>Command completed successfully; ack to dequeue</msg>
|
||||
</result>
|
||||
<msgQ count="1" id="1-3-EXAMPLE-5-6">
|
||||
<msgQ count="1" id="1-3-EXAMPLE-5-6-2011">
|
||||
<qDate>2011-01-01T01:01:01Z</qDate>
|
||||
<msg>Domain was auto-renewed.</msg>
|
||||
</msgQ>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<result code="1301">
|
||||
<msg>Command completed successfully; ack to dequeue</msg>
|
||||
</result>
|
||||
<msgQ count="1" id="2-2-ROID-5-6">
|
||||
<msgQ count="1" id="2-2-ROID-5-6-2011">
|
||||
<qDate>2011-01-01T01:01:01Z</qDate>
|
||||
<msg>Deleted contact jd1234</msg>
|
||||
</msgQ>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<result code="1301">
|
||||
<msg>Command completed successfully; ack to dequeue</msg>
|
||||
</result>
|
||||
<msgQ count="1" id="2-2-ROID-5-3">
|
||||
<msgQ count="1" id="2-2-ROID-5-3-2000">
|
||||
<qDate>2000-06-08T22:00:00Z</qDate>
|
||||
<msg>Transfer requested.</msg>
|
||||
</msgQ>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<result code="1301">
|
||||
<msg>Command completed successfully; ack to dequeue</msg>
|
||||
</result>
|
||||
<msgQ count="1" id="1-3-EXAMPLE-5-6">
|
||||
<msgQ count="1" id="1-3-EXAMPLE-5-6-2011">
|
||||
<qDate>2011-01-01T01:01:01Z</qDate>
|
||||
<msg>Domain deleted.</msg>
|
||||
</msgQ>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<result code="1301">
|
||||
<msg>Command completed successfully; ack to dequeue</msg>
|
||||
</result>
|
||||
<msgQ count="1" id="1-3-EXAMPLE-5-6">
|
||||
<msgQ count="1" id="1-3-EXAMPLE-5-6-2011">
|
||||
<qDate>2011-01-01T01:01:01Z</qDate>
|
||||
<msg>Transfer approved.</msg>
|
||||
</msgQ>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<result code="1301">
|
||||
<msg>Command completed successfully; ack to dequeue</msg>
|
||||
</result>
|
||||
<msgQ count="1" id="3-4-ROID-5-6">
|
||||
<msgQ count="1" id="3-4-ROID-5-6-2011">
|
||||
<qDate>2011-01-01T01:01:01Z</qDate>
|
||||
<msg>Deleted host ns1.test.example</msg>
|
||||
</msgQ>
|
||||
|
|
22
javatests/google/registry/flows/testdata/poll_response_autorenew.xml
vendored
Normal file
22
javatests/google/registry/flows/testdata/poll_response_autorenew.xml
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<response>
|
||||
<result code="1301">
|
||||
<msg>Command completed successfully; ack to dequeue</msg>
|
||||
</result>
|
||||
<msgQ count="1" id="%ID%">
|
||||
<qDate>%QDATE%</qDate>
|
||||
<msg>Domain was auto-renewed.</msg>
|
||||
</msgQ>
|
||||
<resData>
|
||||
<domain:renData
|
||||
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
||||
<domain:name>%DOMAIN%</domain:name>
|
||||
<domain:exDate>%EXDATE%</domain:exDate>
|
||||
</domain:renData>
|
||||
</resData>
|
||||
<trID>
|
||||
<clTRID>ABC-12345</clTRID>
|
||||
<svTRID>server-trid</svTRID>
|
||||
</trID>
|
||||
</response>
|
||||
</epp>
|
|
@ -3,7 +3,7 @@
|
|||
<result code="1301">
|
||||
<msg>Command completed successfully; ack to dequeue</msg>
|
||||
</result>
|
||||
<msgQ count="1" id="2-1-ROID-3-6">
|
||||
<msgQ count="1" id="2-1-ROID-3-6-2000">
|
||||
<qDate>2000-06-08T22:00:00Z</qDate>
|
||||
<msg>Transfer requested.</msg>
|
||||
</msgQ>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<result code="1301">
|
||||
<msg>Command completed successfully; ack to dequeue</msg>
|
||||
</result>
|
||||
<msgQ count="1" id="1-C-EXAMPLE-17-23">
|
||||
<msgQ count="1" id="1-C-EXAMPLE-17-23-2001">
|
||||
<qDate>2001-01-01T00:00:00Z</qDate>
|
||||
<msg>Transfer requested.</msg>
|
||||
</msgQ>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<result code="1301">
|
||||
<msg>Command completed successfully; ack to dequeue</msg>
|
||||
</result>
|
||||
<msgQ count="1" id="1-C-EXAMPLE-17-22">
|
||||
<msgQ count="1" id="1-C-EXAMPLE-17-22-2001">
|
||||
<qDate>2001-01-06T00:00:00Z</qDate>
|
||||
<msg>Transfer approved.</msg>
|
||||
</msgQ>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<result code="1301">
|
||||
<msg>Command completed successfully; ack to dequeue</msg>
|
||||
</result>
|
||||
<msgQ count="1" id="1-C-EXAMPLE-17-21">
|
||||
<msgQ count="1" id="1-C-EXAMPLE-17-21-2001">
|
||||
<qDate>2001-01-06T00:00:00Z</qDate>
|
||||
<msg>Transfer approved.</msg>
|
||||
</msgQ>
|
||||
|
|
11
javatests/google/registry/flows/testdata/poll_response_empty.xml
vendored
Normal file
11
javatests/google/registry/flows/testdata/poll_response_empty.xml
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<response>
|
||||
<result code="1300">
|
||||
<msg>Command completed successfully; no messages</msg>
|
||||
</result>
|
||||
<trID>
|
||||
<clTRID>ABC-12345</clTRID>
|
||||
<svTRID>server-trid</svTRID>
|
||||
</trID>
|
||||
</response>
|
||||
</epp>
|
|
@ -15,13 +15,15 @@
|
|||
package google.registry.model.poll;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.poll.PollMessageExternalKeyConverter.makePollMessageExternalId;
|
||||
import static google.registry.model.poll.PollMessageExternalKeyConverter.parsePollMessageExternalId;
|
||||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.persistActiveContact;
|
||||
import static google.registry.testing.DatastoreHelper.persistActiveDomain;
|
||||
import static google.registry.testing.DatastoreHelper.persistActiveHost;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.model.domain.Period;
|
||||
|
@ -56,8 +58,7 @@ public class PollMessageExternalKeyConverterTest {
|
|||
public final ExceptionRule thrown = new ExceptionRule();
|
||||
|
||||
HistoryEntry historyEntry;
|
||||
FakeClock clock = new FakeClock(DateTime.now(UTC));
|
||||
PollMessageExternalKeyConverter converter = new PollMessageExternalKeyConverter();
|
||||
FakeClock clock = new FakeClock(DateTime.parse("2007-07-07T01:01:01Z"));
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
@ -79,48 +80,65 @@ public class PollMessageExternalKeyConverterTest {
|
|||
|
||||
@Test
|
||||
public void testSuccess_domain() {
|
||||
PollMessage.OneTime pollMessage = persistResource(
|
||||
new PollMessage.OneTime.Builder()
|
||||
.setClientId("TheRegistrar")
|
||||
.setEventTime(clock.nowUtc())
|
||||
.setMsg("Test poll message")
|
||||
.setParent(historyEntry)
|
||||
.build());
|
||||
Key<PollMessage> key = Key.<PollMessage>create(pollMessage);
|
||||
assertThat(converter.convert(key)).isEqualTo("1-2-FOOBAR-4-5");
|
||||
assertThat(converter.reverse().convert("1-2-FOOBAR-4-5")).isEqualTo(key);
|
||||
PollMessage.OneTime pollMessage =
|
||||
persistResource(
|
||||
new PollMessage.OneTime.Builder()
|
||||
.setClientId("TheRegistrar")
|
||||
.setEventTime(clock.nowUtc())
|
||||
.setMsg("Test poll message")
|
||||
.setParent(historyEntry)
|
||||
.build());
|
||||
assertThat(makePollMessageExternalId(pollMessage)).isEqualTo("1-2-FOOBAR-4-5-2007");
|
||||
assertThat(parsePollMessageExternalId("1-2-FOOBAR-4-5-2007"))
|
||||
.isEqualTo(Key.create(pollMessage));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_contact() {
|
||||
historyEntry =
|
||||
persistResource(historyEntry.asBuilder().setParent(persistActiveContact("tim")).build());
|
||||
PollMessage.OneTime pollMessage = persistResource(
|
||||
new PollMessage.OneTime.Builder()
|
||||
.setClientId("TheRegistrar")
|
||||
.setEventTime(clock.nowUtc())
|
||||
.setMsg("Test poll message")
|
||||
.setParent(historyEntry)
|
||||
.build());
|
||||
Key<PollMessage> key = Key.<PollMessage>create(pollMessage);
|
||||
assertThat(converter.convert(key)).isEqualTo("2-5-ROID-4-6");
|
||||
assertThat(converter.reverse().convert("2-5-ROID-4-6")).isEqualTo(key);
|
||||
PollMessage.OneTime pollMessage =
|
||||
persistResource(
|
||||
new PollMessage.OneTime.Builder()
|
||||
.setClientId("TheRegistrar")
|
||||
.setEventTime(clock.nowUtc())
|
||||
.setMsg("Test poll message")
|
||||
.setParent(historyEntry)
|
||||
.build());
|
||||
assertThat(makePollMessageExternalId(pollMessage)).isEqualTo("2-5-ROID-4-6-2007");
|
||||
assertThat(parsePollMessageExternalId("2-5-ROID-4-6-2007")).isEqualTo(Key.create(pollMessage));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_host() {
|
||||
historyEntry =
|
||||
persistResource(historyEntry.asBuilder().setParent(persistActiveHost("time.zyx")).build());
|
||||
PollMessage.OneTime pollMessage = persistResource(
|
||||
new PollMessage.OneTime.Builder()
|
||||
.setClientId("TheRegistrar")
|
||||
.setEventTime(clock.nowUtc())
|
||||
.setMsg("Test poll message")
|
||||
.setParent(historyEntry)
|
||||
.build());
|
||||
Key<PollMessage> key = Key.<PollMessage>create(pollMessage);
|
||||
assertThat(converter.convert(key)).isEqualTo("3-5-ROID-4-6");
|
||||
assertThat(converter.reverse().convert("3-5-ROID-4-6")).isEqualTo(key);
|
||||
PollMessage.OneTime pollMessage =
|
||||
persistResource(
|
||||
new PollMessage.OneTime.Builder()
|
||||
.setClientId("TheRegistrar")
|
||||
.setEventTime(clock.nowUtc())
|
||||
.setMsg("Test poll message")
|
||||
.setParent(historyEntry)
|
||||
.build());
|
||||
assertThat(makePollMessageExternalId(pollMessage)).isEqualTo("3-5-ROID-4-6-2007");
|
||||
assertThat(parsePollMessageExternalId("3-5-ROID-4-6-2007")).isEqualTo(Key.create(pollMessage));
|
||||
}
|
||||
|
||||
@Test
|
||||
// TODO(b/68953444): Remove leniency when backwards compatibility with missing field is no longer
|
||||
// required.
|
||||
public void testSuccess_stillParsesWithMissingYearField() {
|
||||
PollMessage.OneTime pollMessage =
|
||||
persistResource(
|
||||
new PollMessage.OneTime.Builder()
|
||||
.setClientId("TheRegistrar")
|
||||
.setEventTime(clock.nowUtc())
|
||||
.setMsg("Test poll message")
|
||||
.setParent(historyEntry)
|
||||
.build());
|
||||
assertThat(makePollMessageExternalId(pollMessage)).isEqualTo("1-2-FOOBAR-4-5-2007");
|
||||
assertThat(parsePollMessageExternalId("1-2-FOOBAR-4-5")).isEqualTo(Key.create(pollMessage));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -128,19 +146,30 @@ public class PollMessageExternalKeyConverterTest {
|
|||
// Populate the testdata correctly as for 1-2-FOOBAR-4-5 so we know that the only thing that
|
||||
// is wrong here is the EppResourceTypeId.
|
||||
testSuccess_domain();
|
||||
thrown.expect(PollMessageExternalKeyParseException.class);
|
||||
converter.reverse().convert("4-2-FOOBAR-4-5");
|
||||
assertThrows(
|
||||
PollMessageExternalKeyParseException.class,
|
||||
() -> parsePollMessageExternalId("4-2-FOOBAR-4-5-2007"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_tooFewComponentParts() throws Exception {
|
||||
thrown.expect(PollMessageExternalKeyParseException.class);
|
||||
converter.reverse().convert("1-3-EXAMPLE");
|
||||
assertThrows(
|
||||
PollMessageExternalKeyParseException.class,
|
||||
() -> parsePollMessageExternalId("1-3-EXAMPLE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_tooManyComponentParts() throws Exception {
|
||||
assertThrows(
|
||||
PollMessageExternalKeyParseException.class,
|
||||
() -> parsePollMessageExternalId("1-3-EXAMPLE-4-5-2007-2009"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFailure_nonNumericIds() throws Exception {
|
||||
thrown.expect(PollMessageExternalKeyParseException.class);
|
||||
converter.reverse().convert("A-B-FOOBAR-D-E");
|
||||
assertThrows(
|
||||
PollMessageExternalKeyParseException.class,
|
||||
() -> parsePollMessageExternalId("A-B-FOOBAR-D-E-F"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue