Use the correct text VKey for HostResource's superordinateDomain (#608)

* Store the superordinateDomain reference as a VKey rather than Key

This is a reference to a Domain object, so we should store it as a VKey
in reference to the Domain table. This should not affect any business
logic, but rather will allow us to set up the SQL tables for
HostResource et al. properly.
This commit is contained in:
gbrodman 2020-06-08 12:21:51 -04:00 committed by GitHub
parent 1081f7572d
commit 38c481d63e
35 changed files with 276 additions and 249 deletions

View file

@ -347,7 +347,7 @@ public class DeleteContactsAndHostsAction implements Runnable {
String resourceClientId = resource.getPersistedCurrentSponsorClientId();
if (resource instanceof HostResource && ((HostResource) resource).isSubordinate()) {
resourceClientId =
ofy().load().key(((HostResource) resource).getSuperordinateDomain()).now()
tm().load(((HostResource) resource).getSuperordinateDomain())
.cloneProjectedAtTime(now)
.getCurrentSponsorClientId();
}
@ -466,10 +466,11 @@ public class DeleteContactsAndHostsAction implements Runnable {
HostResource host = (HostResource) existingResource;
if (host.isSubordinate()) {
dnsQueue.addHostRefreshTask(host.getFullyQualifiedHostName());
ofy().save().entity(
ofy().load().key(host.getSuperordinateDomain()).now().asBuilder()
.removeSubordinateHost(host.getFullyQualifiedHostName())
.build());
tm().saveNewOrUpdate(
tm().load(host.getSuperordinateDomain())
.asBuilder()
.removeSubordinateHost(host.getFullyQualifiedHostName())
.build());
}
} else {
throw new IllegalStateException(

View file

@ -128,7 +128,7 @@ public final class HostCreateFlow implements TransactionalFlow {
.setFullyQualifiedHostName(targetId)
.setInetAddresses(command.getInetAddresses())
.setRepoId(createRepoId(ObjectifyService.allocateId(), roidSuffix))
.setSuperordinateDomain(superordinateDomain.map(Key::create).orElse(null))
.setSuperordinateDomain(superordinateDomain.map(DomainBase::createVKey).orElse(null))
.build();
historyBuilder
.setType(HistoryEntry.Type.HOST_CREATE)

View file

@ -96,8 +96,7 @@ public final class HostDeleteFlow implements TransactionalFlow {
// the client id, needs to be read off of it.
EppResource owningResource =
existingHost.isSubordinate()
? ofy().load().key(existingHost.getSuperordinateDomain()).now()
.cloneProjectedAtTime(now)
? tm().load(existingHost.getSuperordinateDomain()).cloneProjectedAtTime(now)
: existingHost;
verifyResourceOwnership(clientId, owningResource);
}

View file

@ -18,7 +18,7 @@ import static google.registry.flows.FlowUtils.validateClientIsLoggedIn;
import static google.registry.flows.ResourceFlowUtils.loadAndVerifyExistence;
import static google.registry.flows.host.HostFlowUtils.validateHostName;
import static google.registry.model.EppResourceUtils.isLinked;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key;
@ -77,7 +77,7 @@ public final class HostInfoFlow implements Flow {
// there is no superordinate domain, the host's own values for these fields will be correct.
if (host.isSubordinate()) {
DomainBase superordinateDomain =
ofy().load().key(host.getSuperordinateDomain()).now().cloneProjectedAtTime(now);
tm().load(host.getSuperordinateDomain()).cloneProjectedAtTime(now);
hostInfoDataBuilder
.setCurrentSponsorClientId(superordinateDomain.getCurrentSponsorClientId())
.setLastTransferTime(host.computeLastTransferTime(superordinateDomain));

View file

@ -60,6 +60,7 @@ import google.registry.model.host.HostResource;
import google.registry.model.index.ForeignKeyIndex;
import google.registry.model.reporting.HistoryEntry;
import google.registry.model.reporting.IcannReportingTypes.ActivityReportField;
import google.registry.persistence.VKey;
import java.util.Objects;
import java.util.Optional;
import javax.inject.Inject;
@ -136,9 +137,10 @@ public final class HostUpdateFlow implements TransactionalFlow {
boolean isHostRename = suppliedNewHostName != null;
String oldHostName = targetId;
String newHostName = firstNonNull(suppliedNewHostName, oldHostName);
DomainBase oldSuperordinateDomain = existingHost.isSubordinate()
? ofy().load().key(existingHost.getSuperordinateDomain()).now().cloneProjectedAtTime(now)
: null;
DomainBase oldSuperordinateDomain =
existingHost.isSubordinate()
? tm().load(existingHost.getSuperordinateDomain()).cloneProjectedAtTime(now)
: null;
// Note that lookupSuperordinateDomain calls cloneProjectedAtTime on the domain for us.
Optional<DomainBase> newSuperordinateDomain =
lookupSuperordinateDomain(validateHostName(newHostName), now);
@ -153,8 +155,8 @@ public final class HostUpdateFlow implements TransactionalFlow {
AddRemove remove = command.getInnerRemove();
checkSameValuesNotAddedAndRemoved(add.getStatusValues(), remove.getStatusValues());
checkSameValuesNotAddedAndRemoved(add.getInetAddresses(), remove.getInetAddresses());
Key<DomainBase> newSuperordinateDomainKey =
newSuperordinateDomain.map(Key::create).orElse(null);
VKey<DomainBase> newSuperordinateDomainKey =
newSuperordinateDomain.map(DomainBase::createVKey).orElse(null);
// If the superordinateDomain field is changing, set the lastSuperordinateChange to now.
DateTime lastSuperordinateChange =
Objects.equals(newSuperordinateDomainKey, existingHost.getSuperordinateDomain())
@ -280,28 +282,28 @@ public final class HostUpdateFlow implements TransactionalFlow {
if (existingHost.isSubordinate()
&& newHost.isSubordinate()
&& Objects.equals(
existingHost.getSuperordinateDomain(),
newHost.getSuperordinateDomain())) {
ofy().save().entity(
ofy().load().key(existingHost.getSuperordinateDomain()).now().asBuilder()
.removeSubordinateHost(existingHost.getFullyQualifiedHostName())
.addSubordinateHost(newHost.getFullyQualifiedHostName())
.build());
existingHost.getSuperordinateDomain(), newHost.getSuperordinateDomain())) {
tm().saveNewOrUpdate(
tm().load(existingHost.getSuperordinateDomain())
.asBuilder()
.removeSubordinateHost(existingHost.getFullyQualifiedHostName())
.addSubordinateHost(newHost.getFullyQualifiedHostName())
.build());
return;
}
if (existingHost.isSubordinate()) {
ofy().save().entity(
ofy().load().key(existingHost.getSuperordinateDomain()).now()
.asBuilder()
.removeSubordinateHost(existingHost.getFullyQualifiedHostName())
.build());
tm().saveNewOrUpdate(
tm().load(existingHost.getSuperordinateDomain())
.asBuilder()
.removeSubordinateHost(existingHost.getFullyQualifiedHostName())
.build());
}
if (newHost.isSubordinate()) {
ofy().save().entity(
ofy().load().key(newHost.getSuperordinateDomain()).now()
.asBuilder()
.addSubordinateHost(newHost.getFullyQualifiedHostName())
.build());
tm().saveNewOrUpdate(
tm().load(newHost.getSuperordinateDomain())
.asBuilder()
.addSubordinateHost(newHost.getFullyQualifiedHostName())
.build());
}
}

View file

@ -66,6 +66,7 @@ import google.registry.model.registry.Registry;
import google.registry.model.transfer.TransferData;
import google.registry.model.transfer.TransferStatus;
import google.registry.persistence.VKey;
import google.registry.persistence.WithStringVKey;
import google.registry.schema.replay.DatastoreAndSqlEntity;
import google.registry.util.CollectionUtils;
import java.util.HashSet;
@ -106,6 +107,7 @@ import org.joda.time.Interval;
@javax.persistence.Index(columnList = "fullyQualifiedDomainName"),
@javax.persistence.Index(columnList = "tld")
})
@WithStringVKey
@ExternalMessagingName("domain")
public class DomainBase extends EppResource
implements DatastoreAndSqlEntity, ForeignKeyedEppResource, ResourceWithTransferData {

View file

@ -76,7 +76,7 @@ public class HostResource extends EppResource
@Index
@IgnoreSave(IfNull.class)
@DoNotHydrate
Key<DomainBase> superordinateDomain;
VKey<DomainBase> superordinateDomain;
/**
* The time that this resource was last transferred.
@ -98,7 +98,7 @@ public class HostResource extends EppResource
return fullyQualifiedHostName;
}
public Key<DomainBase> getSuperordinateDomain() {
public VKey<DomainBase> getSuperordinateDomain() {
return superordinateDomain;
}
@ -145,18 +145,18 @@ public class HostResource extends EppResource
*
* <p>If the host is not subordinate the domain can be null and we just return last transfer time.
*
* @param superordinateDomain the loaded superordinate domain, which must match the key in
* the {@link #superordinateDomain} field. Passing it as a parameter allows the caller to
* control the degree of consistency used to load it.
* @param superordinateDomain the loaded superordinate domain, which must match the key in the
* {@link #superordinateDomain} field. Passing it as a parameter allows the caller to control
* the degree of consistency used to load it.
*/
public DateTime computeLastTransferTime(@Nullable DomainBase superordinateDomain) {
public DateTime computeLastTransferTime(@Nullable DomainBase superordinateDomain) {
if (!isSubordinate()) {
checkArgument(superordinateDomain == null);
return getLastTransferTime();
}
checkArgument(
superordinateDomain != null
&& Key.create(superordinateDomain).equals(getSuperordinateDomain()));
&& superordinateDomain.createVKey().equals(getSuperordinateDomain()));
DateTime lastSuperordinateChange =
Optional.ofNullable(getLastSuperordinateChange()).orElse(getCreationTime());
DateTime lastTransferOfCurrentSuperordinate =
@ -207,7 +207,7 @@ public class HostResource extends EppResource
difference(getInstance().getInetAddresses(), inetAddresses)));
}
public Builder setSuperordinateDomain(Key<DomainBase> superordinateDomain) {
public Builder setSuperordinateDomain(VKey<DomainBase> superordinateDomain) {
getInstance().superordinateDomain = superordinateDomain;
return this;
}

View file

@ -433,10 +433,7 @@ public class RdapJsonFormatter {
statuses.add(StatusValue.LINKED);
}
if (hostResource.isSubordinate()
&& ofy()
.load()
.key(hostResource.getSuperordinateDomain())
.now()
&& tm().load(hostResource.getSuperordinateDomain())
.cloneProjectedAtTime(getRequestTime())
.getStatusValues()
.contains(StatusValue.PENDING_TRANSFER)) {

View file

@ -17,7 +17,6 @@ package google.registry.rde;
import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.net.InetAddresses;
import com.googlecode.objectify.Key;
import google.registry.model.domain.DomainBase;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.HostResource;
@ -35,9 +34,8 @@ import org.joda.time.DateTime;
final class HostResourceToXjcConverter {
/** Converts a subordinate {@link HostResource} to {@link XjcRdeHostElement}. */
static XjcRdeHostElement convertSubordinate(
HostResource host, DomainBase superordinateDomain) {
checkArgument(Key.create(superordinateDomain).equals(host.getSuperordinateDomain()));
static XjcRdeHostElement convertSubordinate(HostResource host, DomainBase superordinateDomain) {
checkArgument(superordinateDomain.createVKey().equals(host.getSuperordinateDomain()));
return new XjcRdeHostElement(convertSubordinateHost(host, superordinateDomain));
}

View file

@ -18,6 +18,7 @@ import static com.google.common.base.Strings.nullToEmpty;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static google.registry.model.EppResourceUtils.loadAtPointInTime;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import com.google.appengine.tools.mapreduce.Mapper;
import com.google.auto.value.AutoValue;
@ -186,13 +187,16 @@ public final class RdeStagingMapper extends Mapper<EppResource, PendingDeposit,
return result;
} else if (resource instanceof HostResource) {
HostResource host = (HostResource) resource;
result = Optional.of(host.isSubordinate()
? marshaller.marshalSubordinateHost(
host,
// Note that loadAtPointInTime() does cloneProjectedAtTime(watermark) for us.
loadAtPointInTime(
ofy().load().key(host.getSuperordinateDomain()).now(), watermark).now())
: marshaller.marshalExternalHost(host));
result =
Optional.of(
host.isSubordinate()
? marshaller.marshalSubordinateHost(
host,
// Note that loadAtPointInTime() does cloneProjectedAtTime(watermark) for
// us.
loadAtPointInTime(tm().load(host.getSuperordinateDomain()), watermark)
.now())
: marshaller.marshalExternalHost(host));
cache.put(WatermarkModePair.create(watermark, RdeMode.FULL), result);
cache.put(WatermarkModePair.create(watermark, RdeMode.THIN), result);
return result;

View file

@ -16,7 +16,7 @@ package google.registry.whois;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import com.google.common.collect.ImmutableList;
import com.google.common.net.InetAddresses;
@ -49,7 +49,7 @@ final class NameserverWhoisResponse extends WhoisResponseImpl {
HostResource host = hosts.get(i);
String clientId =
host.isSubordinate()
? ofy().load().key(host.getSuperordinateDomain()).now()
? tm().load(host.getSuperordinateDomain())
.cloneProjectedAtTime(getTimestamp())
.getCurrentSponsorClientId()
: host.getPersistedCurrentSponsorClientId();

View file

@ -61,6 +61,7 @@
<!-- Generated converters for VKey -->
<class>google.registry.model.billing.VKeyConverter_BillingEvent</class>
<class>google.registry.model.domain.VKeyConverter_DomainBase</class>
<class>google.registry.model.domain.token.VKeyConverter_AllocationToken</class>
<class>google.registry.model.host.VKeyConverter_HostResource</class>
<class>google.registry.model.contact.VKeyConverter_ContactResource</class>

View file

@ -725,7 +725,7 @@ public class DeleteContactsAndHostsActionTest
persistResource(
persistHostPendingDelete("ns2.example.tld")
.asBuilder()
.setSuperordinateDomain(Key.create(domain))
.setSuperordinateDomain(domain.createVKey())
.build());
enqueuer.enqueueAsyncDelete(
host,

View file

@ -24,7 +24,6 @@ import static google.registry.testing.EppMetricSubject.assertThat;
import static google.registry.testing.HostResourceSubject.assertAboutHosts;
import com.google.common.collect.ImmutableMap;
import com.googlecode.objectify.Key;
import google.registry.model.domain.DomainBase;
import google.registry.model.host.HostResource;
import google.registry.testing.AppEngineRule;
@ -221,7 +220,7 @@ public class EppLifecycleHostTest extends EppTestCase {
loadByForeignKey(DomainBase.class, "example.bar.foo.tld", timeAfterCreates).get();
assertAboutHosts()
.that(exampleBarFooTldHost)
.hasSuperordinateDomain(Key.create(exampleBarFooTldDomain));
.hasSuperordinateDomain(exampleBarFooTldDomain.createVKey());
assertThat(exampleBarFooTldDomain.getSubordinateHosts())
.containsExactly("ns1.example.bar.foo.tld");
@ -231,14 +230,14 @@ public class EppLifecycleHostTest extends EppTestCase {
loadByForeignKey(DomainBase.class, "example.foo.tld", timeAfterCreates).get();
assertAboutHosts()
.that(exampleFooTldHost)
.hasSuperordinateDomain(Key.create(exampleFooTldDomain));
.hasSuperordinateDomain(exampleFooTldDomain.createVKey());
assertThat(exampleFooTldDomain.getSubordinateHosts()).containsExactly("ns1.example.foo.tld");
HostResource exampleTldHost =
loadByForeignKey(HostResource.class, "ns1.example.tld", timeAfterCreates).get();
DomainBase exampleTldDomain =
loadByForeignKey(DomainBase.class, "example.tld", timeAfterCreates).get();
assertAboutHosts().that(exampleTldHost).hasSuperordinateDomain(Key.create(exampleTldDomain));
assertAboutHosts().that(exampleTldHost).hasSuperordinateDomain(exampleTldDomain.createVKey());
assertThat(exampleTldDomain.getSubordinateHosts()).containsExactly("ns1.example.tld");
assertThatLogoutSucceeds();

View file

@ -719,7 +719,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
persistResource(
newHostResource("ns1." + getUniqueIdFromCommand())
.asBuilder()
.setSuperordinateDomain(Key.create(reloadResourceByForeignKey()))
.setSuperordinateDomain(reloadResourceByForeignKey().createVKey())
.setDeletionTime(clock.nowUtc().minusDays(1))
.build());
clock.advanceOneMilli();
@ -767,7 +767,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
persistResource(
newHostResource("ns1." + getUniqueIdFromCommand())
.asBuilder()
.setSuperordinateDomain(Key.create(reloadResourceByForeignKey()))
.setSuperordinateDomain(reloadResourceByForeignKey().createVKey())
.build());
persistResource(
domain.asBuilder().addSubordinateHost(subordinateHost.getFullyQualifiedHostName()).build());

View file

@ -123,14 +123,14 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
.build());
// Set the superordinate domain of ns1.example.com to example.com. In reality, this would have
// happened in the flow that created it, but here we just overwrite it in Datastore.
host1 = persistResource(host1.asBuilder().setSuperordinateDomain(Key.create(domain)).build());
host1 = persistResource(host1.asBuilder().setSuperordinateDomain(domain.createVKey()).build());
// Create a subordinate host that is not delegated to by anyone.
host3 =
persistResource(
new HostResource.Builder()
.setFullyQualifiedHostName("ns2.example.tld")
.setRepoId("3FF-TLD")
.setSuperordinateDomain(Key.create(domain))
.setSuperordinateDomain(domain.createVKey())
.build());
// Add the subordinate host keys to the existing domain.
domain =

View file

@ -29,7 +29,6 @@ import static google.registry.util.DateTimeUtils.END_OF_TIME;
import com.google.common.base.Ascii;
import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key;
import google.registry.flows.Flow;
import google.registry.flows.ResourceFlowTestCase;
import google.registry.model.EppResource;
@ -116,7 +115,7 @@ public class DomainTransferFlowTestCase<F extends Flow, R extends EppResource>
.setPersistedCurrentSponsorClientId("TheRegistrar")
.setCreationClientId("TheRegistrar")
.setCreationTimeForTest(DateTime.parse("1999-04-03T22:00:00.0Z"))
.setSuperordinateDomain(Key.create(domain))
.setSuperordinateDomain(domain.createVKey())
.build());
domain =
persistResource(

View file

@ -389,8 +389,8 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
HostResource existingHost =
loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc()).get();
addedHost = loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc()).get();
assertThat(existingHost.getSuperordinateDomain()).isEqualTo(Key.create(domain));
assertThat(addedHost.getSuperordinateDomain()).isEqualTo(Key.create(domain));
assertThat(existingHost.getSuperordinateDomain()).isEqualTo(domain.createVKey());
assertThat(addedHost.getSuperordinateDomain()).isEqualTo(domain.createVKey());
}
@Test

View file

@ -34,7 +34,6 @@ import static org.junit.Assert.assertThrows;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key;
import google.registry.flows.EppException;
import google.registry.flows.FlowUtils.IpAddressVersionMismatchException;
import google.registry.flows.ResourceFlowTestCase;
@ -119,7 +118,7 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
HostResource host = reloadResourceByForeignKey();
DomainBase superordinateDomain =
loadByForeignKey(DomainBase.class, "example.tld", clock.nowUtc()).get();
assertAboutHosts().that(host).hasSuperordinateDomain(Key.create(superordinateDomain));
assertAboutHosts().that(host).hasSuperordinateDomain(superordinateDomain.createVKey());
assertThat(superordinateDomain.getSubordinateHosts()).containsExactly("ns1.example.tld");
assertDnsTasksEnqueued("ns1.example.tld");
}
@ -148,7 +147,7 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
HostResource host = reloadResourceByForeignKey();
DomainBase superordinateDomain =
loadByForeignKey(DomainBase.class, "example.tld", clock.nowUtc()).get();
assertAboutHosts().that(host).hasSuperordinateDomain(Key.create(superordinateDomain));
assertAboutHosts().that(host).hasSuperordinateDomain(superordinateDomain.createVKey());
assertThat(superordinateDomain.getSubordinateHosts()).containsExactly("ns1.example.tld");
assertDnsTasksEnqueued("ns1.example.tld");
}

View file

@ -29,7 +29,6 @@ import static org.junit.Assert.assertThrows;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key;
import google.registry.flows.EppException;
import google.registry.flows.ResourceFlowTestCase;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
@ -186,7 +185,7 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
newHostResource("ns1.example.tld")
.asBuilder()
.setPersistedCurrentSponsorClientId("NewRegistrar") // Shouldn't hurt.
.setSuperordinateDomain(Key.create(domain))
.setSuperordinateDomain(domain.createVKey())
.build());
clock.advanceOneMilli();
runFlowAssertResponse(loadFile("host_delete_response.xml"));
@ -206,7 +205,7 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
newHostResource("ns1.example.tld")
.asBuilder()
.setPersistedCurrentSponsorClientId("TheRegistrar") // Shouldn't help.
.setSuperordinateDomain(Key.create(domain))
.setSuperordinateDomain(domain.createVKey())
.build());
EppException thrown = assertThrows(ResourceNotOwnedException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
@ -239,7 +238,7 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
newHostResource("ns1.example.tld")
.asBuilder()
.setPersistedCurrentSponsorClientId("TheRegistrar") // Shouldn't hurt.
.setSuperordinateDomain(Key.create(domain))
.setSuperordinateDomain(domain.createVKey())
.build());
clock.advanceOneMilli();
runFlowAssertResponse(loadFile("host_delete_response.xml"));
@ -272,7 +271,7 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
newHostResource("ns1.example.tld")
.asBuilder()
.setPersistedCurrentSponsorClientId("NewRegistrar") // Shouldn't help.
.setSuperordinateDomain(Key.create(domain))
.setSuperordinateDomain(domain.createVKey())
.build());
EppException thrown = assertThrows(ResourceNotOwnedException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();

View file

@ -25,7 +25,6 @@ import static org.junit.Assert.assertThrows;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.net.InetAddresses;
import com.googlecode.objectify.Key;
import google.registry.flows.EppException;
import google.registry.flows.ResourceFlowTestCase;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
@ -118,7 +117,7 @@ public class HostInfoFlowTest extends ResourceFlowTestCase<HostInfoFlow, HostRes
persistHostResource()
.asBuilder()
.setRepoId("CEEF-FOOBAR")
.setSuperordinateDomain(Key.create(domain))
.setSuperordinateDomain(domain.createVKey())
.setLastSuperordinateChange(lastSuperordinateChange)
.build());
assertTransactionalFlow(false);

View file

@ -220,7 +220,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
.that(reloadResourceByForeignKey())
.hasLastSuperordinateChange(oldHost.getLastSuperordinateChange())
.and()
.hasSuperordinateDomain(Key.create(domain))
.hasSuperordinateDomain(domain.createVKey())
.and()
.hasPersistedCurrentSponsorClientId("TheRegistrar")
.and()
@ -246,7 +246,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
.that(reloadResourceByForeignKey())
.hasLastSuperordinateChange(oldHost.getLastSuperordinateChange())
.and()
.hasSuperordinateDomain(Key.create(domain))
.hasSuperordinateDomain(domain.createVKey())
.and()
.hasPersistedCurrentSponsorClientId("NewRegistrar")
.and()
@ -279,7 +279,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
HostResource renamedHost = doSuccessfulTest();
assertAboutHosts()
.that(renamedHost)
.hasSuperordinateDomain(Key.create(domain))
.hasSuperordinateDomain(domain.createVKey())
.and()
.hasLastSuperordinateChange(oldHost.getLastSuperordinateChange())
.and()
@ -313,7 +313,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
DateTime now = clock.nowUtc();
assertAboutHosts()
.that(renamedHost)
.hasSuperordinateDomain(Key.create(example))
.hasSuperordinateDomain(example.createVKey())
.and()
.hasLastSuperordinateChange(now)
.and()
@ -350,7 +350,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
DateTime now = clock.nowUtc();
assertAboutHosts()
.that(renamedHost)
.hasSuperordinateDomain(Key.create(tldDomain))
.hasSuperordinateDomain(tldDomain.createVKey())
.and()
.hasLastSuperordinateChange(now)
.and()
@ -432,7 +432,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
DateTime now = clock.nowUtc();
assertAboutHosts()
.that(renamedHost)
.hasSuperordinateDomain(Key.create(domain))
.hasSuperordinateDomain(domain.createVKey())
.and()
.hasLastSuperordinateChange(now)
.and()
@ -514,7 +514,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
persistResource(
newHostResource(oldHostName())
.asBuilder()
.setSuperordinateDomain(Key.create(foo))
.setSuperordinateDomain(foo.createVKey())
.setLastTransferTime(null)
.build());
persistResource(foo.asBuilder().setSubordinateHosts(ImmutableSet.of(oldHostName())).build());
@ -551,7 +551,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
persistResource(
newHostResource(oldHostName())
.asBuilder()
.setSuperordinateDomain(Key.create(domain))
.setSuperordinateDomain(domain.createVKey())
.setLastTransferTime(clock.nowUtc().minusDays(20))
.setLastSuperordinateChange(clock.nowUtc().minusDays(3))
.build());
@ -586,7 +586,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
persistResource(
newHostResource(oldHostName())
.asBuilder()
.setSuperordinateDomain(Key.create(foo))
.setSuperordinateDomain(foo.createVKey())
.setLastTransferTime(lastTransferTime)
.setLastSuperordinateChange(clock.nowUtc().minusDays(3))
.build());
@ -617,7 +617,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
persistResource(
newHostResource(oldHostName())
.asBuilder()
.setSuperordinateDomain(Key.create(foo))
.setSuperordinateDomain(foo.createVKey())
.setLastTransferTime(lastTransferTime)
.setLastSuperordinateChange(clock.nowUtc().minusDays(10))
.build());
@ -649,7 +649,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
persistResource(
newHostResource(oldHostName())
.asBuilder()
.setSuperordinateDomain(Key.create(foo))
.setSuperordinateDomain(foo.createVKey())
.setLastTransferTime(null)
.setLastSuperordinateChange(clock.nowUtc().minusDays(3))
.build());
@ -675,7 +675,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
persistResource(
newHostResource(oldHostName())
.asBuilder()
.setSuperordinateDomain(Key.create(domain))
.setSuperordinateDomain(domain.createVKey())
.build());
DateTime lastTransferTime = clock.nowUtc().minusDays(2);
persistResource(
@ -712,7 +712,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
persistResource(
newHostResource(oldHostName())
.asBuilder()
.setSuperordinateDomain(Key.create(domain))
.setSuperordinateDomain(domain.createVKey())
.setLastTransferTime(lastTransferTime)
.setLastSuperordinateChange(clock.nowUtc().minusDays(4))
.build());
@ -747,7 +747,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
persistResource(
newHostResource(oldHostName())
.asBuilder()
.setSuperordinateDomain(Key.create(domain))
.setSuperordinateDomain(domain.createVKey())
.setLastTransferTime(clock.nowUtc().minusDays(12))
.setLastSuperordinateChange(clock.nowUtc().minusDays(4))
.build());
@ -1017,7 +1017,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
newHostResource(oldHostName())
.asBuilder()
.setStatusValues(ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED))
.setSuperordinateDomain(Key.create(persistActiveDomain("example.tld")))
.setSuperordinateDomain(persistActiveDomain("example.tld").createVKey())
.build());
EppException thrown =
assertThrows(ResourceHasClientUpdateProhibitedException.class, this::runFlow);
@ -1031,7 +1031,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
newHostResource(oldHostName())
.asBuilder()
.setStatusValues(ImmutableSet.of(StatusValue.SERVER_UPDATE_PROHIBITED))
.setSuperordinateDomain(Key.create(persistActiveDomain("example.tld")))
.setSuperordinateDomain(persistActiveDomain("example.tld").createVKey())
.build());
ResourceStatusProhibitsOperationException thrown =
assertThrows(ResourceStatusProhibitsOperationException.class, this::runFlow);
@ -1045,7 +1045,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
newHostResource(oldHostName())
.asBuilder()
.setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE))
.setSuperordinateDomain(Key.create(persistActiveDomain("example.tld")))
.setSuperordinateDomain(persistActiveDomain("example.tld").createVKey())
.build());
ResourceStatusProhibitsOperationException thrown =
assertThrows(ResourceStatusProhibitsOperationException.class, this::runFlow);
@ -1105,7 +1105,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
newHostResource("ns1.example.tld")
.asBuilder()
.setPersistedCurrentSponsorClientId("TheRegistrar") // Shouldn't hurt.
.setSuperordinateDomain(Key.create(domain))
.setSuperordinateDomain(domain.createVKey())
.setInetAddresses(ImmutableSet.of(InetAddresses.forString("127.0.0.1")))
.build());
@ -1127,7 +1127,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
newHostResource("ns1.example.tld")
.asBuilder()
.setPersistedCurrentSponsorClientId("NewRegistrar") // Shouldn't help.
.setSuperordinateDomain(Key.create(domain))
.setSuperordinateDomain(domain.createVKey())
.setInetAddresses(ImmutableSet.of(InetAddresses.forString("127.0.0.1")))
.build());
@ -1145,7 +1145,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
newHostResource("ns1.example.tld")
.asBuilder()
.setPersistedCurrentSponsorClientId("TheRegistrar") // Shouldn't hurt.
.setSuperordinateDomain(Key.create(domain))
.setSuperordinateDomain(domain.createVKey())
.setInetAddresses(ImmutableSet.of(InetAddresses.forString("127.0.0.1")))
.build());
@ -1163,7 +1163,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
newHostResource("ns1.example.tld")
.asBuilder()
.setPersistedCurrentSponsorClientId("TheRegistrar") // Shouldn't help.
.setSuperordinateDomain(Key.create(domain))
.setSuperordinateDomain(domain.createVKey())
.setInetAddresses(ImmutableSet.of(InetAddresses.forString("127.0.0.1")))
.build());
@ -1228,7 +1228,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
persistResource(
newHostResource("ns1.example.foo")
.asBuilder()
.setSuperordinateDomain(Key.create(superordinate))
.setSuperordinateDomain(superordinate.createVKey())
.setPersistedCurrentSponsorClientId("NewRegistrar")
.build());

View file

@ -76,7 +76,7 @@ public class DomainBaseTest extends EntityTestCase {
persistResource(
new HostResource.Builder()
.setFullyQualifiedHostName("ns1.example.com")
.setSuperordinateDomain(domainKey)
.setSuperordinateDomain(VKey.createOfy(DomainBase.class, domainKey))
.setRepoId("1-COM")
.build())
.createVKey();

View file

@ -81,7 +81,7 @@ public class HostResourceTest extends EntityTestCase {
.setLastTransferTime(fakeClock.nowUtc())
.setInetAddresses(ImmutableSet.of(InetAddresses.forString("127.0.0.1")))
.setStatusValues(ImmutableSet.of(StatusValue.OK))
.setSuperordinateDomain(Key.create(domain))
.setSuperordinateDomain(domain.createVKey())
.build()));
}
@ -228,7 +228,7 @@ public class HostResourceTest extends EntityTestCase {
.setLastEppUpdateClientId("another registrar")
.setInetAddresses(ImmutableSet.of(InetAddresses.forString("127.0.0.1")))
.setStatusValues(ImmutableSet.of(StatusValue.OK))
.setSuperordinateDomain(Key.create(domain))
.setSuperordinateDomain(domain.createVKey())
.build()));
assertThat(host.computeLastTransferTime(domain)).isNull();
}

View file

@ -37,7 +37,6 @@ import com.google.common.collect.Range;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.googlecode.objectify.Key;
import google.registry.model.contact.ContactResource;
import google.registry.model.domain.DomainBase;
import google.registry.model.domain.Period;
@ -81,14 +80,18 @@ public class RdapDomainSearchActionTest extends RdapSearchActionTestCase<RdapDom
private HostResource hostNs2CatLol;
private HashMap<String, HostResource> hostNameToHostMap = new HashMap<>();
enum RequestType { NONE, NAME, NS_LDH_NAME, NS_IP }
enum RequestType {
NONE,
NAME,
NS_LDH_NAME,
NS_IP
}
private JsonObject generateActualJson(RequestType requestType, String paramValue) {
return generateActualJson(requestType, paramValue, null);
}
private JsonObject generateActualJson(
RequestType requestType, String paramValue, String cursor) {
private JsonObject generateActualJson(RequestType requestType, String paramValue, String cursor) {
action.requestPath = actionPath;
action.requestMethod = POST;
String requestTypeParam = null;
@ -179,9 +182,9 @@ public class RdapDomainSearchActionTest extends RdapSearchActionTestCase<RdapDom
.setCreationClientId("foo")
.build());
persistResource(
hostNs1CatLol.asBuilder().setSuperordinateDomain(Key.create(domainCatLol)).build());
hostNs1CatLol.asBuilder().setSuperordinateDomain(domainCatLol.createVKey()).build());
persistResource(
hostNs2CatLol.asBuilder().setSuperordinateDomain(Key.create(domainCatLol)).build());
hostNs2CatLol.asBuilder().setSuperordinateDomain(domainCatLol.createVKey()).build());
domainCatLol2 =
persistResource(
@ -220,8 +223,9 @@ public class RdapDomainSearchActionTest extends RdapSearchActionTestCase<RdapDom
.build());
// cat.example
createTld("example");
registrar = persistResource(
makeRegistrar("goodregistrar", "St. John Chrysostom", Registrar.State.ACTIVE));
registrar =
persistResource(
makeRegistrar("goodregistrar", "St. John Chrysostom", Registrar.State.ACTIVE));
persistSimpleResources(makeRegistrarContacts(registrar));
domainCatExample =
persistResource(
@ -297,8 +301,7 @@ public class RdapDomainSearchActionTest extends RdapSearchActionTestCase<RdapDom
.build());
// cat.1.test
createTld("1.test");
registrar =
persistResource(makeRegistrar("multiregistrar", "1.test", Registrar.State.ACTIVE));
registrar = persistResource(makeRegistrar("multiregistrar", "1.test", Registrar.State.ACTIVE));
persistSimpleResources(makeRegistrarContacts(registrar));
domainMultipart =
persistResource(
@ -395,10 +398,7 @@ public class RdapDomainSearchActionTest extends RdapSearchActionTestCase<RdapDom
private void deleteCatLol() {
persistResource(
domainCatLol
.asBuilder()
.setDeletionTime(clock.nowUtc().minusMonths(6))
.build());
domainCatLol.asBuilder().setDeletionTime(clock.nowUtc().minusMonths(6)).build());
persistResource(
makeHistoryEntry(
domainCatLol,
@ -416,8 +416,11 @@ public class RdapDomainSearchActionTest extends RdapSearchActionTestCase<RdapDom
for (int i = numHosts; i >= 1; i--) {
String hostName = String.format("ns%d.%s", i, mainDomainName);
subordinateHostnamesBuilder.add(hostName);
HostResource host = makeAndPersistHostResource(
hostName, String.format("5.5.%d.%d", 5 + i / 250, i % 250), clock.nowUtc().minusYears(1));
HostResource host =
makeAndPersistHostResource(
hostName,
String.format("5.5.%d.%d", 5 + i / 250, i % 250),
clock.nowUtc().minusYears(1));
hostKeysBuilder.add(host.createVKey());
}
ImmutableSet<VKey<HostResource>> hostKeys = hostKeysBuilder.build();
@ -533,8 +536,7 @@ public class RdapDomainSearchActionTest extends RdapSearchActionTestCase<RdapDom
assertThat(response.getStatus()).isEqualTo(200);
}
private void runNotFoundTest(
RequestType requestType, String queryString, String errorMessage) {
private void runNotFoundTest(RequestType requestType, String queryString, String errorMessage) {
rememberWildcardType(queryString);
assertThat(generateActualJson(requestType, queryString))
.isEqualTo(generateExpectedJsonError(errorMessage, 404));
@ -654,9 +656,9 @@ public class RdapDomainSearchActionTest extends RdapSearchActionTestCase<RdapDom
@Test
public void testInvalidRequest_rejected() {
assertThat(generateActualJson(RequestType.NONE, null))
.isEqualTo(generateExpectedJsonError(
"You must specify either name=XXXX, nsLdhName=YYYY or nsIp=ZZZZ",
400));
.isEqualTo(
generateExpectedJsonError(
"You must specify either name=XXXX, nsLdhName=YYYY or nsIp=ZZZZ", 400));
assertThat(response.getStatus()).isEqualTo(400);
verifyErrorMetrics(SearchType.NONE, Optional.empty(), 400);
}
@ -1233,7 +1235,7 @@ public class RdapDomainSearchActionTest extends RdapSearchActionTestCase<RdapDom
login("evilregistrar");
runSuccessfulTestWithCatLol(RequestType.NS_LDH_NAME, "ns2.cat.l*", "rdap_domain.json");
verifyMetrics(SearchType.BY_NAMESERVER_NAME, 1, 1);
}
}
@Test
public void testNameserverMatchWithWildcard_found_sameRegistrarRequested() {
@ -1458,24 +1460,21 @@ public class RdapDomainSearchActionTest extends RdapSearchActionTestCase<RdapDom
@Test
public void testNameserverMatchDeletedNameserver_notFound() {
persistResource(
hostNs1CatLol.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
persistResource(hostNs1CatLol.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
runNotFoundTest(RequestType.NS_LDH_NAME, "ns1.cat.lol", "No matching nameservers found");
verifyErrorMetrics(SearchType.BY_NAMESERVER_NAME, Optional.empty(), Optional.of(0L), 404);
}
@Test
public void testNameserverMatchDeletedNameserverWithWildcard_notFound() {
persistResource(
hostNs1CatLol.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
persistResource(hostNs1CatLol.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
runNotFoundTest(RequestType.NS_LDH_NAME, "ns1.cat.l*", "No matching nameservers found");
verifyErrorMetrics(SearchType.BY_NAMESERVER_NAME, Optional.empty(), Optional.of(0L), 404);
}
@Test
public void testNameserverMatchDeletedNameserverWithWildcardAndSuffix_notFound() {
persistResource(
hostNs1CatLol.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
persistResource(hostNs1CatLol.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
runNotFoundTest(RequestType.NS_LDH_NAME, "ns1*.cat.lol", "No matching nameservers found");
verifyErrorMetrics(SearchType.BY_NAMESERVER_NAME, Optional.empty(), Optional.of(0L), 404);
}

View file

@ -31,7 +31,6 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.googlecode.objectify.Key;
import google.registry.model.contact.ContactResource;
import google.registry.model.domain.DomainBase;
import google.registry.model.eppcommon.StatusValue;
@ -159,8 +158,7 @@ public class RdapJsonFormatterTest {
"ns1.dog.みんな", null, null, clock.nowUtc().minusYears(6), "unicoderegistrar")
.asBuilder()
.setSuperordinateDomain(
Key.create(
persistResource(
persistResource(
makeDomainBase(
"dog.みんな",
contactResourceRegistrant,
@ -182,7 +180,8 @@ public class RdapJsonFormatterTest {
.setTransferredRegistrationExpirationTime(
DateTime.parse("2111-10-08T00:44:59Z"))
.build())
.build())))
.build())
.createVKey())
.build());
domainBaseFull =
persistResource(

View file

@ -36,7 +36,6 @@ import com.google.common.collect.ImmutableSet;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.googlecode.objectify.Key;
import google.registry.model.domain.DomainBase;
import google.registry.model.host.HostResource;
import google.registry.model.registrar.Registrar;
@ -111,10 +110,11 @@ public class RdapNameserverSearchActionTest
persistResource(
makeRegistrar("evilregistrar", "Yes Virginia <script>", Registrar.State.ACTIVE));
persistSimpleResources(makeRegistrarContacts(registrar));
hostNs1CatLol = makeAndPersistHostResource(
"ns1.cat.lol", "1.2.3.4", clock.nowUtc().minusYears(1));
hostNs2CatLol = makeAndPersistHostResource(
"ns2.cat.lol", "bad:f00d:cafe::15:beef", clock.nowUtc().minusYears(1));
hostNs1CatLol =
makeAndPersistHostResource("ns1.cat.lol", "1.2.3.4", clock.nowUtc().minusYears(1));
hostNs2CatLol =
makeAndPersistHostResource(
"ns2.cat.lol", "bad:f00d:cafe::15:beef", clock.nowUtc().minusYears(1));
makeAndPersistHostResource(
"ns1.cat2.lol", "1.2.3.3", "bad:f00d:cafe::15:beef", clock.nowUtc().minusYears(1));
makeAndPersistHostResource("ns1.cat.external", null, null, clock.nowUtc().minusYears(1));
@ -132,25 +132,28 @@ public class RdapNameserverSearchActionTest
makeAndPersistHostResource("ns1.cat.1.test", "1.2.3.6", clock.nowUtc().minusYears(1));
// create a domain so that we can use it as a test nameserver search string suffix
domainCatLol = persistResource(
makeDomainBase(
"cat.lol",
persistResource(
makeContactResource("5372808-ERL", "Goblin Market", "lol@cat.lol", registrar)),
persistResource(
makeContactResource("5372808-IRL", "Santa Claus", "BOFH@cat.lol", registrar)),
persistResource(
makeContactResource("5372808-TRL", "The Raven", "bog@cat.lol", registrar)),
hostNs1CatLol,
hostNs2CatLol,
registrar)
.asBuilder()
.setSubordinateHosts(ImmutableSet.of("ns1.cat.lol", "ns2.cat.lol"))
.build());
domainCatLol =
persistResource(
makeDomainBase(
"cat.lol",
persistResource(
makeContactResource(
"5372808-ERL", "Goblin Market", "lol@cat.lol", registrar)),
persistResource(
makeContactResource(
"5372808-IRL", "Santa Claus", "BOFH@cat.lol", registrar)),
persistResource(
makeContactResource("5372808-TRL", "The Raven", "bog@cat.lol", registrar)),
hostNs1CatLol,
hostNs2CatLol,
registrar)
.asBuilder()
.setSubordinateHosts(ImmutableSet.of("ns1.cat.lol", "ns2.cat.lol"))
.build());
persistResource(
hostNs1CatLol.asBuilder().setSuperordinateDomain(Key.create(domainCatLol)).build());
hostNs1CatLol.asBuilder().setSuperordinateDomain(domainCatLol.createVKey()).build());
persistResource(
hostNs2CatLol.asBuilder().setSuperordinateDomain(Key.create(domainCatLol)).build());
hostNs2CatLol.asBuilder().setSuperordinateDomain(domainCatLol.createVKey()).build());
action.ipParam = Optional.empty();
action.nameParam = Optional.empty();
@ -187,10 +190,9 @@ public class RdapNameserverSearchActionTest
hostsBuilder.add(makeHostResource(hostName, "5.5.5.1", "5.5.5.2"));
}
persistResources(hostsBuilder.build());
domainCatLol = persistResource(
domainCatLol.asBuilder()
.setSubordinateHosts(subordinateHostsBuilder.build())
.build());
domainCatLol =
persistResource(
domainCatLol.asBuilder().setSubordinateHosts(subordinateHostsBuilder.build()).build());
}
private void createDeletedHost() {
@ -245,10 +247,7 @@ public class RdapNameserverSearchActionTest
public void testInvalidRequest_rejected() {
action.run();
assertThat(parseJsonObject(response.getPayload()))
.isEqualTo(
generateExpectedJsonError(
"You must specify either name=XXXX or ip=YYYY",
400));
.isEqualTo(generateExpectedJsonError("You must specify either name=XXXX or ip=YYYY", 400));
assertThat(response.getStatus()).isEqualTo(400);
verifyErrorMetrics(Optional.empty(), 400);
}
@ -294,8 +293,7 @@ public class RdapNameserverSearchActionTest
public void testNoCharactersToMatch_rejected() {
assertThat(generateActualJsonWithName("*"))
.isEqualTo(
generateExpectedJsonError(
"Initial search string must be at least 2 characters", 422));
generateExpectedJsonError("Initial search string must be at least 2 characters", 422));
assertThat(response.getStatus()).isEqualTo(422);
verifyErrorMetrics(Optional.empty(), 422);
}
@ -304,8 +302,7 @@ public class RdapNameserverSearchActionTest
public void testFewerThanTwoCharactersToMatch_rejected() {
assertThat(generateActualJsonWithName("a*"))
.isEqualTo(
generateExpectedJsonError(
"Initial search string must be at least 2 characters", 422));
generateExpectedJsonError("Initial search string must be at least 2 characters", 422));
assertThat(response.getStatus()).isEqualTo(422);
verifyErrorMetrics(Optional.empty(), 422);
}
@ -349,7 +346,8 @@ public class RdapNameserverSearchActionTest
@Test
public void testNameMatch_ns2_cat_lol_found() {
assertThat(generateActualJsonWithName("ns2.cat.lol"))
.isEqualTo(generateExpectedJsonForNameserver(
.isEqualTo(
generateExpectedJsonForNameserver(
"ns2.cat.lol",
null,
"4-ROID",
@ -505,7 +503,7 @@ public class RdapNameserverSearchActionTest
public void testNameMatch_nontruncatedResultSet() {
createManyHosts(4);
assertThat(generateActualJsonWithName("nsx*.cat.lol"))
.isEqualTo(loadJsonFile("rdap_nontruncated_hosts.json"));
.isEqualTo(loadJsonFile("rdap_nontruncated_hosts.json"));
assertThat(response.getStatus()).isEqualTo(200);
verifyMetrics(4);
}
@ -535,8 +533,7 @@ public class RdapNameserverSearchActionTest
@Test
public void testNameMatchDeletedHost_foundTheOtherHost() {
persistResource(
hostNs1CatLol.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
persistResource(hostNs1CatLol.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
assertThat(generateActualJsonWithName("ns*.cat.lol"))
.isEqualTo(
generateExpectedJsonForNameserver(
@ -648,8 +645,7 @@ public class RdapNameserverSearchActionTest
* @param expectedNames an immutable list of the host names we expect to retrieve
*/
private void checkCursorNavigation(
boolean byName, String paramValue, ImmutableList<String> expectedNames)
throws Exception {
boolean byName, String paramValue, ImmutableList<String> expectedNames) throws Exception {
String cursor = null;
int expectedNameOffset = 0;
int expectedPageCount =
@ -792,9 +788,9 @@ public class RdapNameserverSearchActionTest
public void testAddressMatch_truncatedResultSet() {
createManyHosts(5);
assertThat(generateActualJsonWithIp("5.5.5.1"))
.isEqualTo(
loadJsonFile(
"rdap_truncated_hosts.json", "QUERY", "ip=5.5.5.1&cursor=MTctUk9JRA%3D%3D"));
.isEqualTo(
loadJsonFile(
"rdap_truncated_hosts.json", "QUERY", "ip=5.5.5.1&cursor=MTctUk9JRA%3D%3D"));
assertThat(response.getStatus()).isEqualTo(200);
verifyMetrics(5, IncompletenessWarningType.TRUNCATED);
}

View file

@ -23,7 +23,6 @@ import static org.junit.Assert.assertThrows;
import com.google.common.collect.ImmutableSet;
import com.google.common.net.InetAddresses;
import com.googlecode.objectify.Key;
import google.registry.model.domain.DomainBase;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.HostResource;
@ -43,8 +42,8 @@ import org.junit.runners.JUnit4;
/**
* Unit tests for {@link HostResourceToXjcConverter}.
*
* <p>This tests the mapping between {@link HostResource} and {@link XjcRdeHost} as well as
* some exceptional conditions.
* <p>This tests the mapping between {@link HostResource} and {@link XjcRdeHost} as well as some
* exceptional conditions.
*/
@RunWith(JUnit4.class)
public class HostResourceToXjcConverterTest {
@ -59,26 +58,29 @@ public class HostResourceToXjcConverterTest {
@Test
public void testConvertSubordinateHost() {
DomainBase domain = newDomainBase("love.foobar").asBuilder()
.setPersistedCurrentSponsorClientId("LeisureDog")
.setLastTransferTime(DateTime.parse("2010-01-01T00:00:00Z"))
.addStatusValue(StatusValue.PENDING_TRANSFER)
.build();
XjcRdeHost bean = HostResourceToXjcConverter.convertSubordinateHost(
new HostResource.Builder()
.setCreationClientId("LawyerCat")
.setCreationTimeForTest(DateTime.parse("1900-01-01T00:00:00Z"))
.setPersistedCurrentSponsorClientId("BusinessCat")
.setFullyQualifiedHostName("ns1.love.foobar")
.setInetAddresses(ImmutableSet.of(InetAddresses.forString("127.0.0.1")))
.setLastTransferTime(DateTime.parse("1910-01-01T00:00:00Z"))
.setLastEppUpdateClientId("CeilingCat")
.setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z"))
.setRepoId("2-roid")
.setStatusValues(ImmutableSet.of(StatusValue.OK))
.setSuperordinateDomain(Key.create(domain))
.build(),
domain);
DomainBase domain =
newDomainBase("love.foobar")
.asBuilder()
.setPersistedCurrentSponsorClientId("LeisureDog")
.setLastTransferTime(DateTime.parse("2010-01-01T00:00:00Z"))
.addStatusValue(StatusValue.PENDING_TRANSFER)
.build();
XjcRdeHost bean =
HostResourceToXjcConverter.convertSubordinateHost(
new HostResource.Builder()
.setCreationClientId("LawyerCat")
.setCreationTimeForTest(DateTime.parse("1900-01-01T00:00:00Z"))
.setPersistedCurrentSponsorClientId("BusinessCat")
.setFullyQualifiedHostName("ns1.love.foobar")
.setInetAddresses(ImmutableSet.of(InetAddresses.forString("127.0.0.1")))
.setLastTransferTime(DateTime.parse("1910-01-01T00:00:00Z"))
.setLastEppUpdateClientId("CeilingCat")
.setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z"))
.setRepoId("2-roid")
.setStatusValues(ImmutableSet.of(StatusValue.OK))
.setSuperordinateDomain(domain.createVKey())
.build(),
domain);
assertThat(bean.getAddrs()).hasSize(1);
assertThat(bean.getAddrs().get(0).getIp().value()).isEqualTo("v4");
@ -119,19 +121,20 @@ public class HostResourceToXjcConverterTest {
@Test
public void testConvertExternalHost() {
XjcRdeHost bean = HostResourceToXjcConverter.convertExternalHost(
new HostResource.Builder()
.setCreationClientId("LawyerCat")
.setCreationTimeForTest(DateTime.parse("1900-01-01T00:00:00Z"))
.setPersistedCurrentSponsorClientId("BusinessCat")
.setFullyQualifiedHostName("ns1.love.lol")
.setInetAddresses(ImmutableSet.of(InetAddresses.forString("127.0.0.1")))
.setLastTransferTime(DateTime.parse("1910-01-01T00:00:00Z"))
.setLastEppUpdateClientId("CeilingCat")
.setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z"))
.setRepoId("2-roid")
.setStatusValues(ImmutableSet.of(StatusValue.OK))
.build());
XjcRdeHost bean =
HostResourceToXjcConverter.convertExternalHost(
new HostResource.Builder()
.setCreationClientId("LawyerCat")
.setCreationTimeForTest(DateTime.parse("1900-01-01T00:00:00Z"))
.setPersistedCurrentSponsorClientId("BusinessCat")
.setFullyQualifiedHostName("ns1.love.lol")
.setInetAddresses(ImmutableSet.of(InetAddresses.forString("127.0.0.1")))
.setLastTransferTime(DateTime.parse("1910-01-01T00:00:00Z"))
.setLastEppUpdateClientId("CeilingCat")
.setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z"))
.setRepoId("2-roid")
.setStatusValues(ImmutableSet.of(StatusValue.OK))
.build());
assertThat(bean.getAddrs()).hasSize(1);
assertThat(bean.getAddrs().get(0).getIp().value()).isEqualTo("v4");
@ -167,19 +170,20 @@ public class HostResourceToXjcConverterTest {
@Test
public void testConvertExternalHost_ipv6() {
XjcRdeHost bean = HostResourceToXjcConverter.convertExternalHost(
new HostResource.Builder()
.setCreationClientId("LawyerCat")
.setCreationTimeForTest(DateTime.parse("1900-01-01T00:00:00Z"))
.setPersistedCurrentSponsorClientId("BusinessCat")
.setFullyQualifiedHostName("ns1.love.lol")
.setInetAddresses(ImmutableSet.of(InetAddresses.forString("cafe::abba")))
.setLastTransferTime(DateTime.parse("1910-01-01T00:00:00Z"))
.setLastEppUpdateClientId("CeilingCat")
.setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z"))
.setRepoId("2-LOL")
.setStatusValues(ImmutableSet.of(StatusValue.OK))
.build());
XjcRdeHost bean =
HostResourceToXjcConverter.convertExternalHost(
new HostResource.Builder()
.setCreationClientId("LawyerCat")
.setCreationTimeForTest(DateTime.parse("1900-01-01T00:00:00Z"))
.setPersistedCurrentSponsorClientId("BusinessCat")
.setFullyQualifiedHostName("ns1.love.lol")
.setInetAddresses(ImmutableSet.of(InetAddresses.forString("cafe::abba")))
.setLastTransferTime(DateTime.parse("1910-01-01T00:00:00Z"))
.setLastEppUpdateClientId("CeilingCat")
.setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z"))
.setRepoId("2-LOL")
.setStatusValues(ImmutableSet.of(StatusValue.OK))
.build());
assertThat(bean.getAddrs()).hasSize(1);
assertThat(bean.getAddrs().get(0).getIp().value()).isEqualTo("v6");
assertThat(bean.getAddrs().get(0).getValue()).isEqualTo("cafe::abba");
@ -208,19 +212,20 @@ public class HostResourceToXjcConverterTest {
@Test
public void testMarshal() throws Exception {
// Bean! Bean! Bean!
XjcRdeHostElement bean = HostResourceToXjcConverter.convertExternal(
new HostResource.Builder()
.setCreationClientId("LawyerCat")
.setCreationTimeForTest(DateTime.parse("1900-01-01T00:00:00Z"))
.setPersistedCurrentSponsorClientId("BusinessCat")
.setFullyQualifiedHostName("ns1.love.lol")
.setInetAddresses(ImmutableSet.of(InetAddresses.forString("cafe::abba")))
.setLastTransferTime(DateTime.parse("1910-01-01T00:00:00Z"))
.setLastEppUpdateClientId("CeilingCat")
.setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z"))
.setRepoId("2-LOL")
.setStatusValues(ImmutableSet.of(StatusValue.OK))
.build());
XjcRdeHostElement bean =
HostResourceToXjcConverter.convertExternal(
new HostResource.Builder()
.setCreationClientId("LawyerCat")
.setCreationTimeForTest(DateTime.parse("1900-01-01T00:00:00Z"))
.setPersistedCurrentSponsorClientId("BusinessCat")
.setFullyQualifiedHostName("ns1.love.lol")
.setInetAddresses(ImmutableSet.of(InetAddresses.forString("cafe::abba")))
.setLastTransferTime(DateTime.parse("1910-01-01T00:00:00Z"))
.setLastEppUpdateClientId("CeilingCat")
.setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z"))
.setRepoId("2-LOL")
.setStatusValues(ImmutableSet.of(StatusValue.OK))
.build());
marshalStrict(bean, new ByteArrayOutputStream(), UTF_8);
}
}

View file

@ -185,7 +185,7 @@ abstract class AbstractEppResourceSubject<
return andChainer();
}
protected <E> And<S> hasValue(E expected, E actual, String name) {
protected <E> And<S> hasValue(@Nullable E expected, @Nullable E actual, String name) {
check(name).that(actual).isEqualTo(expected);
return andChainer();
}

View file

@ -239,7 +239,7 @@ public class DatastoreHelper {
return persistResource(
newHostResource(hostName)
.asBuilder()
.setSuperordinateDomain(Key.create(superordinateDomain))
.setSuperordinateDomain(superordinateDomain.createVKey())
.setInetAddresses(
ImmutableSet.of(InetAddresses.forString("1080:0:0:0:8:800:200C:417A")))
.build());

View file

@ -19,10 +19,11 @@ import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.SimpleSubjectBuilder;
import com.googlecode.objectify.Key;
import google.registry.model.domain.DomainBase;
import google.registry.model.host.HostResource;
import google.registry.persistence.VKey;
import google.registry.testing.TruthChainer.And;
import javax.annotation.Nullable;
import org.joda.time.DateTime;
/** Truth subject for asserting things about {@link HostResource} instances. */
@ -55,7 +56,8 @@ public final class HostResourceSubject
"has lastSuperordinateChange");
}
public And<HostResourceSubject> hasSuperordinateDomain(Key<DomainBase> superordinateDomain) {
public And<HostResourceSubject> hasSuperordinateDomain(
@Nullable VKey<DomainBase> superordinateDomain) {
return hasValue(
superordinateDomain, actual.getSuperordinateDomain(), "has superordinateDomain");
}

View file

@ -288,9 +288,9 @@ class google.registry.model.eppcommon.Trid {
class google.registry.model.host.HostResource {
@Id java.lang.String repoId;
com.google.common.collect.ImmutableSortedMap<org.joda.time.DateTime, com.googlecode.objectify.Key<google.registry.model.ofy.CommitLogManifest>> revisions;
com.googlecode.objectify.Key<google.registry.model.domain.DomainBase> superordinateDomain;
google.registry.model.CreateAutoTimestamp creationTime;
google.registry.model.UpdateAutoTimestamp updateTimestamp;
google.registry.persistence.VKey<google.registry.model.domain.DomainBase> superordinateDomain;
java.lang.String creationClientId;
java.lang.String currentSponsorClientId;
java.lang.String fullyQualifiedHostName;

View file

@ -0,0 +1,19 @@
-- Copyright 2020 The Nomulus Authors. All Rights Reserved.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
ALTER TABLE "HostResource" ALTER COLUMN superordinate_domain TYPE text;
ALTER TABLE IF EXISTS "HostResource"
ADD CONSTRAINT fk_host_resource_superordinate_domain
FOREIGN KEY (superordinate_domain) REFERENCES "Domain"(repo_id);

View file

@ -195,7 +195,7 @@
fully_qualified_host_name text,
last_superordinate_change timestamptz,
last_transfer_time timestamptz,
superordinate_domain bytea,
superordinate_domain text,
primary key (repo_id)
);

View file

@ -316,7 +316,7 @@ CREATE TABLE public."HostResource" (
fully_qualified_host_name text,
last_superordinate_change timestamp with time zone,
last_transfer_time timestamp with time zone,
superordinate_domain bytea
superordinate_domain text
);
@ -1167,6 +1167,14 @@ ALTER TABLE ONLY public."DomainHost"
ADD CONSTRAINT fk_domainhost_host_valid FOREIGN KEY (ns_hosts) REFERENCES public."HostResource"(repo_id);
--
-- Name: HostResource fk_host_resource_superordinate_domain; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public."HostResource"
ADD CONSTRAINT fk_host_resource_superordinate_domain FOREIGN KEY (superordinate_domain) REFERENCES public."Domain"(repo_id);
--
-- Name: PollMessage fk_poll_message_contact_repo_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--