mirror of
https://github.com/google/nomulus.git
synced 2025-04-30 12:07:51 +02:00
Fix confusing "now" parameters on persist deleted helper methods
They were taking a DateTime "now", which would seem like it would be the time of when the resource was deleted, but it was actually the time by which the resource was deleted, with the actual deletion time being hardcoded to a day prior. The confusion was evident because a fair number of tests were passing the wrong thing. I renamed the parameter "deletionTime" to make it exactly clear what it's doing and fixed up some callsites where necessary. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=134818032
This commit is contained in:
parent
35d5307706
commit
c517c98d17
23 changed files with 63 additions and 53 deletions
|
@ -165,7 +165,7 @@ public class DnsUpdateWriterTest {
|
|||
|
||||
@Test
|
||||
public void testPublishDomainDelete_removesDnsRecords() throws Exception {
|
||||
persistDeletedDomain("example.tld", clock.nowUtc());
|
||||
persistDeletedDomain("example.tld", clock.nowUtc().minusDays(1));
|
||||
|
||||
writer.publishDomain("example.tld");
|
||||
|
||||
|
@ -210,7 +210,7 @@ public class DnsUpdateWriterTest {
|
|||
|
||||
@Test
|
||||
public void testPublishHostDelete_removesDnsRecords() throws Exception {
|
||||
persistDeletedHost("ns1.example.tld", clock.nowUtc());
|
||||
persistDeletedHost("ns1.example.tld", clock.nowUtc().minusDays(1));
|
||||
persistActiveDomain("example.tld");
|
||||
|
||||
writer.publishHost("ns1.example.tld");
|
||||
|
@ -225,7 +225,7 @@ public class DnsUpdateWriterTest {
|
|||
|
||||
@Test
|
||||
public void testPublishHostDelete_removesGlueRecords() throws Exception {
|
||||
persistDeletedHost("ns1.example.tld", clock.nowUtc());
|
||||
persistDeletedHost("ns1.example.tld", clock.nowUtc().minusDays(1));
|
||||
persistResource(
|
||||
persistActiveDomain("example.tld")
|
||||
.asBuilder()
|
||||
|
|
|
@ -52,7 +52,7 @@ public class ContactCheckFlowTest
|
|||
|
||||
@Test
|
||||
public void testOneExistsButWasDeleted() throws Exception {
|
||||
persistDeletedContact("sh8013", clock.nowUtc());
|
||||
persistDeletedContact("sh8013", clock.nowUtc().minusDays(1));
|
||||
// These ids come from the check xml.
|
||||
doCheckTest(
|
||||
create(true, "sh8013", null),
|
||||
|
|
|
@ -58,7 +58,7 @@ public class ContactCreateFlowTest
|
|||
|
||||
@Test
|
||||
public void testSuccess_existedButWasDeleted() throws Exception {
|
||||
persistDeletedContact(getUniqueIdFromCommand(), clock.nowUtc());
|
||||
persistDeletedContact(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
|
||||
clock.advanceOneMilli();
|
||||
doSuccessfulTest();
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ public class ContactDeleteFlowTest
|
|||
thrown.expect(
|
||||
ResourceDoesNotExistException.class,
|
||||
String.format("(%s)", getUniqueIdFromCommand()));
|
||||
persistDeletedContact(getUniqueIdFromCommand(), clock.nowUtc());
|
||||
persistDeletedContact(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
|
||||
runFlow();
|
||||
}
|
||||
|
||||
|
|
|
@ -161,7 +161,7 @@ public class ContactUpdateFlowTest
|
|||
thrown.expect(
|
||||
ResourceDoesNotExistException.class,
|
||||
String.format("(%s)", getUniqueIdFromCommand()));
|
||||
persistDeletedContact(getUniqueIdFromCommand(), clock.nowUtc());
|
||||
persistDeletedContact(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
|
||||
runFlow();
|
||||
}
|
||||
|
||||
|
|
|
@ -259,7 +259,7 @@ public class DomainAllocateFlowTest
|
|||
@Test
|
||||
public void testSuccess_existedButWasDeleted() throws Exception {
|
||||
setupDomainApplication("tld", TldState.QUIET_PERIOD);
|
||||
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc());
|
||||
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
|
||||
clock.advanceOneMilli();
|
||||
doSuccessfulTest(2);
|
||||
}
|
||||
|
|
|
@ -139,7 +139,7 @@ public class DomainCheckFlowTest
|
|||
|
||||
@Test
|
||||
public void testSuccess_oneExistsButWasDeleted() throws Exception {
|
||||
persistDeletedDomain("example1.tld", clock.nowUtc());
|
||||
persistDeletedDomain("example1.tld", clock.nowUtc().minusDays(1));
|
||||
doCheckTest(
|
||||
create(true, "example1.tld", null),
|
||||
create(true, "example2.tld", null),
|
||||
|
|
|
@ -523,7 +523,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
|||
@Test
|
||||
public void testSuccess_existedButWasDeleted() throws Exception {
|
||||
persistContactsAndHosts();
|
||||
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc());
|
||||
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
|
||||
clock.advanceOneMilli();
|
||||
doSuccessfulTest();
|
||||
}
|
||||
|
|
|
@ -603,7 +603,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
|
|||
thrown.expect(
|
||||
ResourceDoesNotExistException.class,
|
||||
String.format("(%s)", getUniqueIdFromCommand()));
|
||||
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc());
|
||||
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
|
||||
runFlow();
|
||||
}
|
||||
|
||||
|
|
|
@ -390,7 +390,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
|
|||
thrown.expect(
|
||||
ResourceDoesNotExistException.class,
|
||||
String.format("(%s)", getUniqueIdFromCommand()));
|
||||
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc());
|
||||
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
|
||||
runFlow();
|
||||
}
|
||||
|
||||
|
|
|
@ -454,7 +454,7 @@ public class DomainRestoreRequestFlowTest extends
|
|||
@Test
|
||||
public void testFailure_fullyDeleted() throws Exception {
|
||||
thrown.expect(ResourceDoesNotExistException.class);
|
||||
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc());
|
||||
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
|
||||
runFlow();
|
||||
}
|
||||
|
||||
|
|
|
@ -830,7 +830,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
|
|||
ResourceDoesNotExistException.class,
|
||||
String.format("(%s)", getUniqueIdFromCommand()));
|
||||
persistReferencedEntities();
|
||||
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc());
|
||||
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
|
||||
runFlow();
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ public class HostCheckFlowTest extends ResourceCheckFlowTestCase<HostCheckFlow,
|
|||
|
||||
@Test
|
||||
public void testOneExistsButWasDeleted() throws Exception {
|
||||
persistDeletedHost("ns1.example.tld", clock.nowUtc());
|
||||
persistDeletedHost("ns1.example.tld", clock.nowUtc().minusDays(1));
|
||||
// These ids come from the check xml.
|
||||
doCheckTest(
|
||||
create(true, "ns1.example.tld", null),
|
||||
|
|
|
@ -114,14 +114,14 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
|
|||
|
||||
@Test
|
||||
public void testSuccess_externalExistedButWasDeleted() throws Exception {
|
||||
persistDeletedHost(getUniqueIdFromCommand(), clock.nowUtc());
|
||||
persistDeletedHost(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
|
||||
doSuccessfulTest();
|
||||
assertNoDnsTasksEnqueued();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_internalExistedButWasDeleted() throws Exception {
|
||||
persistDeletedHost(getUniqueIdFromCommand(), clock.nowUtc());
|
||||
persistDeletedHost(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
|
||||
doSuccessfulInternalTest("tld");
|
||||
assertThat(ofy().load().key(reloadResourceByForeignKey().getSuperordinateDomain())
|
||||
.now().getFullyQualifiedDomainName())
|
||||
|
|
|
@ -90,7 +90,7 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
|
|||
thrown.expect(
|
||||
ResourceDoesNotExistException.class,
|
||||
String.format("(%s)", getUniqueIdFromCommand()));
|
||||
persistDeletedHost(getUniqueIdFromCommand(), clock.nowUtc());
|
||||
persistDeletedHost(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
|
||||
runFlow();
|
||||
}
|
||||
|
||||
|
|
|
@ -675,7 +675,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
|
|||
|
||||
@Test
|
||||
public void testFailure_existedButWasDeleted() throws Exception {
|
||||
persistDeletedHost(oldHostName(), clock.nowUtc());
|
||||
persistDeletedHost(oldHostName(), clock.nowUtc().minusDays(1));
|
||||
thrown.expect(
|
||||
ResourceDoesNotExistException.class,
|
||||
String.format("(%s)", getUniqueIdFromCommand()));
|
||||
|
|
|
@ -487,7 +487,7 @@ public class RdapDomainSearchActionTest {
|
|||
|
||||
@Test
|
||||
public void testDomainMatchDeletedDomain_notFound() throws Exception {
|
||||
persistDomainAsDeleted(domainCatLol, clock.nowUtc());
|
||||
persistDomainAsDeleted(domainCatLol, clock.nowUtc().minusDays(1));
|
||||
assertThat(generateActualJson(RequestType.NAME, "cat.lol"))
|
||||
.isEqualTo(generateExpectedJson("No domains found", null, null, "rdap_error_404.json"));
|
||||
assertThat(response.getStatus()).isEqualTo(404);
|
||||
|
@ -495,7 +495,7 @@ public class RdapDomainSearchActionTest {
|
|||
|
||||
@Test
|
||||
public void testDomainMatchDeletedDomainWithWildcard_notFound() throws Exception {
|
||||
persistDomainAsDeleted(domainCatLol, clock.nowUtc());
|
||||
persistDomainAsDeleted(domainCatLol, clock.nowUtc().minusDays(1));
|
||||
assertThat(generateActualJson(RequestType.NAME, "cat.lo*"))
|
||||
.isEqualTo(generateExpectedJson("No domains found", null, null, "rdap_error_404.json"));
|
||||
assertThat(response.getStatus()).isEqualTo(404);
|
||||
|
@ -503,8 +503,8 @@ public class RdapDomainSearchActionTest {
|
|||
|
||||
@Test
|
||||
public void testDomainMatchDeletedDomainsWithWildcardAndTld_notFound() throws Exception {
|
||||
persistDomainAsDeleted(domainCatLol, clock.nowUtc());
|
||||
persistDomainAsDeleted(domainCatLol2, clock.nowUtc());
|
||||
persistDomainAsDeleted(domainCatLol, clock.nowUtc().minusDays(1));
|
||||
persistDomainAsDeleted(domainCatLol2, clock.nowUtc().minusDays(1));
|
||||
generateActualJson(RequestType.NAME, "cat*.lol");
|
||||
assertThat(response.getStatus()).isEqualTo(404);
|
||||
}
|
||||
|
@ -673,7 +673,7 @@ public class RdapDomainSearchActionTest {
|
|||
|
||||
@Test
|
||||
public void testNameserverMatchOneDeletedDomain_foundTheOther() throws Exception {
|
||||
persistDomainAsDeleted(domainCatExample, clock.nowUtc());
|
||||
persistDomainAsDeleted(domainCatExample, clock.nowUtc().minusDays(1));
|
||||
assertThat(generateActualJson(RequestType.NS_LDH_NAME, "ns1.cat.lol"))
|
||||
.isEqualTo(
|
||||
generateExpectedJsonForDomain("cat.lol", null, "C-LOL", "rdap_domain.json"));
|
||||
|
@ -682,8 +682,8 @@ public class RdapDomainSearchActionTest {
|
|||
|
||||
@Test
|
||||
public void testNameserverMatchTwoDeletedDomains_notFound() throws Exception {
|
||||
persistDomainAsDeleted(domainCatLol, clock.nowUtc());
|
||||
persistDomainAsDeleted(domainCatExample, clock.nowUtc());
|
||||
persistDomainAsDeleted(domainCatLol, clock.nowUtc().minusDays(1));
|
||||
persistDomainAsDeleted(domainCatExample, clock.nowUtc().minusDays(1));
|
||||
assertThat(generateActualJson(RequestType.NS_LDH_NAME, "ns1.cat.lol"))
|
||||
.isEqualTo(generateExpectedJson("No domains found", null, null, "rdap_error_404.json"));
|
||||
assertThat(response.getStatus()).isEqualTo(404);
|
||||
|
@ -750,7 +750,7 @@ public class RdapDomainSearchActionTest {
|
|||
|
||||
@Test
|
||||
public void testAddressMatchOneDeletedDomain_foundTheOther() throws Exception {
|
||||
persistDomainAsDeleted(domainCatExample, clock.nowUtc());
|
||||
persistDomainAsDeleted(domainCatExample, clock.nowUtc().minusDays(1));
|
||||
assertThat(generateActualJson(RequestType.NS_IP, "1.2.3.4"))
|
||||
.isEqualTo(
|
||||
generateExpectedJsonForDomain("cat.lol", null, "C-LOL", "rdap_domain.json"));
|
||||
|
@ -759,8 +759,8 @@ public class RdapDomainSearchActionTest {
|
|||
|
||||
@Test
|
||||
public void testAddressMatchTwoDeletedDomains_notFound() throws Exception {
|
||||
persistDomainAsDeleted(domainCatLol, clock.nowUtc());
|
||||
persistDomainAsDeleted(domainCatExample, clock.nowUtc());
|
||||
persistDomainAsDeleted(domainCatLol, clock.nowUtc().minusDays(1));
|
||||
persistDomainAsDeleted(domainCatExample, clock.nowUtc().minusDays(1));
|
||||
assertThat(generateActualJson(RequestType.NS_IP, "1.2.3.4"))
|
||||
.isEqualTo(generateExpectedJson("No domains found", null, null, "rdap_error_404.json"));
|
||||
assertThat(response.getStatus()).isEqualTo(404);
|
||||
|
|
|
@ -249,12 +249,10 @@ public class DatastoreHelper {
|
|||
return persistResource(newContactResource(contactId));
|
||||
}
|
||||
|
||||
public static ContactResource persistDeletedContact(String contactId, DateTime now) {
|
||||
/** Persists a contact resource with the given contact id deleted at the specified time. */
|
||||
public static ContactResource persistDeletedContact(String contactId, DateTime deletionTime) {
|
||||
return persistResource(
|
||||
newContactResource(contactId)
|
||||
.asBuilder()
|
||||
.setDeletionTime(now.minusDays(1))
|
||||
.build());
|
||||
newContactResource(contactId).asBuilder().setDeletionTime(deletionTime).build());
|
||||
}
|
||||
|
||||
public static HostResource persistActiveHost(String hostName) {
|
||||
|
@ -271,9 +269,10 @@ public class DatastoreHelper {
|
|||
.build());
|
||||
}
|
||||
|
||||
public static HostResource persistDeletedHost(String hostName, DateTime now) {
|
||||
/** Persists a host resource with the given hostname deleted at the specified time. */
|
||||
public static HostResource persistDeletedHost(String hostName, DateTime deletionTime) {
|
||||
return persistResource(
|
||||
newHostResource(hostName).asBuilder().setDeletionTime(now.minusDays(1)).build());
|
||||
newHostResource(hostName).asBuilder().setDeletionTime(deletionTime).build());
|
||||
}
|
||||
|
||||
public static DomainResource persistActiveDomain(String domainName) {
|
||||
|
@ -289,17 +288,28 @@ public class DatastoreHelper {
|
|||
return persistResource(newDomainApplication(domainName, contact, phase));
|
||||
}
|
||||
|
||||
public static DomainApplication persistDeletedDomainApplication(String domainName, DateTime now) {
|
||||
return persistResource(newDomainApplication(domainName).asBuilder()
|
||||
.setDeletionTime(now.minusDays(1)).build());
|
||||
/**
|
||||
* Persists a domain application resource with the given domain name deleted at the specified
|
||||
* time.
|
||||
*/
|
||||
public static DomainApplication persistDeletedDomainApplication(
|
||||
String domainName, DateTime deletionTime) {
|
||||
return persistResource(
|
||||
newDomainApplication(domainName).asBuilder().setDeletionTime(deletionTime).build());
|
||||
}
|
||||
|
||||
public static DomainResource persistDeletedDomain(String domainName, DateTime now) {
|
||||
return persistDomainAsDeleted(newDomainResource(domainName), now);
|
||||
/** Persists a domain resource with the given domain name deleted at the specified time. */
|
||||
public static DomainResource persistDeletedDomain(String domainName, DateTime deletionTime) {
|
||||
return persistDomainAsDeleted(newDomainResource(domainName), deletionTime);
|
||||
}
|
||||
|
||||
public static DomainResource persistDomainAsDeleted(DomainResource domain, DateTime now) {
|
||||
return persistResource(domain.asBuilder().setDeletionTime(now.minusDays(1)).build());
|
||||
/**
|
||||
* Returns a persisted domain that is the passed-in domain modified to be deleted at the specified
|
||||
* time.
|
||||
*/
|
||||
public static DomainResource persistDomainAsDeleted(
|
||||
DomainResource domain, DateTime deletionTime) {
|
||||
return persistResource(domain.asBuilder().setDeletionTime(deletionTime).build());
|
||||
}
|
||||
|
||||
/** Persists a domain and enqueues a LORDN task of the appropriate type for it. */
|
||||
|
|
|
@ -75,7 +75,7 @@ public class GetApplicationCommandTest extends CommandTestCase<GetApplicationCom
|
|||
|
||||
@Test
|
||||
public void testSuccess_deletedApplication() throws Exception {
|
||||
persistDeletedDomainApplication("example.tld", now);
|
||||
persistDeletedDomainApplication("example.tld", now.minusDays(1));
|
||||
runCommand("2-TLD");
|
||||
assertInStdout("Application '2-TLD' does not exist or is deleted");
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ public class GetContactCommandTest extends CommandTestCase<GetContactCommand> {
|
|||
|
||||
@Test
|
||||
public void testSuccess_deletedContact() throws Exception {
|
||||
persistDeletedContact("sh8013", now);
|
||||
persistDeletedContact("sh8013", now.minusDays(1));
|
||||
runCommand("sh8013");
|
||||
assertInStdout("Contact 'sh8013' does not exist or is deleted");
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ public class GetDomainCommandTest extends CommandTestCase<GetDomainCommand> {
|
|||
|
||||
@Test
|
||||
public void testSuccess_deletedDomain() throws Exception {
|
||||
persistDeletedDomain("example.tld", now);
|
||||
persistDeletedDomain("example.tld", now.minusDays(1));
|
||||
runCommand("example.tld");
|
||||
assertInStdout("Domain 'example.tld' does not exist or is deleted");
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ public class GetHostCommandTest extends CommandTestCase<GetHostCommand> {
|
|||
|
||||
@Test
|
||||
public void testSuccess_deletedHost() throws Exception {
|
||||
persistDeletedHost("ns1.example.tld", now);
|
||||
persistDeletedHost("ns1.example.tld", now.minusDays(1));
|
||||
runCommand("ns1.example.tld");
|
||||
assertInStdout("Host 'ns1.example.tld' does not exist or is deleted");
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
|
|||
|
||||
@Test
|
||||
public void testSuccess_deletedDomain() throws Exception {
|
||||
persistDeletedDomain("example.tld", now);
|
||||
persistDeletedDomain("example.tld", now.minusDays(1));
|
||||
runCommand("agR0ZXN0chULEgpEb21haW5CYXNlIgUyLVRMRAw");
|
||||
assertInStdout("fullyQualifiedDomainName=example.tld");
|
||||
assertInStdout("deletionTime=" + now.minusDays(1));
|
||||
|
@ -124,7 +124,7 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
|
|||
|
||||
@Test
|
||||
public void testSuccess_deletedContact() throws Exception {
|
||||
persistDeletedContact("sh8013", now);
|
||||
persistDeletedContact("sh8013", now.minusDays(1));
|
||||
runCommand("agR0ZXN0chsLEg9Db250YWN0UmVzb3VyY2UiBjItUk9JRAw");
|
||||
assertInStdout("contactId=sh8013");
|
||||
assertInStdout("deletionTime=" + now.minusDays(1));
|
||||
|
@ -170,7 +170,7 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
|
|||
|
||||
@Test
|
||||
public void testSuccess_deletedHost() throws Exception {
|
||||
persistDeletedHost("ns1.example.tld", now);
|
||||
persistDeletedHost("ns1.example.tld", now.minusDays(1));
|
||||
runCommand("agR0ZXN0chgLEgxIb3N0UmVzb3VyY2UiBjItUk9JRAw");
|
||||
assertInStdout("fullyQualifiedHostName=ns1.example.tld");
|
||||
assertInStdout("deletionTime=" + now.minusDays(1));
|
||||
|
|
Loading…
Add table
Reference in a new issue