Compare commits

..
Author SHA1 Message Date
gbrodmanandGitHub 0423c7ae22 Fix semantic merge conflict (#781)
Note: the schema change isn't from anything I did, I think, but from an
unrelated semantic merge conflict
2020-08-26 12:53:39 -04:00
gbrodmanandGitHub 266bd43792 Persist *History objects as HistoryEntry objects (#749)
* Persist *History objects as HistoryEntry objects

While Datastore is the primary database, we will store *History objects
as HistoryEntry objects and convert to/from the proper objects in the
Datastore transaction manager. This means that History objects will not
properly store the copy of the EppResource until we move to SQL as
primary, but this is the way the world exists anyway so it's not a
problem.

* Format code and simplify the bulk loading

* Add comments with context
2020-08-26 11:45:09 -04:00
Weimin YuandGitHub df15b38a1e Fix JPA setup in Nomulus tool (#780)
* Fix JPA setup in Nomulus tool

Hibernate unnecessarily scans third-party classes in the Nomulus tool,
hitting a bug and fails to set up.

In this change we properly configured persistence.xml to include the orm mapping file (orm.xml) and disable 
auto detection, and provided a custom (NOOP) scanner
to work around Hibernate scanner bugs.

Also improved on the :core:registryIntegrationTest task to test for
JPA setup as well as dependency-packaging.
2020-08-26 09:51:33 -04:00
Ben McIlwainandGitHub daa8bb6b2c Add --autorenews parameter to nomulus update_domain tool (#772) 2020-08-25 17:24:09 -04:00
gbrodmanandGitHub ea2a6165e5 Fix AllocationTokenTest (#779) 2020-08-24 13:08:45 -04:00
Weimin YuandGitHub c36f0c89c8 Fix missing-driver in HibernateSchemaExporterTest (#777)
* Fix missing-driver in HibernateSchemaExporterTest

HibernateSchemaExporterTest is failing with "Driver not found" error
after Java 11 upgrade. Reason is that ServiceLoader now only checks
modules for services.

Proper fix is to define modules.

This short term fix is to declare the driver class explicitly.
2020-08-24 10:20:19 -04:00
Ben McIlwainandGitHub 8d38086d40 Add check to prevent creating VKeys with incorrectly null parents (#774)
* Add check to prevent creating VKeys with incorrectly null parents

Datastore entities that are not the roots of entity groups are uniquely defined
by an inheritance chain in addition to the id/name, not just by id/name.
2020-08-22 09:13:55 -04:00
Shicong HuangandGitHub bb2f35b673 Use composite primary key for RegistrarContact (#761)
* Use composite primary key for RegistrarPoc

* Increase the serial number for flyway file and resolve comments

* Rebase on HEAD

* Rebase on HEAD
2020-08-21 11:17:36 -04:00
Michael MullerandGitHub 15587f03d6 Fix empty Domain nameserver loads (#769)
* Fix empty Domain nameserver loads

Domains with no nameservers were being loaded from SQL as an empty set instead
of null as they should be.

Discovered this will trying to test updates, so added a test for updates in
the course of it.
2020-08-21 11:11:01 -04:00
gbrodmanandGitHub 5c30ef7086 Add a SQL schema to AllocationToken (#763)
* Add a SQL schema to AllocationToken

* Respond to CR

- rename field in tests
- rename allowed_registrar_ids field
- remove unnecessary db load in GATC

* Add TODO for HistoryEntry vkeys

* Run autoformat

* V48 -> V49
2020-08-20 20:18:34 -04:00
Ben McIlwainandGitHub a28632dbe1 Reduce excessive visibility levels in test classes (#773)
* Reduce excessive visibility levels in test classes
2020-08-20 18:34:59 -04:00
Weimin YuandGitHub 70274da971 Allow schema push in alpha and crash (#771)
* Allow schema push in alpha and crash

This allows unsubmitted changes to be tested in alpha and
crash.

Also updated the README file and reformatted with the internal
mdformat tool.
2020-08-19 00:05:57 -04:00
Lai JiangandGitHub f9e3986a4a Hex dump the ICANN report response content for debugging. (#770)
For example if the content is a byte array of "Hello", the Hex dump will
be "48656C6C6F".
2020-08-18 10:23:28 -04:00
82 changed files with 1878 additions and 633 deletions
+141 -158
View File
@@ -635,131 +635,6 @@ artifacts {
testRuntime testJar
}
/**
* We have to break out the test suites because some of the tests conflict
* with one another, but unfortunately this breaks the "--tests" flag. The
* --tests flag only applies to the task named on the command line (usually
* just "test"), not for all tasks of type "Test".
*
* As a better solution, FilteringTest sets testNameIncludePatterns (the
* internal property that --tests sets) from the value of the "testFilter"
* property, allowing us to filter across all the tests in core without
* explicitly specifying a test task or causing errors because there are no
* matching tests in the main task.
*
* To use it, define "testFilter" to be a comma-separated collection of class
* names (wildcards are allowed):
*
* ./gradlew test -P testFilter=*.FooBar,google.registry.tools.ShellCommandTest
*/
class FilteringTest extends Test {
FilteringTest() {
useJUnitPlatform();
}
private void applyTestFilter() {
if (project.testFilter) {
testNameIncludePatterns = project.testFilter.split(',')
// By default, gradle test tasks will produce a failure if no tests
// match the include/exclude/filter rules. Since test filtering allows us
// to select a set of tests from a particular task, we don't want this
// behavior.
filter.failOnNoMatchingTests = false
}
}
/**
* Set to false if you also want to include TestCase and TestSuite classes.
*
* <p>Must be defined before "test", if at all.
*/
boolean excludeTestCases = true
void setTests(List<String> tests) {
// Common exclude pattern. See README in parent directory for explanation.
if (excludeTestCases) {
exclude "**/*TestCase.*", "**/*TestSuite.*"
}
include tests
applyTestFilter()
}
/**
* Include all of the tests (except Test{Case,TestSuite}). This actually
* doesn't explicitly "include" anything, in which cast the Test class tries
* to include everything that is not explicitly excluded.
*/
void includeAllTests() {
exclude "**/*TestCase.*", "**/*TestSuite.*"
applyTestFilter()
}
}
task fragileTest(type: FilteringTest) {
// Common exclude pattern. See README in parent directory for explanation.
tests = fragileTestPatterns
if (rootProject.findProperty("skipDockerIncompatibleTests") == "true") {
exclude dockerIncompatibleTestPatterns
}
// Run every test class in a freshly started process.
forkEvery 1
doFirst {
new File(screenshotsDir).deleteDir()
}
}
task outcastTest(type: FilteringTest) {
tests = outcastTestPatterns
// Sets the maximum number of test executors that may exist at the same time.
// Note that this number appears to contribute to NoClassDefFoundError
// exceptions on certain machines and distros. The root cause is unclear.
// Try reducing this number if you experience similar problems.
maxParallelForks 3
}
// Whitebox test verifying that RegistryTool can be instantiated. Note the
// use of runtimeClasspath. This test emulates the logic in RegistryCli#run.
// A to-do is added there to refactor.
// TODO(weiminyu): Need a similar test for Registry server.
task registryToolIntegrationTest {
dependsOn compileJava
doLast {
def classLoader =
new URLClassLoader(sourceSets.main.runtimeClasspath.collect {
it.toURI().toURL()
} as URL[])
def commandClasses =
(classLoader.loadClass('google.registry.tools.RegistryTool')
.getDeclaredField('COMMAND_MAP').get(null) as Map).values()
commandClasses.each {
try {
Constructor<?> c = ((Class<?>) it).getDeclaredConstructor()
c.setAccessible(true)
c.newInstance()
} catch (Throwable e) {
throw new RuntimeException("Failed to instantiate ${it}:\n ${e}")
}
}
}
}
// Dedicated test suite for schema-dependent tests.
task sqlIntegrationTest(type: FilteringTest) {
// TestSuite still requires a JUnit 4 runner, which knows how to handle JUnit 5 tests.
// Here we need to override parent's choice of JUnit 5. If changing this, remember to
// change :integration:sqlIntegrationTest too.
useJUnit()
excludeTestCases = false
tests = ['google/registry/schema/integration/SqlIntegrationTestSuite.*']
}
task findGoldenImages(type: JavaExec) {
classpath = sourceSets.test.runtimeClasspath
main = 'google.registry.webdriver.GoldenImageFinder'
@@ -879,39 +754,6 @@ task generateGoldenImages(type: FilteringTest) {
}
generateGoldenImages.finalizedBy(findGoldenImages)
task standardTest(type: FilteringTest) {
includeAllTests()
exclude fragileTestPatterns
exclude outcastTestPatterns
// See SqlIntegrationTestSuite.java
exclude '**/*BeforeSuiteTest.*', '**/*AfterSuiteTest.*'
if (rootProject.findProperty("skipDockerIncompatibleTests") == "true") {
exclude dockerIncompatibleTestPatterns
}
// Run every test class in its own process.
// Uncomment to unblock build while troubleshooting inexplicable test errors.
// This setting makes the build take 35 minutes, without it it takes about 10.
// forkEvery 1
// Sets the maximum number of test executors that may exist at the same time.
// Also, Gradle executes tests in 1 thread and some of our test infrastructures
// depend on that, e.g. DualDatabaseTestInvocationContextProvider injects
// different implementation of TransactionManager into TransactionManagerFactory.
maxParallelForks 5
systemProperty 'test.projectRoot', rootProject.projectRootDir
systemProperty 'test.resourcesDir', resourcesDir
}
test {
// Don't run any tests from this task, all testing gets done in the
// FilteringTest tasks.
exclude "**"
// TODO(weiminyu): Remove dependency on sqlIntegrationTest
}.dependsOn(fragileTest, outcastTest, standardTest, registryToolIntegrationTest, sqlIntegrationTest)
createUberJar('nomulus', 'nomulus', 'google.registry.tools.RegistryTool')
// A jar with classes and resources from main sourceSet, excluding internal
@@ -1046,6 +888,147 @@ task runTestServer(dependsOn: copyJsFilesForTestServer, type: JavaExec) {
classpath = sourceSets.test.runtimeClasspath
}
/**
* We have to break out the test suites because some of the tests conflict
* with one another, but unfortunately this breaks the "--tests" flag. The
* --tests flag only applies to the task named on the command line (usually
* just "test"), not for all tasks of type "Test".
*
* As a better solution, FilteringTest sets testNameIncludePatterns (the
* internal property that --tests sets) from the value of the "testFilter"
* property, allowing us to filter across all the tests in core without
* explicitly specifying a test task or causing errors because there are no
* matching tests in the main task.
*
* To use it, define "testFilter" to be a comma-separated collection of class
* names (wildcards are allowed):
*
* ./gradlew test -P testFilter=*.FooBar,google.registry.tools.ShellCommandTest
*/
class FilteringTest extends Test {
FilteringTest() {
useJUnitPlatform();
}
private void applyTestFilter() {
if (project.testFilter) {
testNameIncludePatterns = project.testFilter.split(',')
// By default, gradle test tasks will produce a failure if no tests
// match the include/exclude/filter rules. Since test filtering allows us
// to select a set of tests from a particular task, we don't want this
// behavior.
filter.failOnNoMatchingTests = false
}
}
/**
* Set to false if you also want to include TestCase and TestSuite classes.
*
* <p>Must be defined before "test", if at all.
*/
boolean excludeTestCases = true
void setTests(List<String> tests) {
// Common exclude pattern. See README in parent directory for explanation.
if (excludeTestCases) {
exclude "**/*TestCase.*", "**/*TestSuite.*"
}
include tests
applyTestFilter()
}
/**
* Include all of the tests (except Test{Case,TestSuite}). This actually
* doesn't explicitly "include" anything, in which cast the Test class tries
* to include everything that is not explicitly excluded.
*/
void includeAllTests() {
exclude "**/*TestCase.*", "**/*TestSuite.*"
applyTestFilter()
}
}
task fragileTest(type: FilteringTest) {
// Common exclude pattern. See README in parent directory for explanation.
tests = fragileTestPatterns
if (rootProject.findProperty("skipDockerIncompatibleTests") == "true") {
exclude dockerIncompatibleTestPatterns
}
// Run every test class in a freshly started process.
forkEvery 1
doFirst {
new File(screenshotsDir).deleteDir()
}
}
task outcastTest(type: FilteringTest) {
tests = outcastTestPatterns
// Sets the maximum number of test executors that may exist at the same time.
// Note that this number appears to contribute to NoClassDefFoundError
// exceptions on certain machines and distros. The root cause is unclear.
// Try reducing this number if you experience similar problems.
maxParallelForks 3
}
// Dedicated test suite for schema-dependent tests.
task sqlIntegrationTest(type: FilteringTest) {
// TestSuite still requires a JUnit 4 runner, which knows how to handle JUnit 5 tests.
// Here we need to override parent's choice of JUnit 5. If changing this, remember to
// change :integration:sqlIntegrationTest too.
useJUnit()
excludeTestCases = false
tests = ['google/registry/schema/integration/SqlIntegrationTestSuite.*']
}
// Verifies that RegistryTool can be instantiated:
// - All dependencies are packaged in nomulus.jar
// - JPA setup succeeds.
task registryToolIntegrationTest(dependsOn: nomulus, type: FilteringTest) {
tests = ['google/registry/tools/RegistryToolTest.*']
testClassesDirs = sourceSets.test.output.classesDirs
classpath = nomulus.outputs.files.plus(configurations.testRuntimeClasspath)
.plus(files(testClassesDirs))
}
task standardTest(type: FilteringTest) {
includeAllTests()
exclude fragileTestPatterns
exclude outcastTestPatterns
// See SqlIntegrationTestSuite.java
exclude '**/*BeforeSuiteTest.*', '**/*AfterSuiteTest.*'
if (rootProject.findProperty("skipDockerIncompatibleTests") == "true") {
exclude dockerIncompatibleTestPatterns
}
// Run every test class in its own process.
// Uncomment to unblock build while troubleshooting inexplicable test errors.
// This setting makes the build take 35 minutes, without it it takes about 10.
// forkEvery 1
// Sets the maximum number of test executors that may exist at the same time.
// Also, Gradle executes tests in 1 thread and some of our test infrastructures
// depend on that, e.g. DualDatabaseTestInvocationContextProvider injects
// different implementation of TransactionManager into TransactionManagerFactory.
maxParallelForks 5
systemProperty 'test.projectRoot', rootProject.projectRootDir
systemProperty 'test.resourcesDir', resourcesDir
}
test {
// Don't run any tests from this task, all testing gets done in the
// FilteringTest tasks.
exclude "**"
// TODO(weiminyu): Remove dependency on sqlIntegrationTest
}.dependsOn(fragileTest, outcastTest, standardTest, registryToolIntegrationTest, sqlIntegrationTest)
project.build.dependsOn devtool
project.build.dependsOn buildToolImage
project.build.dependsOn ':stage'
@@ -370,7 +370,8 @@ public class DomainCreateFlow implements TransactionalFlow {
if (allocationToken.isPresent()
&& TokenType.SINGLE_USE.equals(allocationToken.get().getTokenType())) {
entitiesToSave.add(
allocationTokenFlowUtils.redeemToken(allocationToken.get(), Key.create(historyEntry)));
allocationTokenFlowUtils.redeemToken(
allocationToken.get(), HistoryEntry.createVKey(Key.create(historyEntry))));
}
enqueueTasks(newDomain, hasSignedMarks, hasClaimsNotice);
@@ -68,6 +68,7 @@ import google.registry.model.domain.DomainCommand.Update.Change;
import google.registry.model.domain.fee.FeeUpdateCommandExtension;
import google.registry.model.domain.metadata.MetadataExtension;
import google.registry.model.domain.secdns.SecDnsUpdateExtension;
import google.registry.model.domain.superuser.DomainUpdateSuperuserExtension;
import google.registry.model.eppcommon.AuthInfo;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.eppinput.EppInput;
@@ -152,7 +153,8 @@ public final class DomainUpdateFlow implements TransactionalFlow {
extensionManager.register(
FeeUpdateCommandExtension.class,
MetadataExtension.class,
SecDnsUpdateExtension.class);
SecDnsUpdateExtension.class,
DomainUpdateSuperuserExtension.class);
flowCustomLogic.beforeValidation();
extensionManager.validate();
validateClientIsLoggedIn(clientId);
@@ -251,6 +253,15 @@ public final class DomainUpdateFlow implements TransactionalFlow {
.removeContacts(remove.getContacts())
.setRegistrant(firstNonNull(change.getRegistrant(), domain.getRegistrant()))
.setAuthInfo(firstNonNull(change.getAuthInfo(), domain.getAuthInfo()));
Optional<DomainUpdateSuperuserExtension> superuserExt =
eppInput.getSingleExtension(DomainUpdateSuperuserExtension.class);
if (superuserExt.isPresent()) {
if (superuserExt.get().getAutorenews().isPresent()) {
boolean autorenews = superuserExt.get().getAutorenews().get();
domainBuilder.setAutorenewEndTime(
Optional.ofNullable(autorenews ? null : domain.getRegistrationExpirationTime()));
}
}
return domainBuilder.build();
}
@@ -33,6 +33,7 @@ import google.registry.model.domain.token.AllocationToken.TokenStatus;
import google.registry.model.domain.token.AllocationToken.TokenType;
import google.registry.model.registry.Registry;
import google.registry.model.reporting.HistoryEntry;
import google.registry.persistence.VKey;
import java.util.List;
import java.util.Optional;
import javax.inject.Inject;
@@ -107,7 +108,7 @@ public class AllocationTokenFlowUtils {
/** Redeems a SINGLE_USE {@link AllocationToken}, returning the redeemed copy. */
public AllocationToken redeemToken(
AllocationToken token, Key<HistoryEntry> redemptionHistoryEntry) {
AllocationToken token, VKey<HistoryEntry> redemptionHistoryEntry) {
checkArgument(
TokenType.SINGLE_USE.equals(token.getTokenType()),
"Only SINGLE_USE tokens can be marked as redeemed");
@@ -124,7 +125,8 @@ public class AllocationTokenFlowUtils {
private void validateToken(
InternetDomainName domainName, AllocationToken token, String clientId, DateTime now)
throws EppException {
if (!token.getAllowedClientIds().isEmpty() && !token.getAllowedClientIds().contains(clientId)) {
if (!token.getAllowedRegistrarIds().isEmpty()
&& !token.getAllowedRegistrarIds().contains(clientId)) {
throw new AllocationTokenNotValidForRegistrarException();
}
if (!token.getAllowedTlds().isEmpty()
@@ -19,9 +19,12 @@ import google.registry.model.billing.BillingEvent;
import google.registry.model.common.Cursor;
import google.registry.model.common.EntityGroupRoot;
import google.registry.model.common.GaeUserIdConverter;
import google.registry.model.contact.ContactHistory;
import google.registry.model.contact.ContactResource;
import google.registry.model.domain.DomainBase;
import google.registry.model.domain.DomainHistory;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.host.HostHistory;
import google.registry.model.host.HostResource;
import google.registry.model.index.EppResourceIndex;
import google.registry.model.index.EppResourceIndexBucket;
@@ -68,9 +71,11 @@ public final class EntityClasses {
CommitLogCheckpointRoot.class,
CommitLogManifest.class,
CommitLogMutation.class,
ContactHistory.class,
ContactResource.class,
Cursor.class,
DomainBase.class,
DomainHistory.class,
EntityGroupRoot.class,
EppResourceIndex.class,
EppResourceIndexBucket.class,
@@ -79,6 +84,7 @@ public final class EntityClasses {
ForeignKeyIndex.ForeignKeyHostIndex.class,
GaeUserIdConverter.class,
HistoryEntry.class,
HostHistory.class,
HostResource.class,
KmsSecret.class,
KmsSecretRevision.class,
@@ -15,6 +15,7 @@
package google.registry.model.contact;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.EntitySubclass;
import google.registry.model.EppResource;
import google.registry.model.reporting.HistoryEntry;
import google.registry.persistence.VKey;
@@ -36,6 +37,7 @@ import javax.persistence.Entity;
@javax.persistence.Index(columnList = "historyType"),
@javax.persistence.Index(columnList = "historyModificationTime")
})
@EntitySubclass
public class ContactHistory extends HistoryEntry {
// Store ContactBase instead of ContactResource so we don't pick up its @Id
ContactBase contactBase;
@@ -380,7 +380,7 @@ public class DomainContent extends EppResource
// Hibernate needs this in order to populate nsHosts but no one else should ever use it
@SuppressWarnings("UnusedMethod")
private void setNsHosts(Set<VKey<HostResource>> nsHosts) {
this.nsHosts = nsHosts;
this.nsHosts = forceEmptyToNull(nsHosts);
}
// Hibernate needs this in order to populate gracePeriods but no one else should ever use it
@@ -15,6 +15,7 @@
package google.registry.model.domain;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.EntitySubclass;
import google.registry.model.EppResource;
import google.registry.model.contact.ContactResource;
import google.registry.model.host.HostResource;
@@ -43,6 +44,7 @@ import javax.persistence.JoinTable;
@javax.persistence.Index(columnList = "historyType"),
@javax.persistence.Index(columnList = "historyModificationTime")
})
@EntitySubclass
public class DomainHistory extends HistoryEntry {
// Store DomainContent instead of DomainBase so we don't pick up its @Id
DomainContent domainContent;
@@ -20,6 +20,7 @@ import javax.xml.bind.annotation.XmlRootElement;
/** A superuser extension that may be present on domain delete commands. */
@XmlRootElement(name = "domainDelete")
public class DomainDeleteSuperuserExtension extends SuperuserExtension {
@XmlElement(name = "redemptionGracePeriodDays")
int redemptionGracePeriodDays;
@@ -21,6 +21,7 @@ import javax.xml.bind.annotation.XmlRootElement;
/** A superuser extension that may be present on domain transfer request commands. */
@XmlRootElement(name = "domainTransferRequest")
public class DomainTransferRequestSuperuserExtension extends SuperuserExtension {
// We need to specify the period here because the transfer object's period cannot be set to zero.
@XmlElement(name = "renewalPeriod")
Period renewalPeriod;
@@ -0,0 +1,35 @@
// 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.
package google.registry.model.domain.superuser;
import static com.google.common.base.Strings.isNullOrEmpty;
import java.util.Optional;
import javax.annotation.Nullable;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/** A superuser extension that may be present on domain update commands. */
@XmlRootElement(name = "domainUpdate")
public class DomainUpdateSuperuserExtension extends SuperuserExtension {
@XmlElement(name = "autorenews")
@Nullable
String autorenews;
public Optional<Boolean> getAutorenews() {
return Optional.ofNullable(isNullOrEmpty(autorenews) ? null : Boolean.valueOf(autorenews));
}
}
@@ -49,16 +49,32 @@ import google.registry.model.common.TimedTransitionProperty.TimedTransition;
import google.registry.model.reporting.HistoryEntry;
import google.registry.persistence.VKey;
import google.registry.persistence.WithStringVKey;
import google.registry.schema.replay.DatastoreAndSqlEntity;
import java.util.Optional;
import java.util.Set;
import javax.annotation.Nullable;
import javax.persistence.Column;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Table;
import org.joda.time.DateTime;
/** An entity representing an allocation token. */
@ReportedOn
@Entity
@WithStringVKey
public class AllocationToken extends BackupGroupRoot implements Buildable {
@javax.persistence.Entity
@Table(
indexes = {
@javax.persistence.Index(
columnList = "token",
name = "allocation_token_token_idx",
unique = true),
@javax.persistence.Index(
columnList = "domainName",
name = "allocation_token_domain_name_idx"),
})
public class AllocationToken extends BackupGroupRoot implements Buildable, DatastoreAndSqlEntity {
// Promotions should only move forward, and ENDED / CANCELLED are terminal states.
private static final ImmutableMultimap<TokenStatus, TokenStatus> VALID_TOKEN_STATUS_TRANSITIONS =
@@ -86,19 +102,22 @@ public class AllocationToken extends BackupGroupRoot implements Buildable {
}
/** The allocation token string. */
@Id String token;
@javax.persistence.Id @Id String token;
/** The key of the history entry for which the token was used. Null if not yet used. */
@Nullable @Index Key<HistoryEntry> redemptionHistoryEntry;
@Nullable @Index VKey<HistoryEntry> redemptionHistoryEntry;
/** The fully-qualified domain name that this token is limited to, if any. */
@Nullable @Index String domainName;
/** When this token was created. */
@Column(nullable = false)
CreateAutoTimestamp creationTime = CreateAutoTimestamp.create(null);
/** Allowed registrar client IDs for this token, or null if all registrars are allowed. */
@Nullable Set<String> allowedClientIds;
@Column(name = "allowedRegistrarIds")
@Nullable
Set<String> allowedClientIds;
/** Allowed TLDs for this token, or null if all TLDs are allowed. */
@Nullable Set<String> allowedTlds;
@@ -117,6 +136,7 @@ public class AllocationToken extends BackupGroupRoot implements Buildable {
int discountYears = 1;
/** The type of the token, either single-use or unlimited-use. */
@Enumerated(EnumType.STRING)
TokenType tokenType;
// TODO: Remove onLoad once all allocation tokens are migrated to have a discountYears of 1.
@@ -161,7 +181,7 @@ public class AllocationToken extends BackupGroupRoot implements Buildable {
return token;
}
public Optional<Key<HistoryEntry>> getRedemptionHistoryEntry() {
public Optional<VKey<HistoryEntry>> getRedemptionHistoryEntry() {
return Optional.ofNullable(redemptionHistoryEntry);
}
@@ -177,7 +197,7 @@ public class AllocationToken extends BackupGroupRoot implements Buildable {
return Optional.ofNullable(creationTime.getTimestamp());
}
public ImmutableSet<String> getAllowedClientIds() {
public ImmutableSet<String> getAllowedRegistrarIds() {
return nullToEmptyImmutableCopy(allowedClientIds);
}
@@ -260,7 +280,7 @@ public class AllocationToken extends BackupGroupRoot implements Buildable {
return this;
}
public Builder setRedemptionHistoryEntry(Key<HistoryEntry> redemptionHistoryEntry) {
public Builder setRedemptionHistoryEntry(VKey<HistoryEntry> redemptionHistoryEntry) {
getInstance().redemptionHistoryEntry =
checkArgumentNotNull(redemptionHistoryEntry, "Redemption history entry must not be null");
return this;
@@ -279,8 +299,8 @@ public class AllocationToken extends BackupGroupRoot implements Buildable {
return this;
}
public Builder setAllowedClientIds(Set<String> allowedClientIds) {
getInstance().allowedClientIds = forceEmptyToNull(allowedClientIds);
public Builder setAllowedRegistrarIds(Set<String> allowedRegistrarIds) {
getInstance().allowedClientIds = forceEmptyToNull(allowedRegistrarIds);
return this;
}
@@ -50,6 +50,7 @@ import google.registry.model.domain.secdns.SecDnsCreateExtension;
import google.registry.model.domain.secdns.SecDnsUpdateExtension;
import google.registry.model.domain.superuser.DomainDeleteSuperuserExtension;
import google.registry.model.domain.superuser.DomainTransferRequestSuperuserExtension;
import google.registry.model.domain.superuser.DomainUpdateSuperuserExtension;
import google.registry.model.domain.token.AllocationTokenExtension;
import google.registry.model.eppinput.ResourceCommand.ResourceCheck;
import google.registry.model.eppinput.ResourceCommand.SingleResourceCommand;
@@ -309,53 +310,62 @@ public class EppInput extends ImmutableObject {
@XmlType(propOrder = {"command", "extension", "clTRID"})
public static class CommandWrapper extends ImmutableObject {
@XmlElements({
@XmlElement(name = "check", type = Check.class),
@XmlElement(name = "create", type = Create.class),
@XmlElement(name = "delete", type = Delete.class),
@XmlElement(name = "info", type = Info.class),
@XmlElement(name = "login", type = Login.class),
@XmlElement(name = "logout", type = Logout.class),
@XmlElement(name = "poll", type = Poll.class),
@XmlElement(name = "renew", type = Renew.class),
@XmlElement(name = "transfer", type = Transfer.class),
@XmlElement(name = "update", type = Update.class) })
@XmlElement(name = "check", type = Check.class),
@XmlElement(name = "create", type = Create.class),
@XmlElement(name = "delete", type = Delete.class),
@XmlElement(name = "info", type = Info.class),
@XmlElement(name = "login", type = Login.class),
@XmlElement(name = "logout", type = Logout.class),
@XmlElement(name = "poll", type = Poll.class),
@XmlElement(name = "renew", type = Renew.class),
@XmlElement(name = "transfer", type = Transfer.class),
@XmlElement(name = "update", type = Update.class)
})
InnerCommand command;
/** Zero or more command extensions. */
@XmlElementRefs({
// allocation token extension
@XmlElementRef(type = AllocationTokenExtension.class),
// fee extension version 0.6
@XmlElementRef(type = FeeCheckCommandExtensionV06.class),
@XmlElementRef(type = FeeInfoCommandExtensionV06.class),
@XmlElementRef(type = FeeCreateCommandExtensionV06.class),
@XmlElementRef(type = FeeRenewCommandExtensionV06.class),
@XmlElementRef(type = FeeTransferCommandExtensionV06.class),
@XmlElementRef(type = FeeUpdateCommandExtensionV06.class),
// fee extension version 0.11
@XmlElementRef(type = FeeCheckCommandExtensionV11.class),
@XmlElementRef(type = FeeCreateCommandExtensionV11.class),
@XmlElementRef(type = FeeRenewCommandExtensionV11.class),
@XmlElementRef(type = FeeTransferCommandExtensionV11.class),
@XmlElementRef(type = FeeUpdateCommandExtensionV11.class),
// fee extension version 0.12
@XmlElementRef(type = FeeCheckCommandExtensionV12.class),
@XmlElementRef(type = FeeCreateCommandExtensionV12.class),
@XmlElementRef(type = FeeRenewCommandExtensionV12.class),
@XmlElementRef(type = FeeTransferCommandExtensionV12.class),
@XmlElementRef(type = FeeUpdateCommandExtensionV12.class),
// other extensions
@XmlElementRef(type = LaunchCheckExtension.class),
@XmlElementRef(type = LaunchCreateExtension.class),
@XmlElementRef(type = LaunchDeleteExtension.class),
@XmlElementRef(type = LaunchInfoExtension.class),
@XmlElementRef(type = LaunchUpdateExtension.class),
@XmlElementRef(type = MetadataExtension.class),
@XmlElementRef(type = RgpUpdateExtension.class),
@XmlElementRef(type = SecDnsCreateExtension.class),
@XmlElementRef(type = SecDnsUpdateExtension.class),
@XmlElementRef(type = DomainTransferRequestSuperuserExtension.class),
@XmlElementRef(type = DomainDeleteSuperuserExtension.class) })
// Fee extension version 0.6
@XmlElementRef(type = FeeCheckCommandExtensionV06.class),
@XmlElementRef(type = FeeInfoCommandExtensionV06.class),
@XmlElementRef(type = FeeCreateCommandExtensionV06.class),
@XmlElementRef(type = FeeRenewCommandExtensionV06.class),
@XmlElementRef(type = FeeTransferCommandExtensionV06.class),
@XmlElementRef(type = FeeUpdateCommandExtensionV06.class),
// Fee extension version 0.11
@XmlElementRef(type = FeeCheckCommandExtensionV11.class),
@XmlElementRef(type = FeeCreateCommandExtensionV11.class),
@XmlElementRef(type = FeeRenewCommandExtensionV11.class),
@XmlElementRef(type = FeeTransferCommandExtensionV11.class),
@XmlElementRef(type = FeeUpdateCommandExtensionV11.class),
// Fee extension version 0.12
@XmlElementRef(type = FeeCheckCommandExtensionV12.class),
@XmlElementRef(type = FeeCreateCommandExtensionV12.class),
@XmlElementRef(type = FeeRenewCommandExtensionV12.class),
@XmlElementRef(type = FeeTransferCommandExtensionV12.class),
@XmlElementRef(type = FeeUpdateCommandExtensionV12.class),
// Launch phase extensions
@XmlElementRef(type = LaunchCheckExtension.class),
@XmlElementRef(type = LaunchCreateExtension.class),
@XmlElementRef(type = LaunchDeleteExtension.class),
@XmlElementRef(type = LaunchInfoExtension.class),
@XmlElementRef(type = LaunchUpdateExtension.class),
// Superuser extensions
@XmlElementRef(type = DomainDeleteSuperuserExtension.class),
@XmlElementRef(type = DomainTransferRequestSuperuserExtension.class),
@XmlElementRef(type = DomainUpdateSuperuserExtension.class),
// Other extensions
@XmlElementRef(type = AllocationTokenExtension.class),
@XmlElementRef(type = MetadataExtension.class),
@XmlElementRef(type = RgpUpdateExtension.class),
@XmlElementRef(type = SecDnsCreateExtension.class),
@XmlElementRef(type = SecDnsUpdateExtension.class)
})
@XmlElementWrapper
List<CommandExtension> extension;
@@ -15,6 +15,7 @@
package google.registry.model.host;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.EntitySubclass;
import google.registry.model.EppResource;
import google.registry.model.reporting.HistoryEntry;
import google.registry.persistence.VKey;
@@ -37,6 +38,7 @@ import javax.persistence.Entity;
@javax.persistence.Index(columnList = "historyType"),
@javax.persistence.Index(columnList = "historyModificationTime")
})
@EntitySubclass
public class HostHistory extends HistoryEntry {
// Store HostBase instead of HostResource so we don't pick up its @Id
@@ -24,13 +24,16 @@ import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.googlecode.objectify.Key;
import google.registry.model.contact.ContactHistory;
import google.registry.model.host.HostHistory;
import google.registry.model.reporting.HistoryEntry;
import google.registry.persistence.VKey;
import google.registry.persistence.transaction.TransactionManager;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.StreamSupport;
import javax.annotation.Nullable;
import org.joda.time.DateTime;
/** Datastore implementation of {@link TransactionManager}. */
@@ -99,8 +102,7 @@ public class DatastoreTransactionManager implements TransactionManager {
@Override
public void saveNew(Object entity) {
checkArgumentNotNull(entity, "entity must be specified");
getOfy().save().entity(entity);
saveEntity(entity);
}
@Override
@@ -110,8 +112,7 @@ public class DatastoreTransactionManager implements TransactionManager {
@Override
public void saveNewOrUpdate(Object entity) {
checkArgumentNotNull(entity, "entity must be specified");
getOfy().save().entity(entity);
saveEntity(entity);
}
@Override
@@ -121,8 +122,7 @@ public class DatastoreTransactionManager implements TransactionManager {
@Override
public void update(Object entity) {
checkArgumentNotNull(entity, "entity must be specified");
getOfy().save().entity(entity);
saveEntity(entity);
}
@Override
@@ -137,7 +137,7 @@ public class DatastoreTransactionManager implements TransactionManager {
@Override
public <T> boolean checkExists(VKey<T> key) {
return getOfy().load().key(key.getOfyKey()).now() != null;
return loadNullable(key) != null;
}
// TODO: add tests for these methods. They currently have some degree of test coverage because
@@ -146,12 +146,12 @@ public class DatastoreTransactionManager implements TransactionManager {
// interface tests that are applied to both the datastore and SQL implementations.
@Override
public <T> Optional<T> maybeLoad(VKey<T> key) {
return Optional.ofNullable(getOfy().load().key(key.getOfyKey()).now());
return Optional.ofNullable(loadNullable(key));
}
@Override
public <T> T load(VKey<T> key) {
T result = getOfy().load().key(key.getOfyKey()).now();
T result = loadNullable(key);
if (result == null) {
throw new NoSuchElementException(key.toString());
}
@@ -167,7 +167,10 @@ public class DatastoreTransactionManager implements TransactionManager {
.collect(toImmutableMap(key -> (Key<T>) key.getOfyKey(), Functions.identity()));
return getOfy().load().keys(keyMap.keySet()).entrySet().stream()
.collect(ImmutableMap.toImmutableMap(entry -> keyMap.get(entry.getKey()), Entry::getValue));
.collect(
toImmutableMap(
entry -> keyMap.get(entry.getKey()),
entry -> toChildHistoryEntryIfPossible(entry.getValue())));
}
@Override
@@ -191,4 +194,37 @@ public class DatastoreTransactionManager implements TransactionManager {
.collect(toImmutableList());
getOfy().delete().keys(list).now();
}
/**
* The following three methods exist due to the migration to Cloud SQL.
*
* <p>In Cloud SQL, {@link HistoryEntry} objects are represented instead as {@link DomainHistory},
* {@link ContactHistory}, and {@link HostHistory} objects. During the migration, we do not wish
* to change the Datastore schema so all of these objects are stored in Datastore as HistoryEntry
* objects. They are converted to/from the appropriate classes upon retrieval, and converted to
* HistoryEntry on save. See go/r3.0-history-objects for more details.
*/
private void saveEntity(Object entity) {
checkArgumentNotNull(entity, "entity must be specified");
if (entity instanceof HistoryEntry) {
entity = ((HistoryEntry) entity).asHistoryEntry();
}
getOfy().save().entity(entity);
}
@SuppressWarnings("unchecked")
private <T> T toChildHistoryEntryIfPossible(@Nullable T obj) {
// NB: The Key of the object in question may not necessarily be the resulting class that we
// wish to have. Because all *History classes are @EntitySubclasses, their Keys will have type
// HistoryEntry -- even if you create them based off the *History class.
if (obj != null && HistoryEntry.class.isAssignableFrom(obj.getClass())) {
return (T) ((HistoryEntry) obj).toChildHistoryEntity();
}
return obj;
}
@Nullable
private <T> T loadNullable(VKey<T> key) {
return toChildHistoryEntryIfPossible(getOfy().load().key(key.getOfyKey()).now());
}
}
@@ -73,6 +73,7 @@ import google.registry.model.annotations.ReportedOn;
import google.registry.model.common.EntityGroupRoot;
import google.registry.model.registrar.Registrar.BillingAccountEntry.CurrencyMapper;
import google.registry.model.registry.Registry;
import google.registry.persistence.VKey;
import google.registry.schema.replay.DatastoreAndSqlEntity;
import google.registry.util.CidrAddressBlock;
import java.security.cert.CertificateParsingException;
@@ -703,6 +704,10 @@ public class Registrar extends ImmutableObject
return new Builder(clone(this));
}
public VKey<Registrar> createVKey() {
return VKey.create(Registrar.class, clientIdentifier, Key.create(this));
}
/** A builder for constructing {@link Registrar}, since it is immutable. */
public static class Builder extends Buildable.Builder<Registrar> {
public Builder() {}
@@ -20,6 +20,7 @@ import static com.google.common.base.Strings.isNullOrEmpty;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Sets.difference;
import static com.google.common.io.BaseEncoding.base64;
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.registrar.Registrar.checkValidEmail;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
@@ -35,20 +36,26 @@ import com.google.common.collect.Streams;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Ignore;
import com.googlecode.objectify.annotation.Index;
import com.googlecode.objectify.annotation.OnLoad;
import com.googlecode.objectify.annotation.Parent;
import google.registry.model.Buildable;
import google.registry.model.ImmutableObject;
import google.registry.model.JsonMapBuilder;
import google.registry.model.Jsonifiable;
import google.registry.model.annotations.ReportedOn;
import google.registry.model.registrar.RegistrarContact.RegistrarPocId;
import google.registry.persistence.VKey;
import google.registry.schema.replay.DatastoreAndSqlEntity;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import javax.annotation.Nullable;
import javax.persistence.Column;
import javax.persistence.IdClass;
import javax.persistence.PostLoad;
import javax.persistence.Table;
import javax.persistence.Transient;
@@ -59,16 +66,17 @@ import javax.persistence.Transient;
* <p>IMPORTANT NOTE: Any time that you change, update, or delete RegistrarContact entities, you
* *MUST* also modify the persisted Registrar entity with {@link Registrar#contactsRequireSyncing}
* set to true.
*
* <p>TODO(b/163366543): Rename the class name to RegistrarPoc after database migration
*/
@ReportedOn
@Entity
@javax.persistence.Entity
@javax.persistence.Entity(name = "RegistrarPoc")
@Table(
name = "RegistrarPoc",
indexes = {
@javax.persistence.Index(columnList = "gaeUserId", name = "registrarpoc_gae_user_id_idx")
})
// TODO(shicong): Rename the class name to RegistrarPoc after database migration
@IdClass(RegistrarPocId.class)
public class RegistrarContact extends ImmutableObject
implements DatastoreAndSqlEntity, Jsonifiable {
@@ -113,9 +121,10 @@ public class RegistrarContact extends ImmutableObject
/** The email address of the contact. */
@Id
@javax.persistence.Id
@Column(nullable = false)
String emailAddress;
@Ignore @javax.persistence.Id String registrarId;
/** External email address of this contact used for registry lock confirmations. */
String registryLockEmailAddress;
@@ -342,6 +351,39 @@ public class RegistrarContact extends ImmutableObject
.build();
}
/** Sets Cloud SQL specific fields when the entity is loaded from Datastore. */
@OnLoad
void onLoad() {
registrarId = parent.getName();
}
/** Sets Datastore specific fields when the entity is loaded from Cloud SQL. */
@PostLoad
void postLoad() {
parent = Key.create(getCrossTldKey(), Registrar.class, registrarId);
}
public VKey<RegistrarContact> createVKey() {
return VKey.create(
RegistrarContact.class, new RegistrarPocId(emailAddress, registrarId), Key.create(this));
}
/** Class to represent the composite primary key for {@link RegistrarContact} entity. */
static class RegistrarPocId extends ImmutableObject implements Serializable {
String emailAddress;
String registrarId;
// Hibernate requires this default constructor.
private RegistrarPocId() {}
RegistrarPocId(String emailAddress, String registrarId) {
this.emailAddress = emailAddress;
this.registrarId = registrarId;
}
}
/** A builder for constructing a {@link RegistrarContact}, since it is immutable. */
public static class Builder extends Buildable.Builder<RegistrarContact> {
public Builder() {}
@@ -372,6 +414,7 @@ public class RegistrarContact extends ImmutableObject
!isNullOrEmpty(getInstance().registryLockEmailAddress),
"Registry lock email must not be null if allowing registry lock access");
}
getInstance().registrarId = getInstance().parent.getName();
return cloneEmptyToNull(super.build());
}
@@ -14,8 +14,10 @@
package google.registry.model.reporting;
import static com.googlecode.objectify.Key.getKind;
import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.Entity;
@@ -28,9 +30,16 @@ import google.registry.model.Buildable;
import google.registry.model.EppResource;
import google.registry.model.ImmutableObject;
import google.registry.model.annotations.ReportedOn;
import google.registry.model.contact.ContactHistory;
import google.registry.model.contact.ContactResource;
import google.registry.model.domain.DomainBase;
import google.registry.model.domain.DomainHistory;
import google.registry.model.domain.Period;
import google.registry.model.eppcommon.Trid;
import google.registry.model.host.HostHistory;
import google.registry.model.host.HostResource;
import google.registry.persistence.VKey;
import google.registry.persistence.WithStringVKey;
import java.util.Set;
import javax.annotation.Nullable;
import javax.persistence.AttributeOverride;
@@ -49,6 +58,7 @@ import org.joda.time.DateTime;
@ReportedOn
@Entity
@MappedSuperclass
@WithStringVKey // TODO(b/162229294): This should be resolved during the course of that bug
public class HistoryEntry extends ImmutableObject implements Buildable {
/** Represents the type of history entry. */
@@ -109,7 +119,8 @@ public class HistoryEntry extends ImmutableObject implements Buildable {
@Id
@javax.persistence.Id
@Column(name = "historyRevisionId")
Long id;
@VisibleForTesting
public Long id;
/** The resource this event mutated. */
@Parent @Transient protected Key<? extends EppResource> parent;
@@ -257,6 +268,44 @@ public class HistoryEntry extends ImmutableObject implements Buildable {
return new Builder(clone(this));
}
public HistoryEntry asHistoryEntry() {
return new Builder().copyFrom(this).build();
}
@SuppressWarnings("unchecked")
public HistoryEntry toChildHistoryEntity() {
String parentKind = getParent().getKind();
final HistoryEntry resultEntity;
// can't use a switch statement since we're calling getKind()
if (parentKind.equals(getKind(DomainBase.class))) {
resultEntity =
new DomainHistory.Builder()
.copyFrom(this)
.setDomainRepoId(
VKey.create(DomainBase.class, parent.getName(), (Key<DomainBase>) parent))
.build();
} else if (parentKind.equals(getKind(HostResource.class))) {
resultEntity =
new HostHistory.Builder()
.copyFrom(this)
.setHostRepoId(
VKey.create(HostResource.class, parent.getName(), (Key<HostResource>) parent))
.build();
} else if (parentKind.equals(getKind(ContactResource.class))) {
resultEntity =
new ContactHistory.Builder()
.copyFrom(this)
.setContactRepoId(
VKey.create(
ContactResource.class, parent.getName(), (Key<ContactResource>) parent))
.build();
} else {
throw new IllegalStateException(
String.format("Unknown kind of HistoryEntry parent %s", parentKind));
}
return resultEntity;
}
/** A builder for {@link HistoryEntry} since it is immutable */
public static class Builder<T extends HistoryEntry, B extends Builder<?, ?>>
extends GenericBuilder<T, B> {
@@ -266,17 +315,40 @@ public class HistoryEntry extends ImmutableObject implements Buildable {
super(instance);
}
// Used to fill out the fields in this object from an object which may not be exactly the same
// as the class T, where both classes still subclass HistoryEntry
public B copyFrom(HistoryEntry historyEntry) {
setId(historyEntry.id);
setParent(historyEntry.parent);
setType(historyEntry.type);
setPeriod(historyEntry.period);
setXmlBytes(historyEntry.xmlBytes);
setModificationTime(historyEntry.modificationTime);
setClientId(historyEntry.clientId);
setOtherClientId(historyEntry.otherClientId);
setTrid(historyEntry.trid);
setBySuperuser(historyEntry.bySuperuser);
setReason(historyEntry.reason);
setRequestedByRegistrar(historyEntry.requestedByRegistrar);
setDomainTransactionRecords(nullToEmptyImmutableCopy(historyEntry.domainTransactionRecords));
return thisCastToDerived();
}
@Override
public T build() {
return super.build();
}
public B setId(long id) {
getInstance().id = id;
return thisCastToDerived();
}
public B setParent(EppResource parent) {
getInstance().parent = Key.create(parent);
return thisCastToDerived();
}
// Until we move completely to SQL, override this in subclasses (e.g. HostHistory) to set VKeys
public B setParent(Key<? extends EppResource> parent) {
getInstance().parent = parent;
return thisCastToDerived();
@@ -59,6 +59,9 @@ public class HibernateSchemaExporter {
settings.put(Environment.USER, username);
settings.put(Environment.PASS, password);
settings.put(Environment.HBM2DDL_AUTO, "none");
// Register driver explicitly to work around ServiceLoader change after Java 8.
// Driver self-registration only works if driver is declared in a module.
settings.put(Environment.DRIVER, "org.postgresql.Driver");
settings.put(Environment.SHOW_SQL, "true");
settings.put(
Environment.PHYSICAL_NAMING_STRATEGY, NomulusNamingStrategy.class.getCanonicalName());
@@ -0,0 +1,45 @@
// 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.
package google.registry.persistence;
import com.google.common.collect.ImmutableSet;
import org.hibernate.boot.archive.internal.StandardArchiveDescriptorFactory;
import org.hibernate.boot.archive.scan.internal.ScanResultImpl;
import org.hibernate.boot.archive.scan.internal.StandardScanner;
import org.hibernate.boot.archive.scan.spi.ScanEnvironment;
import org.hibernate.boot.archive.scan.spi.ScanOptions;
import org.hibernate.boot.archive.scan.spi.ScanParameters;
import org.hibernate.boot.archive.scan.spi.ScanResult;
import org.hibernate.boot.archive.scan.spi.Scanner;
/**
* A do-nothing {@link Scanner} for Hibernate that works around bugs in Hibernate's default
* implementation. This is required for the Nomulus tool.
*
* <p>Please refer to <a href="../../../../resources/META-INF/persistence.xml">persistence.xml</a>
* for more information.
*/
public class NoopJpaEntityScanner extends StandardScanner {
public NoopJpaEntityScanner() {
super(StandardArchiveDescriptorFactory.INSTANCE);
}
@Override
public ScanResult scan(
ScanEnvironment environment, ScanOptions options, ScanParameters parameters) {
return new ScanResultImpl(ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of());
}
}
@@ -14,10 +14,12 @@
package google.registry.persistence;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import com.googlecode.objectify.Key;
import google.registry.model.BackupGroupRoot;
import google.registry.model.ImmutableObject;
import google.registry.model.translators.VKeyTranslatorFactory;
import java.io.Serializable;
@@ -75,11 +77,42 @@ public class VKey<T> extends ImmutableObject implements Serializable {
return new VKey<T>(kind, ofyKey, sqlKey);
}
/** Creates a symmetric {@link VKey} in which both sql and ofy keys are {@code id}. */
/**
* Creates a symmetric {@link VKey} in which both sql and ofy keys are {@code id}.
*
* <p>IMPORTANT USAGE NOTE: Datastore entities that are not roots of entity groups (i.e. those
* that do not have a null parent in their Objectify keys) require the full entity group
* inheritance chain to be specified and thus cannot use this create method. You need to use
* {@link #create(Class, Object, Key)} instead and pass in the full, valid parent field in the
* Datastore key.
*/
public static <T> VKey<T> create(Class<T> kind, long id) {
checkArgument(
kind.isAssignableFrom(BackupGroupRoot.class),
"The kind %s is not a BackupGroupRoot and thus needs its entire entity group chain"
+ " specified in a parent",
kind.getCanonicalName());
return new VKey<T>(kind, Key.create(kind, id), id);
}
/**
* Creates a symmetric {@link VKey} in which both sql and ofy keys are {@code name}.
*
* <p>IMPORTANT USAGE NOTE: Datastore entities that are not roots of entity groups (i.e. those
* that do not have a null parent in their Objectify keys) require the full entity group
* inheritance chain to be specified and thus cannot use this create method. You need to use
* {@link #create(Class, Object, Key)} instead and pass in the full, valid parent field in the
* Datastore key.
*/
public static <T> VKey<T> create(Class<T> kind, String name) {
checkArgument(
kind.isAssignableFrom(BackupGroupRoot.class),
"The kind %s is not a BackupGroupRoot and thus needs its entire entity group chain"
+ " specified in a parent",
kind.getCanonicalName());
return new VKey<T>(kind, Key.create(kind, name), name);
}
/** Returns the type of the entity. */
public Class<? extends T> getKind() {
return this.kind;
@@ -0,0 +1,49 @@
// 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.
package google.registry.persistence.converter;
import com.google.common.collect.Maps;
import google.registry.model.common.TimedTransitionProperty;
import google.registry.model.domain.token.AllocationToken.TokenStatus;
import google.registry.model.domain.token.AllocationToken.TokenStatusTransition;
import java.util.Map;
import javax.persistence.Converter;
import org.joda.time.DateTime;
/**
* JPA converter for storing/retrieving {@link TimedTransitionProperty} maps referring to {@link
* TokenStatus}es.
*/
@Converter(autoApply = true)
public class AllocationTokenStatusTransitionConverter
extends TimedTransitionPropertyConverterBase<TokenStatus, TokenStatusTransition> {
@Override
Map.Entry<String, String> convertToDatabaseMapEntry(
Map.Entry<DateTime, TokenStatusTransition> entry) {
return Maps.immutableEntry(entry.getKey().toString(), entry.getValue().getValue().name());
}
@Override
Map.Entry<DateTime, TokenStatus> convertToEntityMapEntry(Map.Entry<String, String> entry) {
return Maps.immutableEntry(
DateTime.parse(entry.getKey()), TokenStatus.valueOf(entry.getValue()));
}
@Override
Class<TokenStatusTransition> getTimedTransitionSubclass() {
return TokenStatusTransition.class;
}
}
@@ -28,6 +28,7 @@ import com.google.api.client.http.HttpTransport;
import com.google.common.base.Ascii;
import com.google.common.base.Splitter;
import com.google.common.flogger.FluentLogger;
import com.google.common.io.BaseEncoding;
import com.google.common.io.ByteStreams;
import google.registry.config.RegistryConfig.Config;
import google.registry.keyring.api.KeyModule.Key;
@@ -93,8 +94,10 @@ public class IcannHttpReporter {
response.getContent().close();
}
logger.atInfo().log(
"Received response code %d with content %s",
response.getStatusCode(), new String(content, UTF_8));
"Received response code %d with content: %s\n\nResponse content in hex: %s",
response.getStatusCode(),
new String(content, UTF_8),
BaseEncoding.base16().encode(content));
XjcIirdeaResult result = parseResult(content);
if (result.getCode().getValue() != 1000) {
success = false;
@@ -182,7 +182,8 @@ class GenerateAllocationTokensCommand implements CommandWithRemoteApi {
new AllocationToken.Builder()
.setToken(t)
.setTokenType(tokenType == null ? SINGLE_USE : tokenType)
.setAllowedClientIds(ImmutableSet.copyOf(nullToEmpty(allowedClientIds)))
.setAllowedRegistrarIds(
ImmutableSet.copyOf(nullToEmpty(allowedClientIds)))
.setAllowedTlds(ImmutableSet.copyOf(nullToEmpty(allowedTlds)));
Optional.ofNullable(discountFraction).ifPresent(token::setDiscountFraction);
Optional.ofNullable(discountPremiums).ifPresent(token::setDiscountPremiums);
@@ -16,6 +16,7 @@ package google.registry.tools;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
@@ -59,7 +60,7 @@ final class GetAllocationTokenCommand implements CommandWithRemoteApi {
System.out.printf("Token %s was not redeemed.\n", token);
} else {
DomainBase domain =
domains.get(loadedToken.getRedemptionHistoryEntry().get().<DomainBase>getParent());
domains.get(loadedToken.getRedemptionHistoryEntry().get().getOfyKey().getParent());
if (domain == null) {
System.out.printf("ERROR: Token %s was redeemed but domain can't be loaded.\n", token);
} else {
@@ -82,7 +83,8 @@ final class GetAllocationTokenCommand implements CommandWithRemoteApi {
.map(AllocationToken::getRedemptionHistoryEntry)
.filter(Optional::isPresent)
.map(Optional::get)
.map(Key::<DomainBase>getParent)
.map(key -> tm().load(key))
.map(he -> (Key<DomainBase>) he.getParent())
.collect(toImmutableList());
ImmutableMap.Builder<Key<DomainBase>, DomainBase> domainsBuilder = new ImmutableMap.Builder<>();
for (List<Key<DomainBase>> keys : Lists.partition(domainKeys, BATCH_SIZE)) {
@@ -112,8 +112,6 @@ final class RegistryCli implements AutoCloseable, CommandRunner {
// Create all command instances. It would be preferrable to do this in the constructor, but
// JCommander mutates the command instances and doesn't reset them so we have to do it for every
// run.
// TODO(weiminyu): extract this into a standalone static method to simplify
// :core:registryToolIntegrationTest
try {
for (Map.Entry<String, ? extends Class<? extends Command>> entry : commands.entrySet()) {
Command command = entry.getValue().getDeclaredConstructor().newInstance();
@@ -131,7 +131,7 @@ final class UpdateAllocationTokensCommand extends UpdateOrDeleteAllocationTokens
private AllocationToken updateToken(AllocationToken original) {
AllocationToken.Builder builder = original.asBuilder();
Optional.ofNullable(allowedClientIds)
.ifPresent(clientIds -> builder.setAllowedClientIds(ImmutableSet.copyOf(clientIds)));
.ifPresent(clientIds -> builder.setAllowedRegistrarIds(ImmutableSet.copyOf(clientIds)));
Optional.ofNullable(allowedTlds)
.ifPresent(tlds -> builder.setAllowedTlds(ImmutableSet.copyOf(tlds)));
Optional.ofNullable(discountFraction).ifPresent(builder::setDiscountFraction);
@@ -17,10 +17,11 @@ package google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.domain.rgp.GracePeriodStatus.AUTO_RENEW;
import static google.registry.model.eppcommon.StatusValue.SERVER_UPDATE_PROHIBITED;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
import static org.joda.time.DateTimeZone.UTC;
import static java.util.function.Predicate.isEqual;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
@@ -31,15 +32,19 @@ import com.google.common.flogger.FluentLogger;
import com.google.template.soy.data.SoyMapData;
import google.registry.model.domain.DesignatedContact;
import google.registry.model.domain.DomainBase;
import google.registry.model.domain.GracePeriodBase;
import google.registry.model.eppcommon.StatusValue;
import google.registry.tools.params.NameserversParameter;
import google.registry.tools.soy.DomainUpdateSoyInfo;
import google.registry.util.Clock;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import javax.annotation.Nullable;
import javax.inject.Inject;
import org.joda.time.DateTime;
/** A command to update a new domain via EPP. */
@@ -48,6 +53,8 @@ final class UpdateDomainCommand extends CreateOrUpdateDomainCommand {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
@Inject Clock clock;
@Parameter(names = "--statuses", description = "Comma-separated list of statuses to set.")
private List<String> statuses = new ArrayList<>();
@@ -123,6 +130,15 @@ final class UpdateDomainCommand extends CreateOrUpdateDomainCommand {
)
boolean clearDsRecords = false;
@Nullable
@Parameter(
names = "--autorenews",
arity = 1,
description =
"Whether the domain autorenews. If false, the domain will automatically be"
+ " deleted at the end of its current registration period.")
Boolean autorenews;
@Override
protected void initMutatingEppToolCommand() {
if (!nameservers.isEmpty()) {
@@ -159,7 +175,18 @@ final class UpdateDomainCommand extends CreateOrUpdateDomainCommand {
clearDsRecords = true;
}
ImmutableSet.Builder<String> autorenewGracePeriodWarningDomains = new ImmutableSet.Builder<>();
DateTime now = clock.nowUtc();
for (String domain : domains) {
Optional<DomainBase> domainOptional = loadByForeignKey(DomainBase.class, domain, now);
checkArgumentPresent(domainOptional, "Domain '%s' does not exist or is deleted", domain);
DomainBase domainBase = domainOptional.get();
checkArgument(
!domainBase.getStatusValues().contains(SERVER_UPDATE_PROHIBITED),
"The domain '%s' has status SERVER_UPDATE_PROHIBITED. Verify that you are allowed "
+ "to make updates, and if so, use the domain_unlock command to enable updates.",
domain);
// Use TreeSets so that the results are always in the same order (this makes testing easier).
Set<String> addAdminsThisDomain = new TreeSet<>(addAdmins);
Set<String> removeAdminsThisDomain = new TreeSet<>(removeAdmins);
@@ -171,16 +198,6 @@ final class UpdateDomainCommand extends CreateOrUpdateDomainCommand {
Set<String> removeStatusesThisDomain = new TreeSet<>(removeStatuses);
if (!nameservers.isEmpty() || !admins.isEmpty() || !techs.isEmpty() || !statuses.isEmpty()) {
DateTime now = DateTime.now(UTC);
Optional<DomainBase> domainOptional =
loadByForeignKey(DomainBase.class, domain, now);
checkArgumentPresent(domainOptional, "Domain '%s' does not exist or is deleted", domain);
DomainBase domainBase = domainOptional.get();
checkArgument(
!domainBase.getStatusValues().contains(SERVER_UPDATE_PROHIBITED),
"The domain '%s' has status SERVER_UPDATE_PROHIBITED. Verify that you are allowed "
+ "to make updates, and if so, use the domain_unlock command to enable updates.",
domain);
if (!nameservers.isEmpty()) {
ImmutableSortedSet<String> existingNameservers = domainBase.loadNameserverHostNames();
populateAddRemoveLists(
@@ -232,33 +249,41 @@ final class UpdateDomainCommand extends CreateOrUpdateDomainCommand {
}
boolean add =
!addNameserversThisDomain.isEmpty()
(!addNameserversThisDomain.isEmpty()
|| !addAdminsThisDomain.isEmpty()
|| !addTechsThisDomain.isEmpty()
|| !addStatusesThisDomain.isEmpty();
|| !addStatusesThisDomain.isEmpty());
boolean remove =
!removeNameserversThisDomain.isEmpty()
(!removeNameserversThisDomain.isEmpty()
|| !removeAdminsThisDomain.isEmpty()
|| !removeTechsThisDomain.isEmpty()
|| !removeStatusesThisDomain.isEmpty();
|| !removeStatusesThisDomain.isEmpty());
boolean change = registrant != null || password != null;
boolean secdns =
!addDsRecords.isEmpty()
boolean change = (registrant != null || password != null);
boolean secDns =
(!addDsRecords.isEmpty()
|| !removeDsRecords.isEmpty()
|| !dsRecords.isEmpty()
|| clearDsRecords;
|| clearDsRecords);
if (!add && !remove && !change && !secdns) {
if (!add && !remove && !change && !secDns && autorenews == null) {
logger.atInfo().log("No changes need to be made to domain %s", domain);
continue;
}
// If autorenew is being turned off and this domain is already in the autorenew grace period,
// then we want to warn the user that they might want to delete it instead.
if (Boolean.FALSE.equals(autorenews)) {
if (domainBase.getGracePeriods().stream()
.map(GracePeriodBase::getType)
.anyMatch(isEqual(AUTO_RENEW))) {
autorenewGracePeriodWarningDomains.add(domain);
}
}
setSoyTemplate(DomainUpdateSoyInfo.getInstance(), DomainUpdateSoyInfo.DOMAINUPDATE);
addSoyRecord(
clientId,
SoyMapData soyMapData =
new SoyMapData(
"domain", domain,
"add", add,
@@ -274,14 +299,27 @@ final class UpdateDomainCommand extends CreateOrUpdateDomainCommand {
"change", change,
"registrant", registrant,
"password", password,
"secdns", secdns,
"secdns", secDns,
"addDsRecords", DsRecord.convertToSoy(addDsRecords),
"removeDsRecords", DsRecord.convertToSoy(removeDsRecords),
"removeAllDsRecords", clearDsRecords));
"removeAllDsRecords", clearDsRecords);
if (autorenews != null) {
soyMapData.put("autorenews", autorenews.toString());
}
addSoyRecord(clientId, soyMapData);
}
ImmutableSet<String> domainsToWarn = autorenewGracePeriodWarningDomains.build();
if (!domainsToWarn.isEmpty()) {
logger.atWarning().log(
"The following domains are in autorenew grace periods. Consider aborting this command"
+ " and running `nomulus delete_domain` instead to terminate autorenewal immediately"
+ " rather than in one year, if desired:\n%s",
String.join(", ", domainsToWarn));
}
}
protected void populateAddRemoveLists(
private void populateAddRemoveLists(
Set<String> targetSet, Set<String> oldSet, Set<String> addSet, Set<String> removeSet) {
addSet.addAll(Sets.difference(targetSet, oldSet));
removeSet.addAll(Sets.difference(oldSet, targetSet));
@@ -42,10 +42,6 @@ public abstract class XjcObject {
XjcXmlTransformer.marshalStrict(this, out, encoding);
}
public void marshalLenient(OutputStream out, Charset encoding) throws XmlException {
XjcXmlTransformer.marshalLenient(this, out, encoding);
}
/**
* Turns object into a formatted XML string <i>by any means necessary</i>.
*
@@ -47,4 +47,12 @@
</all>
</complexType>
<element name="domainUpdate" type="superuser:domainUpdateType" />
<complexType name="domainUpdateType">
<all>
<element name="autorenews" minOccurs="0" type="boolean" />
</all>
</complexType>
</schema>
@@ -11,14 +11,33 @@
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<!--
All JPA entities must be enumerated here. JPA does not support auto detection.
All JPA entity-mapping files and annotated classes must be enumerated
here. Automatic entity detection is not part of the JPA spec. Explicit
declaration makes it easier to migrate to another provider.
Note that Hibernate's auto detection functionality (hibernate.archive.autodection)
does not meet our needs. It only scans archives, not the 'classes' folders. So we
are left with two options:
* Move tests to another (sub)project. This is not a big problem, but feels unnatural.
* Use Hibernate's ServiceRegistry for bootstrapping (not JPA-compliant)
Although Hibernate provides the auto detection functionality (configured by
the hibernate.archive.autodetection property), it relies on a fragile
scanner that can be broken by certain classes. For example, in the uber jar
for the Nomulus tool, a repackaged Guava class ( {@code
com.google.appengine.repackaged.com.google.common.html.LinkDetector})
from appengine-api-1.0-sdk:1.9.81 can break the scanner in
hibernate-core:5.4.17.Final. The large number of third-party classes also
makes JPA setup noticeably slower in the tool.
When auto detection is enabled in Hibernate, we also need a separate
persistence.xml for tests. See <a
href="https://stackoverflow.com/questions/61127082/hibernate-doesnt-find-entities-in-test">
this webpage</a> for an example.
Because of the reasons above, we disable auto detection in Hibernate.
When auto detection is disabled, Hibernate still invokes the scanner which always
goes over the archive that has this file. We need to override the default scanner
with an NOOP one for Nomulus tool.
-->
<mapping-file>META-INF/orm.xml</mapping-file>
<class>google.registry.model.billing.BillingEvent$Cancellation</class>
<class>google.registry.model.billing.BillingEvent$OneTime</class>
<class>google.registry.model.billing.BillingEvent$Recurring</class>
@@ -26,6 +45,7 @@
<class>google.registry.model.contact.ContactResource</class>
<class>google.registry.model.domain.DomainBase</class>
<class>google.registry.model.domain.DomainHistory</class>
<class>google.registry.model.domain.token.AllocationToken</class>
<class>google.registry.model.host.HostHistory</class>
<class>google.registry.model.host.HostResource</class>
<class>google.registry.model.registrar.Registrar</class>
@@ -46,6 +66,7 @@
<class>google.registry.model.registry.label.ReservedList</class>
<!-- Customized type converters -->
<class>google.registry.persistence.converter.AllocationTokenStatusTransitionConverter</class>
<class>google.registry.persistence.converter.BillingCostTransitionConverter</class>
<class>google.registry.persistence.converter.BillingEventFlagSetConverter</class>
<class>google.registry.persistence.converter.BloomFilterConverter</class>
@@ -76,8 +97,16 @@
<class>google.registry.model.host.VKeyConverter_HostResource</class>
<class>google.registry.model.poll.VKeyConverter_Autorenew</class>
<class>google.registry.model.poll.VKeyConverter_OneTime</class>
<class>google.registry.model.reporting.VKeyConverter_HistoryEntry</class>
<!-- TODO(weiminyu): check out application-layer validation. -->
<validation-mode>NONE</validation-mode>
<properties>
<!-- Disables auto detection. -->
<property name="hibernate.archive.autodetection" value=""/>
<!-- NOOP scanner needed for Nomulus tool. -->
<property name="hibernate.archive.scanner"
value="google.registry.persistence.NoopJpaEntityScanner"/>
</properties>
</persistence-unit>
</persistence>
@@ -35,6 +35,7 @@
{@param addDsRecords: list<[keyTag:int, alg:int, digestType:int, digest:string]>}
{@param removeDsRecords: list<[keyTag:int, alg:int, digestType:int, digest:string]>}
{@param removeAllDsRecords: bool}
{@param? autorenews: string}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
@@ -96,39 +97,46 @@
{/if}
</domain:update>
</update>
{if $secdns}
{if $secdns or $autorenews}
<extension>
<secDNS:update xmlns:secDNS="urn:ietf:params:xml:ns:secDNS-1.1">
{if $removeAllDsRecords}
<secDNS:rem>
<secDNS:all>true</secDNS:all>
</secDNS:rem>
{/if}
{if length($removeDsRecords) > 0}
<secDNS:rem>
{for $dsRecord in $removeDsRecords}
<secDNS:dsData>
<secDNS:keyTag>{$dsRecord.keyTag}</secDNS:keyTag>
<secDNS:alg>{$dsRecord.alg}</secDNS:alg>
<secDNS:digestType>{$dsRecord.digestType}</secDNS:digestType>
<secDNS:digest>{$dsRecord.digest}</secDNS:digest>
</secDNS:dsData>
{/for}
</secDNS:rem>
{/if}
{if length($addDsRecords) > 0}
<secDNS:add>
{for $dsRecord in $addDsRecords}
<secDNS:dsData>
<secDNS:keyTag>{$dsRecord.keyTag}</secDNS:keyTag>
<secDNS:alg>{$dsRecord.alg}</secDNS:alg>
<secDNS:digestType>{$dsRecord.digestType}</secDNS:digestType>
<secDNS:digest>{$dsRecord.digest}</secDNS:digest>
</secDNS:dsData>
{/for}
</secDNS:add>
{/if}
</secDNS:update>
{if $secdns}
<secDNS:update xmlns:secDNS="urn:ietf:params:xml:ns:secDNS-1.1">
{if $removeAllDsRecords}
<secDNS:rem>
<secDNS:all>true</secDNS:all>
</secDNS:rem>
{/if}
{if length($removeDsRecords) > 0}
<secDNS:rem>
{for $dsRecord in $removeDsRecords}
<secDNS:dsData>
<secDNS:keyTag>{$dsRecord.keyTag}</secDNS:keyTag>
<secDNS:alg>{$dsRecord.alg}</secDNS:alg>
<secDNS:digestType>{$dsRecord.digestType}</secDNS:digestType>
<secDNS:digest>{$dsRecord.digest}</secDNS:digest>
</secDNS:dsData>
{/for}
</secDNS:rem>
{/if}
{if length($addDsRecords) > 0}
<secDNS:add>
{for $dsRecord in $addDsRecords}
<secDNS:dsData>
<secDNS:keyTag>{$dsRecord.keyTag}</secDNS:keyTag>
<secDNS:alg>{$dsRecord.alg}</secDNS:alg>
<secDNS:digestType>{$dsRecord.digestType}</secDNS:digestType>
<secDNS:digest>{$dsRecord.digest}</secDNS:digest>
</secDNS:dsData>
{/for}
</secDNS:add>
{/if}
</secDNS:update>
{/if}
{if $autorenews}
<superuser:domainUpdate xmlns:superuser="urn:google:params:xml:ns:superuser-1.0">
<superuser:autorenews>{$autorenews}</superuser:autorenews>
</superuser:domainUpdate>
{/if}
</extension>
{/if}
<clTRID>RegistryTool</clTRID>
@@ -51,7 +51,7 @@ class InitSqlPipelineGraphTest {
TestPipelineExtension.create().enableAbandonedNodeEnforcement(false);
@Test
public void createPipeline_compareGraph() throws IOException {
void createPipeline_compareGraph() throws IOException {
new InitSqlPipeline(options, testPipeline).setupPipeline();
String dotString = PipelineDotRenderer.toDotString(testPipeline);
URL goldenDotUrl = Resources.getResource(InitSqlPipelineGraphTest.class, GOLDEN_DOT_FILE);
@@ -71,6 +71,7 @@ import google.registry.model.registry.Registry;
import google.registry.model.registry.Registry.TldState;
import google.registry.model.registry.label.ReservedList;
import google.registry.model.reporting.HistoryEntry;
import google.registry.persistence.VKey;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
import org.joda.time.DateTime;
@@ -162,12 +163,13 @@ class DomainCheckFlowTest extends ResourceCheckFlowTestCase<DomainCheckFlow, Dom
@Test
void testSuccess_oneExists_allocationTokenIsRedeemed() throws Exception {
setEppInput("domain_check_allocationtoken.xml");
persistActiveDomain("example1.tld");
DomainBase domain = persistActiveDomain("example1.tld");
Key<HistoryEntry> historyEntryKey = Key.create(Key.create(domain), HistoryEntry.class, 1L);
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(SINGLE_USE)
.setRedemptionHistoryEntry(Key.create(HistoryEntry.class, 1L))
.setRedemptionHistoryEntry(VKey.create(HistoryEntry.class, 1L, historyEntryKey))
.build());
doCheckTest(
create(false, "example1.tld", "In use"),
@@ -417,7 +419,7 @@ class DomainCheckFlowTest extends ResourceCheckFlowTestCase<DomainCheckFlow, Dom
.setToken("abc123")
.setTokenType(UNLIMITED_USE)
.setDiscountFraction(0.5)
.setAllowedClientIds(ImmutableSet.of("someOtherClient"))
.setAllowedRegistrarIds(ImmutableSet.of("someOtherClient"))
.setTokenStatusTransitions(
ImmutableSortedMap.<DateTime, TokenStatus>naturalOrder()
.put(START_OF_TIME, TokenStatus.NOT_STARTED)
@@ -162,6 +162,7 @@ import google.registry.model.reporting.DomainTransactionRecord;
import google.registry.model.reporting.DomainTransactionRecord.TransactionReportField;
import google.registry.model.reporting.HistoryEntry;
import google.registry.monitoring.whitebox.EppMetric;
import google.registry.persistence.VKey;
import google.registry.testing.TaskQueueHelper.TaskMatcher;
import java.math.BigDecimal;
import java.util.Map;
@@ -492,11 +493,13 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
"domain_create_allocationtoken.xml",
ImmutableMap.of("DOMAIN", "example.tld", "YEARS", "2"));
persistContactsAndHosts();
DomainBase domain = persistActiveDomain("foo.tld");
Key<HistoryEntry> historyEntryKey = Key.create(Key.create(domain), HistoryEntry.class, 505L);
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(SINGLE_USE)
.setRedemptionHistoryEntry(Key.create(HistoryEntry.class, 505L))
.setRedemptionHistoryEntry(VKey.create(HistoryEntry.class, 505L, historyEntryKey))
.build());
clock.advanceOneMilli();
EppException thrown =
@@ -519,7 +522,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
HistoryEntry historyEntry =
ofy().load().type(HistoryEntry.class).ancestor(reloadResourceByForeignKey()).first().now();
assertThat(ofy().load().entity(token).now().getRedemptionHistoryEntry())
.hasValue(Key.create(historyEntry));
.hasValue(HistoryEntry.createVKey(Key.create(historyEntry)));
}
@Test
@@ -1263,7 +1266,9 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
ofy().load().key(Key.create(AllocationToken.class, token)).now();
assertThat(reloadedToken.isRedeemed()).isTrue();
assertThat(reloadedToken.getRedemptionHistoryEntry())
.hasValue(Key.create(getHistoryEntries(reloadResourceByForeignKey()).get(0)));
.hasValue(
HistoryEntry.createVKey(
Key.create(getHistoryEntries(reloadResourceByForeignKey()).get(0))));
}
private void assertAllocationTokenWasNotRedeemed(String token) {
@@ -1498,7 +1503,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(UNLIMITED_USE)
.setAllowedClientIds(ImmutableSet.of("someClientId"))
.setAllowedRegistrarIds(ImmutableSet.of("someClientId"))
.setDiscountFraction(0.5)
.setTokenStatusTransitions(
ImmutableSortedMap.<DateTime, TokenStatus>naturalOrder()
@@ -572,6 +572,7 @@ class DomainTransferRequestFlowTest
Duration expectedAutomaticTransferLength,
BillingEvent.Cancellation.Builder... extraExpectedBillingEvents)
throws Exception {
eppRequestSource = EppRequestSource.TOOL;
setEppInput(commandFilename, substitutions);
ImmutableSet<GracePeriod> originalGracePeriods = domain.getGracePeriods();
// Replace the ROID in the xml file with the one generated in our test.
@@ -903,7 +904,6 @@ class DomainTransferRequestFlowTest
@Test
void testSuccess_superuserExtension_zeroPeriod_nonZeroAutomaticTransferLength() throws Exception {
setupDomain("example", "tld");
eppRequestSource = EppRequestSource.TOOL;
clock.advanceOneMilli();
doSuccessfulSuperuserExtensionTest(
"domain_transfer_request_superuser_extension.xml",
@@ -918,7 +918,6 @@ class DomainTransferRequestFlowTest
@Test
void testSuccess_superuserExtension_zeroPeriod_zeroAutomaticTransferLength() throws Exception {
setupDomain("example", "tld");
eppRequestSource = EppRequestSource.TOOL;
clock.advanceOneMilli();
doSuccessfulSuperuserExtensionTest(
"domain_transfer_request_superuser_extension.xml",
@@ -934,7 +933,6 @@ class DomainTransferRequestFlowTest
void testSuccess_superuserExtension_nonZeroPeriod_nonZeroAutomaticTransferLength()
throws Exception {
setupDomain("example", "tld");
eppRequestSource = EppRequestSource.TOOL;
clock.advanceOneMilli();
doSuccessfulSuperuserExtensionTest(
"domain_transfer_request_superuser_extension.xml",
@@ -948,7 +946,6 @@ class DomainTransferRequestFlowTest
@Test
void testSuccess_superuserExtension_zeroPeriod_autorenewGraceActive() throws Exception {
eppRequestSource = EppRequestSource.TOOL;
setupDomain("example", "tld");
VKey<BillingEvent.Recurring> existingAutorenewEvent = domain.getAutorenewBillingEvent();
// Set domain to have auto-renewed just before the transfer request, so that it will have an
@@ -89,12 +89,14 @@ import google.registry.model.host.HostResource;
import google.registry.model.registry.Registry;
import google.registry.model.reporting.HistoryEntry;
import google.registry.persistence.VKey;
import java.util.Optional;
import org.joda.money.Money;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link DomainUpdateFlow}. */
public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, DomainBase> {
class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, DomainBase> {
private static final DelegationSignerData SOME_DSDATA =
DelegationSignerData.create(1, 2, 3, base16().decode("0123"));
@@ -105,13 +107,12 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
"DIGEST_TYPE", "1",
"DIGEST", "38EC35D5B3A34B44C39B");
ContactResource sh8013Contact;
ContactResource mak21Contact;
ContactResource unusedContact;
HistoryEntry historyEntryDomainCreate;
private ContactResource sh8013Contact;
private ContactResource mak21Contact;
private ContactResource unusedContact;
@BeforeEach
public void initDomainTest() {
void initDomainTest() {
createTld("tld");
// Note that "domain_update.xml" tests adding and removing the same contact type.
setEppInput("domain_update.xml");
@@ -141,12 +142,11 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.setRegistrant(mak21Contact.createVKey())
.setNameservers(ImmutableSet.of(host.createVKey()))
.build());
historyEntryDomainCreate =
persistResource(
new HistoryEntry.Builder()
.setType(HistoryEntry.Type.DOMAIN_CREATE)
.setParent(domain)
.build());
persistResource(
new HistoryEntry.Builder()
.setType(HistoryEntry.Type.DOMAIN_CREATE)
.setParent(domain)
.build());
clock.advanceOneMilli();
return domain;
}
@@ -164,12 +164,11 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
DesignatedContact.create(Type.ADMIN, unusedContact.createVKey())))
.setNameservers(ImmutableSet.of(host.createVKey()))
.build());
historyEntryDomainCreate =
persistResource(
new HistoryEntry.Builder()
.setType(HistoryEntry.Type.DOMAIN_CREATE)
.setParent(domain)
.build());
persistResource(
new HistoryEntry.Builder()
.setType(HistoryEntry.Type.DOMAIN_CREATE)
.setParent(domain)
.build());
clock.advanceOneMilli();
return domain;
}
@@ -193,27 +192,29 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.and()
.hasLastEppUpdateTime(clock.nowUtc())
.and()
.hasLastEppUpdateClientId("TheRegistrar");
.hasLastEppUpdateClientId("TheRegistrar")
.and()
.hasNoAutorenewEndTime();
assertNoBillingEvents();
assertDnsTasksEnqueued("example.tld");
}
@Test
public void testDryRun() throws Exception {
void testDryRun() throws Exception {
persistReferencedEntities();
persistDomain();
dryRunFlowAssertResponse(loadFile("generic_success_response.xml"));
}
@Test
public void testSuccess() throws Exception {
void testSuccess() throws Exception {
persistReferencedEntities();
persistDomain();
doSuccessfulTest();
}
@Test
public void testSuccess_clTridNotSpecified() throws Exception {
void testSuccess_clTridNotSpecified() throws Exception {
setEppInput("domain_update_no_cltrid.xml");
persistReferencedEntities();
persistDomain();
@@ -221,7 +222,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_cachingDisabled() throws Exception {
void testSuccess_cachingDisabled() throws Exception {
boolean origIsCachingEnabled = RegistryConfig.isEppResourceCachingEnabled();
try {
RegistryConfig.overrideIsEppResourceCachingEnabledForTesting(false);
@@ -234,7 +235,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_inQuietPeriod() throws Exception {
void testSuccess_inQuietPeriod() throws Exception {
persistResource(
Registry.get("tld")
.asBuilder()
@@ -246,7 +247,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_emptyRegistrant() throws Exception {
void testFailure_emptyRegistrant() throws Exception {
setEppInput("domain_update_empty_registrant.xml");
persistReferencedEntities();
persistDomain();
@@ -272,7 +273,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_maxNumberOfNameservers() throws Exception {
void testSuccess_maxNumberOfNameservers() throws Exception {
persistReferencedEntities();
persistDomain();
// Modify domain to have 13 nameservers. We will then remove one and add one in the test.
@@ -281,7 +282,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_addAndRemoveLargeNumberOfNameserversAndContacts() throws Exception {
void testSuccess_addAndRemoveLargeNumberOfNameserversAndContacts() throws Exception {
persistReferencedEntities();
persistDomain();
setEppInput("domain_update_max_everything.xml");
@@ -325,7 +326,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_metadata() throws Exception {
void testSuccess_metadata() throws Exception {
eppRequestSource = EppRequestSource.TOOL;
setEppInput("domain_update_metadata.xml");
persistReferencedEntities();
@@ -344,7 +345,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_metadataNotFromTool() throws Exception {
void testSuccess_metadataNotFromTool() throws Exception {
setEppInput("domain_update_metadata.xml");
persistReferencedEntities();
persistDomain();
@@ -353,7 +354,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_removeContact() throws Exception {
void testSuccess_removeContact() throws Exception {
setEppInput("domain_update_remove_contact.xml");
persistReferencedEntities();
persistDomain();
@@ -361,7 +362,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_addAndRemoveSubordinateHostNameservers() throws Exception {
void testSuccess_addAndRemoveSubordinateHostNameservers() throws Exception {
// Test that operations involving subordinate hosts as nameservers do not change the subordinate
// host relationship itself.
setEppInput("domain_update_subordinate_hosts.xml");
@@ -394,7 +395,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_registrantMovedToTechContact() throws Exception {
void testSuccess_registrantMovedToTechContact() throws Exception {
setEppInput("domain_update_registrant_to_tech.xml");
persistReferencedEntities();
ContactResource sh8013 =
@@ -409,7 +410,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_multipleReferencesToSameContactRemoved() throws Exception {
void testSuccess_multipleReferencesToSameContactRemoved() throws Exception {
setEppInput("domain_update_remove_multiple_contacts.xml");
persistReferencedEntities();
ContactResource sh8013 =
@@ -430,7 +431,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_removeClientUpdateProhibited() throws Exception {
void testSuccess_removeClientUpdateProhibited() throws Exception {
persistReferencedEntities();
persistResource(
persistDomain()
@@ -474,7 +475,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_secDnsAdd() throws Exception {
void testSuccess_secDnsAdd() throws Exception {
doSecDnsSuccessfulTest(
"domain_update_dsdata_add.xml",
null,
@@ -485,7 +486,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_secDnsAddPreservesExisting() throws Exception {
void testSuccess_secDnsAddPreservesExisting() throws Exception {
doSecDnsSuccessfulTest(
"domain_update_dsdata_add.xml",
ImmutableSet.of(SOME_DSDATA),
@@ -497,7 +498,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_secDnsAddSameDoesNothing() throws Exception {
void testSuccess_secDnsAddSameDoesNothing() throws Exception {
doSecDnsSuccessfulTest(
"domain_update_dsdata_add.xml",
ImmutableSet.of(SOME_DSDATA),
@@ -506,7 +507,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_secDnsAddOnlyKeyTagRemainsSame() throws Exception {
void testSuccess_secDnsAddOnlyKeyTagRemainsSame() throws Exception {
doSecDnsSuccessfulTest(
"domain_update_dsdata_add.xml",
ImmutableSet.of(SOME_DSDATA),
@@ -517,7 +518,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
// Changing any of the four fields in DelegationSignerData should result in a new object
@Test
public void testSuccess_secDnsAddOnlyChangeKeyTag() throws Exception {
void testSuccess_secDnsAddOnlyChangeKeyTag() throws Exception {
doSecDnsSuccessfulTest(
"domain_update_dsdata_add.xml",
ImmutableSet.of(SOME_DSDATA),
@@ -527,7 +528,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_secDnsAddOnlyChangeAlgorithm() throws Exception {
void testSuccess_secDnsAddOnlyChangeAlgorithm() throws Exception {
doSecDnsSuccessfulTest(
"domain_update_dsdata_add.xml",
ImmutableSet.of(SOME_DSDATA),
@@ -536,7 +537,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_secDnsAddOnlyChangeDigestType() throws Exception {
void testSuccess_secDnsAddOnlyChangeDigestType() throws Exception {
doSecDnsSuccessfulTest(
"domain_update_dsdata_add.xml",
ImmutableSet.of(SOME_DSDATA),
@@ -545,7 +546,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_secDnsAddOnlyChangeDigest() throws Exception {
void testSuccess_secDnsAddOnlyChangeDigest() throws Exception {
doSecDnsSuccessfulTest(
"domain_update_dsdata_add.xml",
ImmutableSet.of(SOME_DSDATA),
@@ -554,7 +555,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_secDnsAddToMaxRecords() throws Exception {
void testSuccess_secDnsAddToMaxRecords() throws Exception {
ImmutableSet.Builder<DelegationSignerData> builder = new ImmutableSet.Builder<>();
for (int i = 0; i < 7; ++i) {
builder.add(DelegationSignerData.create(i, 2, 3, new byte[] {0, 1, 2}));
@@ -573,7 +574,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_secDnsRemove() throws Exception {
void testSuccess_secDnsRemove() throws Exception {
doSecDnsSuccessfulTest(
"domain_update_dsdata_rem.xml",
ImmutableSet.of(
@@ -583,7 +584,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_secDnsRemoveAll() throws Exception {
void testSuccess_secDnsRemoveAll() throws Exception {
// As an aside, this test also validates that it's ok to set the 'urgent' attribute to false.
doSecDnsSuccessfulTest(
"domain_update_dsdata_rem_all.xml",
@@ -594,7 +595,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_secDnsAddRemove() throws Exception {
void testSuccess_secDnsAddRemove() throws Exception {
doSecDnsSuccessfulTest(
"domain_update_dsdata_add_rem.xml",
ImmutableSet.of(
@@ -606,7 +607,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_secDnsAddRemoveToMaxRecords() throws Exception {
void testSuccess_secDnsAddRemoveToMaxRecords() throws Exception {
ImmutableSet.Builder<DelegationSignerData> builder = new ImmutableSet.Builder<>();
for (int i = 0; i < 7; ++i) {
builder.add(DelegationSignerData.create(i, 2, 3, new byte[] {0, 1, 2}));
@@ -630,7 +631,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_secDnsAddRemoveSame() throws Exception {
void testSuccess_secDnsAddRemoveSame() throws Exception {
// Adding and removing the same dsData is a no-op because removes are processed first.
doSecDnsSuccessfulTest(
"domain_update_dsdata_add_rem_same.xml",
@@ -643,13 +644,13 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_secDnsRemoveAlreadyNotThere() throws Exception {
void testSuccess_secDnsRemoveAlreadyNotThere() throws Exception {
// Removing a dsData that isn't there is a no-op.
doSecDnsSuccessfulTest(
"domain_update_dsdata_rem.xml", ImmutableSet.of(SOME_DSDATA), ImmutableSet.of(SOME_DSDATA));
}
public void doServerStatusBillingTest(String xmlFilename, boolean isBillable) throws Exception {
void doServerStatusBillingTest(String xmlFilename, boolean isBillable) throws Exception {
setEppInput(xmlFilename);
clock.advanceOneMilli();
runFlowAssertResponse(
@@ -674,7 +675,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_addServerStatusBillingEvent() throws Exception {
void testSuccess_addServerStatusBillingEvent() throws Exception {
eppRequestSource = EppRequestSource.TOOL;
persistReferencedEntities();
persistDomain();
@@ -682,7 +683,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_noBillingOnPreExistingServerStatus() throws Exception {
void testSuccess_noBillingOnPreExistingServerStatus() throws Exception {
eppRequestSource = EppRequestSource.TOOL;
DomainBase addStatusDomain = persistActiveDomain(getUniqueIdFromCommand());
persistResource(
@@ -691,7 +692,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_removeServerStatusBillingEvent() throws Exception {
void testSuccess_removeServerStatusBillingEvent() throws Exception {
eppRequestSource = EppRequestSource.TOOL;
persistReferencedEntities();
DomainBase removeStatusDomain = persistDomain();
@@ -701,7 +702,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_changeServerStatusBillingEvent() throws Exception {
void testSuccess_changeServerStatusBillingEvent() throws Exception {
eppRequestSource = EppRequestSource.TOOL;
persistReferencedEntities();
DomainBase changeStatusDomain = persistDomain();
@@ -711,26 +712,26 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_noBillingEventOnNonServerStatusChange() throws Exception {
void testSuccess_noBillingEventOnNonServerStatusChange() throws Exception {
persistActiveDomain(getUniqueIdFromCommand());
doServerStatusBillingTest("domain_update_add_non_server_status.xml", false);
}
@Test
public void testSuccess_noBillingEventOnServerHoldStatusChange() throws Exception {
void testSuccess_noBillingEventOnServerHoldStatusChange() throws Exception {
persistActiveDomain(getUniqueIdFromCommand());
doServerStatusBillingTest("domain_update_add_server_hold_status.xml", false);
}
@Test
public void testSuccess_noBillingEventOnServerStatusChangeNotFromRegistrar() throws Exception {
void testSuccess_noBillingEventOnServerStatusChangeNotFromRegistrar() throws Exception {
eppRequestSource = EppRequestSource.TOOL;
persistActiveDomain(getUniqueIdFromCommand());
doServerStatusBillingTest("domain_update_add_server_status_non_registrar.xml", false);
}
@Test
public void testSuccess_superuserClientUpdateProhibited() throws Exception {
void testSuccess_superuserClientUpdateProhibited() throws Exception {
setEppInput("domain_update_add_server_hold_status.xml");
persistReferencedEntities();
persistResource(
@@ -758,29 +759,29 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_secDnsAllCannotBeFalse() throws Exception {
void testFailure_secDnsAllCannotBeFalse() throws Exception {
doSecDnsFailingTest(SecDnsAllUsageException.class, "domain_update_dsdata_rem_all_false.xml");
}
@Test
public void testFailure_secDnsEmptyNotAllowed() throws Exception {
void testFailure_secDnsEmptyNotAllowed() throws Exception {
doSecDnsFailingTest(EmptySecDnsUpdateException.class, "domain_update_dsdata_empty.xml");
}
@Test
public void testFailure_secDnsUrgentNotSupported() throws Exception {
void testFailure_secDnsUrgentNotSupported() throws Exception {
doSecDnsFailingTest(
UrgentAttributeNotSupportedException.class, "domain_update_dsdata_urgent.xml");
}
@Test
public void testFailure_secDnsChangeNotSupported() throws Exception {
void testFailure_secDnsChangeNotSupported() throws Exception {
doSecDnsFailingTest(
MaxSigLifeChangeNotSupportedException.class, "domain_update_maxsiglife.xml");
}
@Test
public void testFailure_secDnsTooManyDsRecords() throws Exception {
void testFailure_secDnsTooManyDsRecords() throws Exception {
ImmutableSet.Builder<DelegationSignerData> builder = new ImmutableSet.Builder<>();
for (int i = 0; i < 8; ++i) {
builder.add(DelegationSignerData.create(i, 2, 3, new byte[] {0, 1, 2}));
@@ -794,7 +795,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_tooManyNameservers() throws Exception {
void testFailure_tooManyNameservers() throws Exception {
setEppInput("domain_update_add_nameserver.xml");
persistReferencedEntities();
persistDomain();
@@ -805,7 +806,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_wrongExtension() throws Exception {
void testFailure_wrongExtension() throws Exception {
setEppInput("domain_update_wrong_extension.xml");
persistReferencedEntities();
persistDomain();
@@ -814,7 +815,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_neverExisted() throws Exception {
void testFailure_neverExisted() throws Exception {
persistReferencedEntities();
ResourceDoesNotExistException thrown =
assertThrows(ResourceDoesNotExistException.class, this::runFlow);
@@ -822,7 +823,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_existedButWasDeleted() throws Exception {
void testFailure_existedButWasDeleted() throws Exception {
persistReferencedEntities();
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
ResourceDoesNotExistException thrown =
@@ -831,7 +832,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_missingHost() throws Exception {
void testFailure_missingHost() throws Exception {
persistActiveHost("ns1.example.foo");
persistActiveContact("sh8013");
persistActiveContact("mak21");
@@ -842,7 +843,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_missingContact() throws Exception {
void testFailure_missingContact() throws Exception {
persistActiveHost("ns1.example.foo");
persistActiveHost("ns2.example.foo");
persistActiveContact("mak21");
@@ -853,7 +854,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_addingDuplicateContact() throws Exception {
void testFailure_addingDuplicateContact() throws Exception {
persistReferencedEntities();
persistActiveContact("foo");
persistDomain();
@@ -878,7 +879,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_statusValueNotClientSettable() throws Exception {
void testFailure_statusValueNotClientSettable() throws Exception {
setEppInput("domain_update_prohibited_status.xml");
persistReferencedEntities();
persistDomain();
@@ -887,7 +888,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_superuserStatusValueNotClientSettable() throws Exception {
void testSuccess_superuserStatusValueNotClientSettable() throws Exception {
setEppInput("domain_update_prohibited_status.xml");
persistReferencedEntities();
persistDomain();
@@ -896,7 +897,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_serverUpdateProhibited_prohibitsNonSuperuserUpdates() throws Exception {
void testFailure_serverUpdateProhibited_prohibitsNonSuperuserUpdates() throws Exception {
persistReferencedEntities();
persistResource(
newDomainBase(getUniqueIdFromCommand())
@@ -908,7 +909,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_serverUpdateProhibited_allowsSuperuserUpdates() throws Exception {
void testSuccess_serverUpdateProhibited_allowsSuperuserUpdates() throws Exception {
persistReferencedEntities();
persistResource(persistDomain().asBuilder().addStatusValue(SERVER_UPDATE_PROHIBITED).build());
clock.advanceOneMilli();
@@ -917,7 +918,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_serverUpdateProhibited_notSettableWithoutSuperuser() throws Exception {
void testFailure_serverUpdateProhibited_notSettableWithoutSuperuser() throws Exception {
setEppInput("domain_update_add_registry_lock.xml");
persistReferencedEntities();
persistDomain();
@@ -926,7 +927,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_serverUpdateProhibited_isSettableWithSuperuser() throws Exception {
void testSuccess_serverUpdateProhibited_isSettableWithSuperuser() throws Exception {
setEppInput("domain_update_add_registry_lock.xml");
persistReferencedEntities();
persistDomain();
@@ -935,7 +936,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_clientUpdateProhibited() throws Exception {
void testFailure_clientUpdateProhibited() throws Exception {
createTld("com");
setEppInput("domain_update_authinfo.xml");
persistReferencedEntities();
@@ -950,7 +951,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_serverUpdateProhibited() throws Exception {
void testFailure_serverUpdateProhibited() throws Exception {
persistReferencedEntities();
persistResource(
newDomainBase(getUniqueIdFromCommand())
@@ -963,7 +964,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_pendingDelete() throws Exception {
void testFailure_pendingDelete() throws Exception {
persistReferencedEntities();
persistResource(
newDomainBase(getUniqueIdFromCommand())
@@ -977,7 +978,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_duplicateContactInCommand() throws Exception {
void testFailure_duplicateContactInCommand() throws Exception {
setEppInput("domain_update_duplicate_contact.xml");
persistReferencedEntities();
persistDomain();
@@ -986,7 +987,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_multipleDuplicateContactInCommand() throws Exception {
void testFailure_multipleDuplicateContactInCommand() throws Exception {
setEppInput("domain_update_multiple_duplicate_contacts.xml");
persistReferencedEntities();
persistDomain();
@@ -1001,7 +1002,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_missingContactType() throws Exception {
void testFailure_missingContactType() throws Exception {
// We need to test for missing type, but not for invalid - the schema enforces that for us.
setEppInput("domain_update_missing_contact_type.xml");
persistReferencedEntities();
@@ -1011,7 +1012,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_unauthorizedClient() throws Exception {
void testFailure_unauthorizedClient() throws Exception {
sessionMetadata.setClientId("NewRegistrar");
persistReferencedEntities();
persistDomain();
@@ -1020,7 +1021,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_superuserUnauthorizedClient() throws Exception {
void testSuccess_superuserUnauthorizedClient() throws Exception {
sessionMetadata.setClientId("NewRegistrar");
persistReferencedEntities();
persistDomain();
@@ -1030,7 +1031,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_notAuthorizedForTld() throws Exception {
void testFailure_notAuthorizedForTld() throws Exception {
persistResource(
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
persistReferencedEntities();
@@ -1040,7 +1041,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_superuserNotAuthorizedForTld() throws Exception {
void testSuccess_superuserNotAuthorizedForTld() throws Exception {
persistResource(
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
persistReferencedEntities();
@@ -1051,7 +1052,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_sameNameserverAddedAndRemoved() throws Exception {
void testFailure_sameNameserverAddedAndRemoved() throws Exception {
setEppInput("domain_update_add_remove_same_host.xml");
persistReferencedEntities();
persistResource(
@@ -1068,7 +1069,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_sameContactAddedAndRemoved() throws Exception {
void testFailure_sameContactAddedAndRemoved() throws Exception {
setEppInput("domain_update_add_remove_same_contact.xml");
persistReferencedEntities();
persistResource(
@@ -1086,7 +1087,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_removeAdmin() throws Exception {
void testFailure_removeAdmin() throws Exception {
setEppInput("domain_update_remove_admin.xml");
persistReferencedEntities();
persistResource(
@@ -1102,7 +1103,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_removeTech() throws Exception {
void testFailure_removeTech() throws Exception {
setEppInput("domain_update_remove_tech.xml");
persistReferencedEntities();
persistResource(
@@ -1118,7 +1119,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_addPendingDeleteContact() throws Exception {
void testFailure_addPendingDeleteContact() throws Exception {
persistReferencedEntities();
persistDomain();
persistActiveHost("ns1.example.foo");
@@ -1137,7 +1138,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_addPendingDeleteHost() throws Exception {
void testFailure_addPendingDeleteHost() throws Exception {
persistReferencedEntities();
persistDomain();
persistActiveHost("ns1.example.foo");
@@ -1156,7 +1157,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_newRegistrantNotAllowListed() throws Exception {
void testFailure_newRegistrantNotAllowListed() throws Exception {
persistReferencedEntities();
persistDomain();
persistResource(
@@ -1170,8 +1171,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_addedNameserverDisallowedInTld()
throws Exception {
void testFailure_addedNameserverDisallowedInTld() throws Exception {
persistReferencedEntities();
persistDomain();
persistResource(
@@ -1186,7 +1186,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_newNameserverAllowListed() throws Exception {
void testSuccess_newNameserverAllowListed() throws Exception {
setEppInput("domain_update_add_nameserver.xml");
persistReferencedEntities();
persistDomain();
@@ -1212,7 +1212,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_changeRegistrantAllowListed() throws Exception {
void testSuccess_changeRegistrantAllowListed() throws Exception {
setEppInput("domain_update_registrant.xml");
persistReferencedEntities();
persistDomain();
@@ -1229,7 +1229,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_changeContactsAndRegistrant() throws Exception {
void testSuccess_changeContactsAndRegistrant() throws Exception {
setEppInput("domain_update_contacts_and_registrant.xml");
persistReferencedEntities();
persistDomainWithRegistrant();
@@ -1256,7 +1256,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_nameserverAndRegistrantAllowListed() throws Exception {
void testSuccess_nameserverAndRegistrantAllowListed() throws Exception {
persistReferencedEntities();
persistDomain();
persistResource(
@@ -1269,7 +1269,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_tldWithNameserverAllowList_removeNameserver() throws Exception {
void testSuccess_tldWithNameserverAllowList_removeNameserver() throws Exception {
setEppInput("domain_update_remove_nameserver.xml");
persistReferencedEntities();
persistDomain();
@@ -1301,7 +1301,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_tldWithNameserverAllowList_removeLastNameserver() throws Exception {
void testFailure_tldWithNameserverAllowList_removeLastNameserver() throws Exception {
persistReferencedEntities();
persistDomain();
setEppInput("domain_update_remove_nameserver.xml");
@@ -1317,7 +1317,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testSuccess_domainCreateNotRestricted_doNotApplyServerProhibitedStatusCodes()
void testSuccess_domainCreateNotRestricted_doNotApplyServerProhibitedStatusCodes()
throws Exception {
persistReferencedEntities();
persistDomain();
@@ -1328,7 +1328,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testFailure_freePremium_wrongFee() throws Exception {
void testFailure_freePremium_wrongFee() throws Exception {
setEppInput("domain_update_fee.xml", ImmutableMap.of("FEE_VERSION", "0.11"));
persistReferencedEntities();
persistDomain();
@@ -1339,7 +1339,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
// This test should throw an exception, because the fee extension is required when the fee is not
// zero.
@Test
public void testFailure_missingFeeOnNonFreeUpdate() throws Exception {
void testFailure_missingFeeOnNonFreeUpdate() throws Exception {
setEppInput("domain_update_wildcard.xml", ImmutableMap.of("DOMAIN", "non-free-update.tld"));
persistReferencedEntities();
persistDomain();
@@ -1349,11 +1349,41 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
@Test
public void testIcannActivityReportField_getsLogged() throws Exception {
void testIcannActivityReportField_getsLogged() throws Exception {
persistReferencedEntities();
persistDomain();
runFlow();
assertIcannReportingActivityFieldLogged("srs-dom-update");
assertTldsFieldLogged("tld");
}
@Test
void testSuperuserExtension_turnsOffAutorenew() throws Exception {
eppRequestSource = EppRequestSource.TOOL;
setEppInput("domain_update_superuser_extension.xml", ImmutableMap.of("AUTORENEWS", "false"));
DateTime expirationTime = clock.nowUtc().plusYears(3);
persistReferencedEntities();
persistResource(
persistDomain().asBuilder().setRegistrationExpirationTime(expirationTime).build());
clock.advanceOneMilli();
runFlowAsSuperuser();
assertAboutDomains().that(reloadResourceByForeignKey()).hasAutorenewEndTime(expirationTime);
}
@Test
void testSuperuserExtension_turnsOnAutorenew() throws Exception {
eppRequestSource = EppRequestSource.TOOL;
setEppInput("domain_update_superuser_extension.xml", ImmutableMap.of("AUTORENEWS", "true"));
DateTime expirationTime = clock.nowUtc().plusYears(3);
persistReferencedEntities();
persistResource(
persistDomain()
.asBuilder()
.setAutorenewEndTime(Optional.of(expirationTime))
.setRegistrationExpirationTime(expirationTime)
.build());
clock.advanceOneMilli();
runFlowAsSuperuser();
assertAboutDomains().that(reloadResourceByForeignKey()).hasNoAutorenewEndTime();
}
}
@@ -22,6 +22,7 @@ import static google.registry.model.domain.token.AllocationToken.TokenStatus.VAL
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
import static google.registry.model.domain.token.AllocationToken.TokenType.UNLIMITED_USE;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistActiveDomain;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
@@ -42,11 +43,13 @@ import google.registry.flows.domain.token.AllocationTokenFlowUtils.AllocationTok
import google.registry.flows.domain.token.AllocationTokenFlowUtils.AllocationTokenNotValidForRegistrarException;
import google.registry.flows.domain.token.AllocationTokenFlowUtils.AllocationTokenNotValidForTldException;
import google.registry.flows.domain.token.AllocationTokenFlowUtils.InvalidAllocationTokenException;
import google.registry.model.domain.DomainBase;
import google.registry.model.domain.DomainCommand;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.domain.token.AllocationToken.TokenStatus;
import google.registry.model.registry.Registry;
import google.registry.model.reporting.HistoryEntry;
import google.registry.persistence.VKey;
import google.registry.testing.AppEngineExtension;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
@@ -127,7 +130,7 @@ class AllocationTokenFlowUtilsTest {
void test_validateToken_invalidForClientId() {
persistResource(
createOneMonthPromoTokenBuilder(DateTime.now(UTC).minusDays(1))
.setAllowedClientIds(ImmutableSet.of("NewRegistrar"))
.setAllowedRegistrarIds(ImmutableSet.of("NewRegistrar"))
.build());
assertValidateThrowsEppException(AllocationTokenNotValidForRegistrarException.class);
}
@@ -189,11 +192,13 @@ class AllocationTokenFlowUtilsTest {
@Test
void test_checkDomainsWithToken_showsFailureMessageForRedeemedToken() {
DomainBase domain = persistActiveDomain("example.tld");
Key<HistoryEntry> historyEntryKey = Key.create(Key.create(domain), HistoryEntry.class, 1051L);
persistResource(
new AllocationToken.Builder()
.setToken("tokeN")
.setTokenType(SINGLE_USE)
.setRedemptionHistoryEntry(Key.create(HistoryEntry.class, 101L))
.setRedemptionHistoryEntry(VKey.create(HistoryEntry.class, 101L, historyEntryKey))
.build());
assertThat(
flowUtils
@@ -31,7 +31,6 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import google.registry.model.EntityTestCase;
import google.registry.model.ImmutableObjectSubject;
import google.registry.model.billing.BillingEvent;
import google.registry.model.contact.Disclose.PostalInfoChoice;
import google.registry.model.contact.PostalInfo.Type;
import google.registry.model.eppcommon.AuthInfo.PasswordAuth;
@@ -46,6 +45,7 @@ import org.junit.jupiter.api.Test;
/** Unit tests for {@link ContactResource}. */
public class ContactResourceTest extends EntityTestCase {
private ContactResource originalContact;
private ContactResource contactResource;
@@ -113,8 +113,6 @@ public class ContactResourceTest extends EntityTestCase {
.setGainingClientId("gaining")
.setLosingClientId("losing")
.setPendingTransferExpirationTime(fakeClock.nowUtc())
.setServerApproveEntities(
ImmutableSet.of(VKey.create(BillingEvent.OneTime.class, 1)))
.setTransferRequestTime(fakeClock.nowUtc())
.setTransferStatus(TransferStatus.SERVER_APPROVED)
.setTransferRequestTrid(Trid.create("client-trid", "server-trid"))
@@ -144,11 +144,10 @@ public class DomainBaseSqlTest {
EntityManager em = jpaTm().getEntityManager();
DomainBase result = em.find(DomainBase.class, "4-COM");
// Fix grace period and DS data, since we can't persist them yet.
// Fix DS data, since we can't persist it yet.
result =
result
.asBuilder()
.setRegistrant(contactKey)
.setDsData(
ImmutableSet.of(
DelegationSignerData.create(1, 2, 3, new byte[] {0, 1, 2})))
@@ -193,6 +192,38 @@ public class DomainBaseSqlTest {
});
}
@Test
void testUpdates() {
jpaTm()
.transact(
() -> {
jpaTm().saveNew(contact);
jpaTm().saveNew(contact2);
jpaTm().saveNew(domain);
jpaTm().saveNew(host);
});
domain = domain.asBuilder().setNameservers(ImmutableSet.of()).build();
jpaTm().transact(() -> jpaTm().saveNewOrUpdate(domain));
jpaTm()
.transact(
() -> {
DomainBase result = jpaTm().load(domain.createVKey());
// Fix DS data, since we can't persist that yet.
result =
result
.asBuilder()
.setDsData(
ImmutableSet.of(
DelegationSignerData.create(1, 2, 3, new byte[] {0, 1, 2})))
.build();
assertAboutImmutableObjects()
.that(result)
.isEqualExceptFields(domain, "updateTimestamp", "creationTime");
});
}
static ContactResource makeContact(String repoId) {
return new ContactResource.Builder()
.setRepoId(repoId)
@@ -98,6 +98,11 @@ public class GracePeriodTest {
@Test
void testFailure_createForRecurring_notAutoRenew() {
Key<Recurring> recurringKey =
Key.create(
Key.create(Key.create(DomainBase.class, "1-TEST"), HistoryEntry.class, 343L),
Recurring.class,
12345);
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@@ -107,7 +112,7 @@ public class GracePeriodTest {
"1-TEST",
now.plusDays(1),
"TheRegistrar",
VKey.create(Recurring.class, 12345)));
VKey.create(Recurring.class, 12345, recurringKey)));
assertThat(thrown).hasMessageThat().contains("autorenew");
}
}
@@ -16,6 +16,7 @@ package google.registry.model.domain.token;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
import static google.registry.model.domain.token.AllocationToken.TokenStatus.CANCELLED;
import static google.registry.model.domain.token.AllocationToken.TokenStatus.ENDED;
import static google.registry.model.domain.token.AllocationToken.TokenStatus.NOT_STARTED;
@@ -23,7 +24,9 @@ import static google.registry.model.domain.token.AllocationToken.TokenStatus.VAL
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
import static google.registry.model.domain.token.AllocationToken.TokenType.UNLIMITED_USE;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistActiveDomain;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static org.joda.time.DateTimeZone.UTC;
@@ -33,15 +36,21 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap;
import com.googlecode.objectify.Key;
import google.registry.model.EntityTestCase;
import google.registry.model.domain.DomainBase;
import google.registry.model.domain.token.AllocationToken.TokenStatus;
import google.registry.model.domain.token.AllocationToken.TokenType;
import google.registry.model.reporting.HistoryEntry;
import google.registry.persistence.VKey;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link AllocationToken}. */
class AllocationTokenTest extends EntityTestCase {
public class AllocationTokenTest extends EntityTestCase {
public AllocationTokenTest() {
super(JpaEntityCoverageCheck.ENABLED);
}
@BeforeEach
void beforeEach() {
@@ -53,11 +62,11 @@ class AllocationTokenTest extends EntityTestCase {
AllocationToken unlimitedUseToken =
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setToken("abc123Unlimited")
.setTokenType(UNLIMITED_USE)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("dev", "app"))
.setAllowedClientIds(ImmutableSet.of("TheRegistrar, NewRegistrar"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar, NewRegistrar"))
.setDiscountFraction(0.5)
.setDiscountPremiums(true)
.setDiscountYears(3)
@@ -70,26 +79,52 @@ class AllocationTokenTest extends EntityTestCase {
.build());
assertThat(ofy().load().entity(unlimitedUseToken).now()).isEqualTo(unlimitedUseToken);
DomainBase domain = persistActiveDomain("example.foo");
Key<HistoryEntry> historyEntryKey = Key.create(Key.create(domain), HistoryEntry.class, 1);
AllocationToken singleUseToken =
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setRedemptionHistoryEntry(Key.create(HistoryEntry.class, 1L))
.setToken("abc123Single")
.setRedemptionHistoryEntry(HistoryEntry.createVKey(historyEntryKey))
.setDomainName("example.foo")
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setTokenType(SINGLE_USE)
.build());
assertThat(ofy().load().entity(singleUseToken).now()).isEqualTo(singleUseToken);
jpaTm()
.transact(
() -> {
jpaTm().saveNew(unlimitedUseToken);
jpaTm().saveNew(singleUseToken);
});
jpaTm()
.transact(
() -> {
assertAboutImmutableObjects()
.that(jpaTm().load(VKey.createSql(AllocationToken.class, "abc123Unlimited")))
.isEqualExceptFields(
unlimitedUseToken,
"creationTime",
"updateTimestamp",
"redemptionHistoryEntry");
assertAboutImmutableObjects()
.that(jpaTm().load(VKey.createSql(AllocationToken.class, "abc123Single")))
.isEqualExceptFields(
singleUseToken, "creationTime", "updateTimestamp", "redemptionHistoryEntry");
});
}
@Test
void testIndexing() throws Exception {
DomainBase domain = persistActiveDomain("blahdomain.foo");
Key<HistoryEntry> historyEntryKey = Key.create(Key.create(domain), HistoryEntry.class, 1);
verifyIndexing(
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(SINGLE_USE)
.setRedemptionHistoryEntry(Key.create(HistoryEntry.class, 1L))
.setRedemptionHistoryEntry(VKey.create(HistoryEntry.class, 1L, historyEntryKey))
.setDomainName("blahdomain.foo")
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.build()),
@@ -189,11 +224,13 @@ class AllocationTokenTest extends EntityTestCase {
@Test
void testBuild_redemptionHistoryEntryOnlyInSingleUse() {
DomainBase domain = persistActiveDomain("blahdomain.foo");
Key<HistoryEntry> historyEntryKey = Key.create(Key.create(domain), HistoryEntry.class, 1);
AllocationToken.Builder builder =
new AllocationToken.Builder()
.setToken("foobar")
.setTokenType(TokenType.UNLIMITED_USE)
.setRedemptionHistoryEntry(Key.create(HistoryEntry.class, "hi"));
.setRedemptionHistoryEntry(VKey.create(HistoryEntry.class, 1L, historyEntryKey));
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, builder::build);
assertThat(thrown)
.hasMessageThat()
@@ -17,11 +17,14 @@ package google.registry.model.history;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatastoreHelper.newContactResourceWithRoid;
import static google.registry.testing.SqlHelper.saveRegistrar;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.googlecode.objectify.Key;
import google.registry.model.EntityTestCase;
import google.registry.model.contact.ContactBase;
import google.registry.model.contact.ContactHistory;
import google.registry.model.contact.ContactResource;
import google.registry.model.eppcommon.Trid;
@@ -44,19 +47,8 @@ public class ContactHistoryTest extends EntityTestCase {
jpaTm().transact(() -> jpaTm().saveNew(contact));
VKey<ContactResource> contactVKey = contact.createVKey();
ContactResource contactFromDb = jpaTm().transact(() -> jpaTm().load(contactVKey));
ContactHistory contactHistory =
new ContactHistory.Builder()
.setType(HistoryEntry.Type.HOST_CREATE)
.setXmlBytes("<xml></xml>".getBytes(UTF_8))
.setModificationTime(fakeClock.nowUtc())
.setClientId("TheRegistrar")
.setTrid(Trid.create("ABC-123", "server-trid"))
.setBySuperuser(false)
.setReason("reason")
.setRequestedByRegistrar(true)
.setContactBase(contactFromDb)
.setContactRepoId(contactVKey)
.build();
ContactHistory contactHistory = createContactHistory(contactFromDb, contactVKey);
contactHistory.id = null;
jpaTm().transact(() -> jpaTm().saveNew(contactHistory));
jpaTm()
.transact(
@@ -68,6 +60,47 @@ public class ContactHistoryTest extends EntityTestCase {
});
}
@Test
void testOfyPersistence() {
saveRegistrar("TheRegistrar");
ContactResource contact = newContactResourceWithRoid("contactId", "contact1");
tm().transact(() -> tm().saveNew(contact));
VKey<ContactResource> contactVKey = contact.createVKey();
ContactResource contactFromDb = tm().transact(() -> tm().load(contactVKey));
fakeClock.advanceOneMilli();
ContactHistory contactHistory = createContactHistory(contactFromDb, contactVKey);
tm().transact(() -> tm().saveNew(contactHistory));
// retrieving a HistoryEntry or a ContactHistory with the same key should return the same object
// note: due to the @EntitySubclass annotation. all Keys for ContactHistory objects will have
// type HistoryEntry
VKey<ContactHistory> contactHistoryVKey =
VKey.createOfy(ContactHistory.class, Key.create(contactHistory));
VKey<HistoryEntry> historyEntryVKey =
VKey.createOfy(HistoryEntry.class, Key.create(contactHistory.asHistoryEntry()));
ContactHistory hostHistoryFromDb = tm().transact(() -> tm().load(contactHistoryVKey));
HistoryEntry historyEntryFromDb = tm().transact(() -> tm().load(historyEntryVKey));
assertThat(hostHistoryFromDb).isEqualTo(historyEntryFromDb);
}
private ContactHistory createContactHistory(
ContactBase contact, VKey<ContactResource> contactVKey) {
return new ContactHistory.Builder()
.setType(HistoryEntry.Type.HOST_CREATE)
.setXmlBytes("<xml></xml>".getBytes(UTF_8))
.setModificationTime(fakeClock.nowUtc())
.setClientId("TheRegistrar")
.setTrid(Trid.create("ABC-123", "server-trid"))
.setBySuperuser(false)
.setReason("reason")
.setRequestedByRegistrar(true)
.setContactBase(contact)
.setContactRepoId(contactVKey)
.build();
}
static void assertContactHistoriesEqual(ContactHistory one, ContactHistory two) {
assertAboutImmutableObjects()
.that(one)
@@ -17,15 +17,18 @@ package google.registry.model.history;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatastoreHelper.newContactResourceWithRoid;
import static google.registry.testing.DatastoreHelper.newDomainBase;
import static google.registry.testing.DatastoreHelper.newHostResourceWithRoid;
import static google.registry.testing.SqlHelper.saveRegistrar;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.googlecode.objectify.Key;
import google.registry.model.EntityTestCase;
import google.registry.model.contact.ContactResource;
import google.registry.model.domain.DomainBase;
import google.registry.model.domain.DomainContent;
import google.registry.model.domain.DomainHistory;
import google.registry.model.eppcommon.Trid;
import google.registry.model.host.HostResource;
@@ -36,18 +39,23 @@ import org.junit.jupiter.api.Test;
/** Tests for {@link DomainHistory}. */
public class DomainHistoryTest extends EntityTestCase {
public DomainHistoryTest() {
DomainHistoryTest() {
super(JpaEntityCoverageCheck.ENABLED);
}
@Test
public void testPersistence() {
void testPersistence() {
saveRegistrar("TheRegistrar");
HostResource host = newHostResourceWithRoid("ns1.example.com", "host1");
jpaTm().transact(() -> jpaTm().saveNew(host));
ContactResource contact = newContactResourceWithRoid("contactId", "contact1");
jpaTm().transact(() -> jpaTm().saveNew(contact));
jpaTm()
.transact(
() -> {
jpaTm().saveNew(host);
jpaTm().saveNew(contact);
});
DomainBase domain =
newDomainBase("example.tld", "domainRepoId", contact)
@@ -56,19 +64,8 @@ public class DomainHistoryTest extends EntityTestCase {
.build();
jpaTm().transact(() -> jpaTm().saveNew(domain));
DomainHistory domainHistory =
new DomainHistory.Builder()
.setType(HistoryEntry.Type.DOMAIN_CREATE)
.setXmlBytes("<xml></xml>".getBytes(UTF_8))
.setModificationTime(fakeClock.nowUtc())
.setClientId("TheRegistrar")
.setTrid(Trid.create("ABC-123", "server-trid"))
.setBySuperuser(false)
.setReason("reason")
.setRequestedByRegistrar(true)
.setDomainContent(domain)
.setDomainRepoId(domain.createVKey())
.build();
DomainHistory domainHistory = createDomainHistory(domain);
domainHistory.id = null;
jpaTm().transact(() -> jpaTm().saveNew(domainHistory));
jpaTm()
@@ -82,9 +79,62 @@ public class DomainHistoryTest extends EntityTestCase {
});
}
@Test
void testOfyPersistence() {
saveRegistrar("TheRegistrar");
HostResource host = newHostResourceWithRoid("ns1.example.com", "host1");
ContactResource contact = newContactResourceWithRoid("contactId", "contact1");
tm().transact(
() -> {
tm().saveNew(host);
tm().saveNew(contact);
});
fakeClock.advanceOneMilli();
DomainBase domain =
newDomainBase("example.tld", "domainRepoId", contact)
.asBuilder()
.setNameservers(host.createVKey())
.build();
tm().transact(() -> tm().saveNew(domain));
fakeClock.advanceOneMilli();
DomainHistory domainHistory = createDomainHistory(domain);
tm().transact(() -> tm().saveNew(domainHistory));
// retrieving a HistoryEntry or a DomainHistory with the same key should return the same object
// note: due to the @EntitySubclass annotation. all Keys for ContactHistory objects will have
// type HistoryEntry
VKey<DomainHistory> domainHistoryVKey =
VKey.createOfy(DomainHistory.class, Key.create(domainHistory));
VKey<HistoryEntry> historyEntryVKey =
VKey.createOfy(HistoryEntry.class, Key.create(domainHistory.asHistoryEntry()));
DomainHistory domainHistoryFromDb = tm().transact(() -> tm().load(domainHistoryVKey));
HistoryEntry historyEntryFromDb = tm().transact(() -> tm().load(historyEntryVKey));
assertThat(domainHistoryFromDb).isEqualTo(historyEntryFromDb);
}
static void assertDomainHistoriesEqual(DomainHistory one, DomainHistory two) {
assertAboutImmutableObjects()
.that(one)
.isEqualExceptFields(two, "domainContent", "domainRepoId", "parent");
}
private DomainHistory createDomainHistory(DomainContent domain) {
return new DomainHistory.Builder()
.setType(HistoryEntry.Type.DOMAIN_CREATE)
.setXmlBytes("<xml></xml>".getBytes(UTF_8))
.setModificationTime(fakeClock.nowUtc())
.setClientId("TheRegistrar")
.setTrid(Trid.create("ABC-123", "server-trid"))
.setBySuperuser(false)
.setReason("reason")
.setRequestedByRegistrar(true)
.setDomainContent(domain)
.setDomainRepoId(domain.createVKey())
.build();
}
}
@@ -17,12 +17,15 @@ package google.registry.model.history;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatastoreHelper.newHostResourceWithRoid;
import static google.registry.testing.SqlHelper.saveRegistrar;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.googlecode.objectify.Key;
import google.registry.model.EntityTestCase;
import google.registry.model.eppcommon.Trid;
import google.registry.model.host.HostBase;
import google.registry.model.host.HostHistory;
import google.registry.model.host.HostResource;
import google.registry.model.reporting.HistoryEntry;
@@ -44,19 +47,8 @@ public class HostHistoryTest extends EntityTestCase {
jpaTm().transact(() -> jpaTm().saveNew(host));
VKey<HostResource> hostVKey = VKey.createSql(HostResource.class, "host1");
HostResource hostFromDb = jpaTm().transact(() -> jpaTm().load(hostVKey));
HostHistory hostHistory =
new HostHistory.Builder()
.setType(HistoryEntry.Type.HOST_CREATE)
.setXmlBytes("<xml></xml>".getBytes(UTF_8))
.setModificationTime(fakeClock.nowUtc())
.setClientId("TheRegistrar")
.setTrid(Trid.create("ABC-123", "server-trid"))
.setBySuperuser(false)
.setReason("reason")
.setRequestedByRegistrar(true)
.setHostBase(hostFromDb)
.setHostRepoId(hostVKey)
.build();
HostHistory hostHistory = createHostHistory(hostFromDb, hostVKey);
hostHistory.id = null;
jpaTm().transact(() -> jpaTm().saveNew(hostHistory));
jpaTm()
.transact(
@@ -69,10 +61,49 @@ public class HostHistoryTest extends EntityTestCase {
});
}
@Test
public void testOfySave() {
saveRegistrar("registrar1");
HostResource host = newHostResourceWithRoid("ns1.example.com", "host1");
tm().transact(() -> tm().saveNew(host));
VKey<HostResource> hostVKey = VKey.create(HostResource.class, "host1", Key.create(host));
HostResource hostFromDb = tm().transact(() -> tm().load(hostVKey));
HostHistory hostHistory = createHostHistory(hostFromDb, hostVKey);
fakeClock.advanceOneMilli();
tm().transact(() -> tm().saveNew(hostHistory));
// retrieving a HistoryEntry or a HostHistory with the same key should return the same object
// note: due to the @EntitySubclass annotation. all Keys for ContactHistory objects will have
// type HistoryEntry
VKey<HostHistory> hostHistoryVKey = VKey.createOfy(HostHistory.class, Key.create(hostHistory));
VKey<HistoryEntry> historyEntryVKey =
VKey.createOfy(HistoryEntry.class, Key.create(hostHistory.asHistoryEntry()));
HostHistory hostHistoryFromDb = tm().transact(() -> tm().load(hostHistoryVKey));
HistoryEntry historyEntryFromDb = tm().transact(() -> tm().load(historyEntryVKey));
assertThat(hostHistoryFromDb).isEqualTo(historyEntryFromDb);
}
private void assertHostHistoriesEqual(HostHistory one, HostHistory two) {
assertAboutImmutableObjects().that(one).isEqualExceptFields(two, "hostBase");
assertAboutImmutableObjects()
.that(one.getHostBase())
.isEqualExceptFields(two.getHostBase(), "repoId");
}
private HostHistory createHostHistory(HostBase hostBase, VKey<HostResource> hostVKey) {
return new HostHistory.Builder()
.setType(HistoryEntry.Type.HOST_CREATE)
.setXmlBytes("<xml></xml>".getBytes(UTF_8))
.setModificationTime(fakeClock.nowUtc())
.setClientId("TheRegistrar")
.setTrid(Trid.create("ABC-123", "server-trid"))
.setBySuperuser(false)
.setReason("reason")
.setRequestedByRegistrar(true)
.setHostBase(hostBase)
.setHostRepoId(hostVKey)
.build();
}
}
@@ -27,13 +27,11 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.collect.ImmutableSet;
import com.google.common.net.InetAddresses;
import google.registry.model.EntityTestCase;
import google.registry.model.billing.BillingEvent;
import google.registry.model.domain.DomainBase;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.eppcommon.Trid;
import google.registry.model.transfer.DomainTransferData;
import google.registry.model.transfer.TransferStatus;
import google.registry.persistence.VKey;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -62,8 +60,6 @@ class HostResourceTest extends EntityTestCase {
.setGainingClientId("gaining")
.setLosingClientId("losing")
.setPendingTransferExpirationTime(fakeClock.nowUtc())
.setServerApproveEntities(
ImmutableSet.of(VKey.create(BillingEvent.OneTime.class, 1)))
.setTransferRequestTime(fakeClock.nowUtc())
.setTransferStatus(TransferStatus.SERVER_APPROVED)
.setTransferRequestTrid(Trid.create("client-trid", "server-trid"))
@@ -64,7 +64,7 @@ public class ReservedListSqlDaoTest {
}
@Test
public void save_worksSuccessfully() {
void save_worksSuccessfully() {
ReservedListSqlDao.save(testReservedList);
jpaTm()
.transact(
@@ -82,14 +82,14 @@ public class ReservedListSqlDaoTest {
}
@Test
public void checkExists_worksSuccessfully() {
void checkExists_worksSuccessfully() {
assertThat(ReservedListSqlDao.checkExists("testlist")).isFalse();
ReservedListSqlDao.save(testReservedList);
assertThat(ReservedListSqlDao.checkExists("testlist")).isTrue();
}
@Test
public void getLatestRevision_worksSuccessfully() {
void getLatestRevision_worksSuccessfully() {
assertThat(ReservedListSqlDao.getLatestRevision("testlist").isPresent()).isFalse();
ReservedListSqlDao.save(testReservedList);
ReservedList persistedList = ReservedListSqlDao.getLatestRevision("testlist").get();
@@ -101,7 +101,7 @@ public class ReservedListSqlDaoTest {
}
@Test
public void getLatestRevision_returnsLatestRevision() {
void getLatestRevision_returnsLatestRevision() {
ReservedListSqlDao.save(
new ReservedList.Builder()
.setName("testlist")
@@ -18,10 +18,13 @@ import static com.google.common.truth.Truth.assertThat;
import static org.joda.time.DateTimeZone.UTC;
import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key;
import google.registry.model.billing.BillingEvent;
import google.registry.model.domain.DomainBase;
import google.registry.model.domain.Period;
import google.registry.model.eppcommon.Trid;
import google.registry.model.poll.PollMessage;
import google.registry.model.reporting.HistoryEntry;
import google.registry.persistence.VKey;
import google.registry.testing.AppEngineExtension;
import org.joda.time.DateTime;
@@ -46,11 +49,33 @@ public class TransferDataTest {
@BeforeEach
void beforeEach() {
transferBillingEventKey = VKey.create(BillingEvent.OneTime.class, 12345);
otherServerApproveBillingEventKey = VKey.create(BillingEvent.Cancellation.class, 2468);
recurringBillingEventKey = VKey.create(BillingEvent.Recurring.class, 13579);
autorenewPollMessageKey = VKey.create(PollMessage.Autorenew.class, 67890);
otherServerApprovePollMessageKey = VKey.create(PollMessage.OneTime.class, 314159);
Key<HistoryEntry> historyEntryKey =
Key.create(Key.create(DomainBase.class, "4-TLD"), HistoryEntry.class, 1356L);
transferBillingEventKey =
VKey.create(
BillingEvent.OneTime.class,
12345,
Key.create(historyEntryKey, BillingEvent.OneTime.class, 12345));
otherServerApproveBillingEventKey =
VKey.create(
BillingEvent.Cancellation.class,
2468,
Key.create(historyEntryKey, BillingEvent.Cancellation.class, 2468));
recurringBillingEventKey =
VKey.create(
BillingEvent.Recurring.class,
13579,
Key.create(historyEntryKey, BillingEvent.Recurring.class, 13579));
autorenewPollMessageKey =
VKey.create(
PollMessage.Autorenew.class,
67890,
Key.create(historyEntryKey, PollMessage.Autorenew.class, 67890));
otherServerApprovePollMessageKey =
VKey.create(
PollMessage.OneTime.class,
314159,
Key.create(historyEntryKey, PollMessage.OneTime.class, 314159));
}
@Test
@@ -14,8 +14,12 @@
package google.registry.persistence;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.googlecode.objectify.Key;
import google.registry.model.billing.BillingEvent.OneTime;
import google.registry.model.registrar.RegistrarContact;
import google.registry.testing.AppEngineExtension;
import google.registry.testing.TestObject;
import org.junit.jupiter.api.Test;
@@ -37,7 +41,22 @@ class VKeyTest {
VKey.create(TestObject.class, "foo", Key.create(TestObject.create("foo")));
assertThat(key.maybeGetSqlKey().isPresent()).isTrue();
assertThat(key.maybeGetOfyKey().isPresent()).isTrue();
assertThat(VKey.createSql(TestObject.class, "foo").maybeGetSqlKey()).hasValue("foo");
}
assertThat(VKey.createSql(TestObject.class, "foo").maybeGetSqlKey().get()).isEqualTo("foo");
@Test
void testCreateById_failsWhenParentIsNullButShouldntBe() {
IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> VKey.create(OneTime.class, 134L));
assertThat(thrown).hasMessageThat().contains("BackupGroupRoot");
}
@Test
void testCreateByName_failsWhenParentIsNullButShouldntBe() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
() -> VKey.create(RegistrarContact.class, "fake@example.com"));
assertThat(thrown).hasMessageThat().contains("BackupGroupRoot");
}
}
@@ -0,0 +1,87 @@
// 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.
package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.domain.token.AllocationToken.TokenStatus.ENDED;
import static google.registry.model.domain.token.AllocationToken.TokenStatus.NOT_STARTED;
import static google.registry.model.domain.token.AllocationToken.TokenStatus.VALID;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import com.google.common.collect.ImmutableSortedMap;
import google.registry.model.ImmutableObject;
import google.registry.model.common.TimedTransitionProperty;
import google.registry.model.domain.token.AllocationToken.TokenStatus;
import google.registry.model.domain.token.AllocationToken.TokenStatusTransition;
import google.registry.persistence.transaction.JpaTestRules;
import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension;
import javax.persistence.Entity;
import javax.persistence.Id;
import org.joda.time.DateTime;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link AllocationTokenStatusTransitionConverter}. */
public class AllocationTokenStatusTransitionConverterTest {
@RegisterExtension
public final JpaUnitTestExtension jpa =
new JpaTestRules.Builder()
.withInitScript("sql/flyway/V14__load_extension_for_hstore.sql")
.withEntityClass(AllocationTokenStatusTransitionConverterTestEntity.class)
.buildUnitTestRule();
private static final ImmutableSortedMap<DateTime, TokenStatus> values =
ImmutableSortedMap.of(
START_OF_TIME,
NOT_STARTED,
DateTime.parse("2001-01-01T00:00:00.0Z"),
VALID,
DateTime.parse("2002-01-01T00:00:00.0Z"),
ENDED);
@Test
void roundTripConversion_returnsSameTimedTransitionProperty() {
TimedTransitionProperty<TokenStatus, TokenStatusTransition> timedTransitionProperty =
TimedTransitionProperty.fromValueMap(values, TokenStatusTransition.class);
AllocationTokenStatusTransitionConverterTestEntity testEntity =
new AllocationTokenStatusTransitionConverterTestEntity(timedTransitionProperty);
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
AllocationTokenStatusTransitionConverterTestEntity persisted =
jpaTm()
.transact(
() ->
jpaTm()
.getEntityManager()
.find(AllocationTokenStatusTransitionConverterTestEntity.class, "id"));
assertThat(persisted.timedTransitionProperty).containsExactlyEntriesIn(timedTransitionProperty);
}
@Entity
private static class AllocationTokenStatusTransitionConverterTestEntity extends ImmutableObject {
@Id String name = "id";
TimedTransitionProperty<TokenStatus, TokenStatusTransition> timedTransitionProperty;
private AllocationTokenStatusTransitionConverterTestEntity() {}
private AllocationTokenStatusTransitionConverterTestEntity(
TimedTransitionProperty<TokenStatus, TokenStatusTransition> timedTransitionProperty) {
this.timedTransitionProperty = timedTransitionProperty;
}
}
}
@@ -38,7 +38,7 @@ public class DurationConverterTest {
private final DurationConverter converter = new DurationConverter();
@Test
public void testNulls() {
void testNulls() {
assertThat(converter.convertToDatabaseColumn(null)).isEqualTo(new PGInterval());
assertThat(converter.convertToEntityAttribute(new PGInterval())).isNull();
}
@@ -140,7 +140,7 @@ class JpaTransactionManagerImplTest {
}
@Test
public void transact_retriesOptimisticLockExceptions() {
void transact_retriesOptimisticLockExceptions() {
JpaTransactionManager spyJpaTm = spy(jpaTm());
doThrow(OptimisticLockException.class).when(spyJpaTm).delete(any(VKey.class));
spyJpaTm.transact(() -> spyJpaTm.saveNew(theEntity));
@@ -159,7 +159,7 @@ class JpaTransactionManagerImplTest {
}
@Test
public void transactNoRetry_doesNotRetryOptimisticLockException() {
void transactNoRetry_doesNotRetryOptimisticLockException() {
JpaTransactionManager spyJpaTm = spy(jpaTm());
doThrow(OptimisticLockException.class).when(spyJpaTm).delete(any(VKey.class));
spyJpaTm.transactNoRetry(() -> spyJpaTm.saveNew(theEntity));
@@ -178,7 +178,7 @@ class JpaTransactionManagerImplTest {
}
@Test
public void transact_retriesNestedOptimisticLockExceptions() {
void transact_retriesNestedOptimisticLockExceptions() {
JpaTransactionManager spyJpaTm = spy(jpaTm());
doThrow(new RuntimeException().initCause(new OptimisticLockException()))
.when(spyJpaTm)
@@ -198,7 +198,7 @@ class JpaTransactionManagerImplTest {
}
@Test
public void transactNewReadOnly_retriesJdbcConnectionExceptions() {
void transactNewReadOnly_retriesJdbcConnectionExceptions() {
JpaTransactionManager spyJpaTm = spy(jpaTm());
doThrow(JDBCConnectionException.class).when(spyJpaTm).load(any(VKey.class));
spyJpaTm.transact(() -> spyJpaTm.saveNew(theEntity));
@@ -217,7 +217,7 @@ class JpaTransactionManagerImplTest {
}
@Test
public void transactNewReadOnly_retriesNestedJdbcConnectionExceptions() {
void transactNewReadOnly_retriesNestedJdbcConnectionExceptions() {
JpaTransactionManager spyJpaTm = spy(jpaTm());
doThrow(
new RuntimeException()
@@ -240,7 +240,7 @@ class JpaTransactionManagerImplTest {
}
@Test
public void doTransactionless_retriesJdbcConnectionExceptions() {
void doTransactionless_retriesJdbcConnectionExceptions() {
JpaTransactionManager spyJpaTm = spy(jpaTm());
doThrow(JDBCConnectionException.class).when(spyJpaTm).load(any(VKey.class));
spyJpaTm.transact(() -> spyJpaTm.saveNew(theEntity));
@@ -34,28 +34,26 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
public class TransactionTest {
class TransactionTest {
@RegisterExtension
public final AppEngineExtension appEngine =
final AppEngineExtension appEngine =
AppEngineExtension.builder()
.withDatastoreAndCloudSql()
.withOfyTestEntities(TestEntity.class)
.withJpaUnitTestEntities(TestEntity.class)
.build();
TestEntity fooEntity, barEntity;
public TransactionTest() {}
private TestEntity fooEntity, barEntity;
@BeforeEach
public void setUp() {
void beforeEach() {
fooEntity = new TestEntity("foo");
barEntity = new TestEntity("bar");
}
@Test
public void testTransactionReplay() {
void testTransactionReplay() {
Transaction txn = new Transaction.Builder().addUpdate(fooEntity).addUpdate(barEntity).build();
txn.writeToDatastore();
@@ -72,7 +70,7 @@ public class TransactionTest {
}
@Test
public void testSerialization() throws Exception {
void testSerialization() throws Exception {
Transaction txn = new Transaction.Builder().addUpdate(barEntity).build();
txn.writeToDatastore();
@@ -90,7 +88,7 @@ public class TransactionTest {
}
@Test
public void testDeserializationErrors() throws Exception {
void testDeserializationErrors() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(baos);
out.writeInt(12345);
@@ -103,7 +101,7 @@ public class TransactionTest {
}
@Test
public void testTransactionSerialization() throws IOException {
void testTransactionSerialization() throws IOException {
RegistryConfig.overrideCloudSqlReplicateTransactions(true);
try {
jpaTm()
@@ -134,7 +132,7 @@ public class TransactionTest {
}
@Test
public void testTransactionSerializationDisabledByDefault() {
void testTransactionSerializationDisabledByDefault() {
jpaTm()
.transact(
() -> {
@@ -61,7 +61,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link RdeStagingReducer}. */
public class RdeStagingReducerTest {
class RdeStagingReducerTest {
@RegisterExtension
AppEngineExtension appEngineRule =
@@ -103,7 +103,7 @@ public class RdeStagingReducerTest {
ValidationMode.STRICT);
@BeforeEach
public void setUp() {
void beforeEach() {
createTld("soy");
CursorDao.saveCursor(Cursor.create(CursorType.BRDA, now, Registry.get("soy")), "soy");
CursorDao.saveCursor(Cursor.create(CursorType.RDE_STAGING, now, Registry.get("soy")), "soy");
@@ -115,7 +115,7 @@ public class RdeStagingReducerTest {
}
@Test
public void testSuccess_BRDA() throws Exception {
void testSuccess_BRDA() throws Exception {
key = PendingDeposit.create("soy", now, THIN, CursorType.BRDA, Duration.standardDays(1));
reducer.reduce(key, brdaFragments);
String outputFile = decryptGhostrydeGcsFile("soy_2000-01-01_thin_S1_R1.xml.ghostryde");
@@ -143,7 +143,7 @@ public class RdeStagingReducerTest {
}
@Test
public void testSuccess_BRDA_manual() throws Exception {
void testSuccess_BRDA_manual() throws Exception {
key = PendingDeposit.createInManualOperation("soy", now, THIN, "", 0);
reducer.reduce(key, brdaFragments);
String outputFile = decryptGhostrydeGcsFile("manual/soy_2000-01-01_thin_S1_R0.xml.ghostryde");
@@ -167,7 +167,7 @@ public class RdeStagingReducerTest {
}
@Test
public void testSuccess_RDE() throws Exception {
void testSuccess_RDE() throws Exception {
key = PendingDeposit.create("soy", now, FULL, CursorType.RDE_STAGING, Duration.standardDays(1));
reducer.reduce(key, rdeFragments);
String outputFile = decryptGhostrydeGcsFile("soy_2000-01-01_full_S1_R1.xml.ghostryde");
@@ -189,7 +189,7 @@ public class RdeStagingReducerTest {
}
@Test
public void testSuccess_RDE_manual() throws Exception {
void testSuccess_RDE_manual() throws Exception {
key = PendingDeposit.createInManualOperation("soy", now, FULL, "", 0);
reducer.reduce(key, rdeFragments);
String outputFile = decryptGhostrydeGcsFile("manual/soy_2000-01-01_full_S1_R0.xml.ghostryde");
@@ -42,7 +42,7 @@ public class CursorDaoTest {
private final Logger loggerToIntercept = Logger.getLogger(CursorDao.class.getCanonicalName());
@RegisterExtension
public final AppEngineExtension appEngine =
final AppEngineExtension appEngine =
AppEngineExtension.builder()
.withDatastoreAndCloudSql()
.enableJpaEntityCoverageCheck(true)
@@ -50,7 +50,7 @@ public class CursorDaoTest {
.build();
@Test
public void save_worksSuccessfullyOnNewCursor() {
void save_worksSuccessfullyOnNewCursor() {
Cursor cursor = Cursor.create(CursorType.BRDA, "tld", fakeClock.nowUtc());
CursorDao.save(cursor);
Cursor returnedCursor = CursorDao.load(CursorType.BRDA, "tld");
@@ -58,7 +58,7 @@ public class CursorDaoTest {
}
@Test
public void save_worksSuccessfullyOnExistingCursor() {
void save_worksSuccessfullyOnExistingCursor() {
Cursor cursor = Cursor.create(CursorType.RDE_REPORT, "tld", fakeClock.nowUtc());
CursorDao.save(cursor);
Cursor cursor2 = Cursor.create(CursorType.RDE_REPORT, "tld", fakeClock.nowUtc().plusDays(3));
@@ -68,7 +68,7 @@ public class CursorDaoTest {
}
@Test
public void save_worksSuccessfullyOnNewGlobalCursor() {
void save_worksSuccessfullyOnNewGlobalCursor() {
Cursor cursor = Cursor.createGlobal(CursorType.RECURRING_BILLING, fakeClock.nowUtc());
CursorDao.save(cursor);
Cursor returnedCursor = CursorDao.load(CursorType.RECURRING_BILLING);
@@ -76,7 +76,7 @@ public class CursorDaoTest {
}
@Test
public void save_worksSuccessfullyOnExistingGlobalCursor() {
void save_worksSuccessfullyOnExistingGlobalCursor() {
Cursor cursor = Cursor.createGlobal(CursorType.RECURRING_BILLING, fakeClock.nowUtc());
CursorDao.save(cursor);
Cursor cursor2 =
@@ -87,7 +87,7 @@ public class CursorDaoTest {
}
@Test
public void saveAll_worksSuccessfully() {
void saveAll_worksSuccessfully() {
Cursor cursor = Cursor.createGlobal(CursorType.RECURRING_BILLING, fakeClock.nowUtc());
Cursor cursor2 = Cursor.create(CursorType.RDE_REPORT, "tld", fakeClock.nowUtc());
ImmutableSet<Cursor> cursors = ImmutableSet.<Cursor>builder().add(cursor, cursor2).build();
@@ -98,13 +98,13 @@ public class CursorDaoTest {
}
@Test
public void saveAll_worksSuccessfullyEmptySet() {
void saveAll_worksSuccessfullyEmptySet() {
CursorDao.saveAll(ImmutableSet.of());
assertThat(CursorDao.loadAll()).isEmpty();
}
@Test
public void load_worksSuccessfully() {
void load_worksSuccessfully() {
Cursor cursor = Cursor.createGlobal(CursorType.RECURRING_BILLING, fakeClock.nowUtc());
Cursor cursor2 = Cursor.create(CursorType.RDE_REPORT, "tld", fakeClock.nowUtc());
Cursor cursor3 = Cursor.create(CursorType.RDE_REPORT, "foo", fakeClock.nowUtc());
@@ -119,7 +119,7 @@ public class CursorDaoTest {
}
@Test
public void loadAll_worksSuccessfully() {
void loadAll_worksSuccessfully() {
Cursor cursor = Cursor.createGlobal(CursorType.RECURRING_BILLING, fakeClock.nowUtc());
Cursor cursor2 = Cursor.create(CursorType.RDE_REPORT, "tld", fakeClock.nowUtc());
Cursor cursor3 = Cursor.create(CursorType.RDE_REPORT, "foo", fakeClock.nowUtc());
@@ -130,13 +130,13 @@ public class CursorDaoTest {
}
@Test
public void loadAll_worksSuccessfullyEmptyTable() {
void loadAll_worksSuccessfullyEmptyTable() {
List<Cursor> returnedCursors = CursorDao.loadAll();
assertThat(returnedCursors.size()).isEqualTo(0);
}
@Test
public void loadByType_worksSuccessfully() {
void loadByType_worksSuccessfully() {
Cursor cursor = Cursor.createGlobal(CursorType.RECURRING_BILLING, fakeClock.nowUtc());
Cursor cursor2 = Cursor.create(CursorType.RDE_REPORT, "tld", fakeClock.nowUtc());
Cursor cursor3 = Cursor.create(CursorType.RDE_REPORT, "foo", fakeClock.nowUtc());
@@ -147,13 +147,13 @@ public class CursorDaoTest {
}
@Test
public void loadByType_worksSuccessfullyNoneOfType() {
void loadByType_worksSuccessfullyNoneOfType() {
List<Cursor> returnedCursors = CursorDao.loadByType(CursorType.RDE_REPORT);
assertThat(returnedCursors.size()).isEqualTo(0);
}
@Test
public void saveCursor_worksSuccessfully() {
void saveCursor_worksSuccessfully() {
createTld("tld");
google.registry.model.common.Cursor cursor =
google.registry.model.common.Cursor.create(
@@ -172,7 +172,7 @@ public class CursorDaoTest {
}
@Test
public void saveCursor_worksSuccessfullyOnGlobalCursor() {
void saveCursor_worksSuccessfullyOnGlobalCursor() {
google.registry.model.common.Cursor cursor =
google.registry.model.common.Cursor.createGlobal(
CursorType.RECURRING_BILLING, fakeClock.nowUtc());
@@ -188,7 +188,7 @@ public class CursorDaoTest {
}
@Test
public void saveCursors_worksSuccessfully() {
void saveCursors_worksSuccessfully() {
createTlds("tld", "foo");
google.registry.model.common.Cursor cursor1 =
google.registry.model.common.Cursor.create(
@@ -237,7 +237,7 @@ public class CursorDaoTest {
}
@Test
public void loadAndCompare_worksSuccessfully() {
void loadAndCompare_worksSuccessfully() {
loggerToIntercept.addHandler(logHandler);
createTld("tld");
google.registry.model.common.Cursor cursor =
@@ -249,7 +249,7 @@ public class CursorDaoTest {
}
@Test
public void loadAndCompare_worksSuccessfullyGlobalCursor() {
void loadAndCompare_worksSuccessfullyGlobalCursor() {
loggerToIntercept.addHandler(logHandler);
google.registry.model.common.Cursor cursor =
google.registry.model.common.Cursor.createGlobal(
@@ -260,7 +260,7 @@ public class CursorDaoTest {
}
@Test
public void loadAndCompare_worksSuccessfullyCursorNotInCloudSql() {
void loadAndCompare_worksSuccessfullyCursorNotInCloudSql() {
loggerToIntercept.addHandler(logHandler);
createTld("tld");
google.registry.model.common.Cursor cursor =
@@ -275,7 +275,7 @@ public class CursorDaoTest {
}
@Test
public void loadAndCompare_worksSuccessfullyGlobalCursorNotInCloudSql() {
void loadAndCompare_worksSuccessfullyGlobalCursorNotInCloudSql() {
loggerToIntercept.addHandler(logHandler);
google.registry.model.common.Cursor cursor =
google.registry.model.common.Cursor.createGlobal(
@@ -289,7 +289,7 @@ public class CursorDaoTest {
}
@Test
public void loadAndCompare_worksSuccessfullyCursorsNotEqual() {
void loadAndCompare_worksSuccessfullyCursorsNotEqual() {
loggerToIntercept.addHandler(logHandler);
createTld("tld");
google.registry.model.common.Cursor cursor =
@@ -310,7 +310,7 @@ public class CursorDaoTest {
}
@Test
public void loadAndCompareAll_worksSuccessfully() {
void loadAndCompareAll_worksSuccessfully() {
loggerToIntercept.addHandler(logHandler);
// Create Datastore cursors
@@ -335,7 +335,7 @@ public class CursorDaoTest {
}
@Test
public void loadAndCompareAll_worksSuccessfullyMissingOne() {
void loadAndCompareAll_worksSuccessfullyMissingOne() {
loggerToIntercept.addHandler(logHandler);
// Create Datastore cursors
@@ -371,7 +371,7 @@ public class CursorDaoTest {
}
@Test
public void loadAndCompareAll_worksSuccessfullyOneWithWrongTime() {
void loadAndCompareAll_worksSuccessfullyOneWithWrongTime() {
loggerToIntercept.addHandler(logHandler);
// Create Datastore cursors
@@ -404,7 +404,7 @@ public class CursorDaoTest {
}
@Test
public void loadAndCompareAll_worksSuccessfullyEmptyMap() {
void loadAndCompareAll_worksSuccessfullyEmptyMap() {
loggerToIntercept.addHandler(logHandler);
CursorDao.loadAndCompareAll(ImmutableMap.of(), CursorType.ICANN_UPLOAD_ACTIVITY);
assertAboutLogs().that(logHandler).hasNoLogsAtLevel(Level.WARNING);
@@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assert_;
import google.registry.model.billing.BillingEventTest;
import google.registry.model.contact.ContactResourceTest;
import google.registry.model.domain.DomainBaseSqlTest;
import google.registry.model.domain.token.AllocationTokenTest;
import google.registry.model.history.ContactHistoryTest;
import google.registry.model.history.DomainHistoryTest;
import google.registry.model.history.HostHistoryTest;
@@ -72,6 +73,7 @@ import org.junit.runner.RunWith;
@SelectClasses({
// BeforeSuiteTest must be the first entry. See class javadoc for details.
BeforeSuiteTest.class,
AllocationTokenTest.class,
BillingEventTest.class,
ClaimsListDaoTest.class,
ContactHistoryTest.class,
@@ -0,0 +1,73 @@
// 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.
package google.registry.schema.registrar;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.registrar.RegistrarContact.Type.WHOIS;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.SqlHelper.saveRegistrar;
import com.google.common.collect.ImmutableSet;
import google.registry.model.registrar.Registrar;
import google.registry.model.registrar.RegistrarContact;
import google.registry.persistence.transaction.JpaTestRules;
import google.registry.persistence.transaction.JpaTestRules.JpaIntegrationWithCoverageExtension;
import google.registry.testing.DatastoreEntityExtension;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for persisting {@link RegistrarContact} entities. */
class RegistrarContactTest {
@RegisterExtension
@Order(value = 1)
DatastoreEntityExtension datastoreEntityExtension = new DatastoreEntityExtension();
@RegisterExtension
JpaIntegrationWithCoverageExtension jpa =
new JpaTestRules.Builder().buildIntegrationWithCoverageExtension();
private Registrar testRegistrar;
private RegistrarContact testRegistrarPoc;
@BeforeEach
public void beforeEach() {
testRegistrar = saveRegistrar("registrarId");
testRegistrarPoc =
new RegistrarContact.Builder()
.setParent(testRegistrar)
.setName("Judith Registrar")
.setEmailAddress("judith.doe@example.com")
.setRegistryLockEmailAddress("judith.doe@external.com")
.setPhoneNumber("+1.2125650000")
.setFaxNumber("+1.2125650001")
.setTypes(ImmutableSet.of(WHOIS))
.setVisibleInWhoisAsAdmin(true)
.setVisibleInWhoisAsTech(false)
.setVisibleInDomainWhoisAsAbuse(false)
.build();
}
@Test
void testPersistence_succeeds() {
jpaTm().transact(() -> jpaTm().saveNew(testRegistrarPoc));
RegistrarContact persisted =
jpaTm().transact(() -> jpaTm().load(testRegistrarPoc.createVKey()));
assertThat(persisted).isEqualTo(testRegistrarPoc);
}
}
@@ -39,14 +39,14 @@ public class LockDaoTest {
@RegisterExtension
@Order(value = 1)
public DatastoreEntityExtension datastoreEntityExtension = new DatastoreEntityExtension();
DatastoreEntityExtension datastoreEntityExtension = new DatastoreEntityExtension();
@RegisterExtension
public final JpaIntegrationWithCoverageExtension jpa =
final JpaIntegrationWithCoverageExtension jpa =
new JpaTestRules.Builder().withClock(fakeClock).buildIntegrationWithCoverageExtension();
@Test
public void save_worksSuccessfully() {
void save_worksSuccessfully() {
Lock lock =
Lock.create("testResource", "tld", "testLogId", fakeClock.nowUtc(), Duration.millis(2));
LockDao.save(lock);
@@ -56,7 +56,7 @@ public class LockDaoTest {
}
@Test
public void save_succeedsWhenLockAlreadyExists() {
void save_succeedsWhenLockAlreadyExists() {
Lock lock =
Lock.create("testResource", "tld", "testLogId", fakeClock.nowUtc(), Duration.millis(2));
LockDao.save(lock);
@@ -67,7 +67,7 @@ public class LockDaoTest {
}
@Test
public void save_worksSuccesfullyGlobalLock() {
void save_worksSuccesfullyGlobalLock() {
Lock lock =
Lock.createGlobal("testResource", "testLogId", fakeClock.nowUtc(), Duration.millis(2));
LockDao.save(lock);
@@ -77,7 +77,7 @@ public class LockDaoTest {
}
@Test
public void load_worksSuccessfully() {
void load_worksSuccessfully() {
Lock lock =
Lock.create("testResource", "tld", "testLogId", fakeClock.nowUtc(), Duration.millis(2));
LockDao.save(lock);
@@ -87,7 +87,7 @@ public class LockDaoTest {
}
@Test
public void load_worksSuccessfullyGlobalLock() {
void load_worksSuccessfullyGlobalLock() {
Lock lock =
Lock.createGlobal("testResource", "testLogId", fakeClock.nowUtc(), Duration.millis(2));
LockDao.save(lock);
@@ -97,13 +97,13 @@ public class LockDaoTest {
}
@Test
public void load_worksSuccesfullyLockDoesNotExist() {
void load_worksSuccesfullyLockDoesNotExist() {
Optional<Lock> returnedLock = LockDao.load("testResource", "tld");
assertThat(returnedLock.isPresent()).isFalse();
}
@Test
public void delete_worksSuccesfully() {
void delete_worksSuccesfully() {
Lock lock =
Lock.create("testResource", "tld", "testLogId", fakeClock.nowUtc(), Duration.millis(2));
LockDao.save(lock);
@@ -115,7 +115,7 @@ public class LockDaoTest {
}
@Test
public void delete_worksSuccessfullyGlobalLock() {
void delete_worksSuccessfullyGlobalLock() {
Lock lock =
Lock.createGlobal("testResource", "testLogId", fakeClock.nowUtc(), Duration.millis(2));
LockDao.save(lock);
@@ -127,12 +127,12 @@ public class LockDaoTest {
}
@Test
public void delete_succeedsLockDoesntExist() {
void delete_succeedsLockDoesntExist() {
LockDao.delete("testResource");
}
@Test
public void compare_logsWarningWhenCloudSqlLockMissing() {
void compare_logsWarningWhenCloudSqlLockMissing() {
loggerToIntercept.addHandler(logHandler);
google.registry.model.server.Lock datastoreLock =
google.registry.model.server.Lock.create(
@@ -146,7 +146,7 @@ public class LockDaoTest {
}
@Test
public void compare_logsWarningWhenCloudSqlLockExistsWhenItShouldNot() {
void compare_logsWarningWhenCloudSqlLockExistsWhenItShouldNot() {
loggerToIntercept.addHandler(logHandler);
Lock lock =
Lock.createGlobal("testResource", "testLogId", fakeClock.nowUtc(), Duration.millis(2));
@@ -159,7 +159,7 @@ public class LockDaoTest {
}
@Test
public void compare_logsWarningWhenLocksDontMatch() {
void compare_logsWarningWhenLocksDontMatch() {
loggerToIntercept.addHandler(logHandler);
Lock cloudSqlLock =
Lock.create("testResource", "tld", "testLogId", fakeClock.nowUtc(), Duration.millis(2));
@@ -46,7 +46,7 @@ public class PremiumListDaoTest {
private final FakeClock fakeClock = new FakeClock();
@RegisterExtension
public final AppEngineExtension appEngine =
final AppEngineExtension appEngine =
AppEngineExtension.builder()
.withDatastoreAndCloudSql()
.enableJpaEntityCoverageCheck(true)
@@ -58,7 +58,7 @@ public class PremiumListDaoTest {
private PremiumList testList;
@BeforeEach
void setUp() {
void beforeEach() {
testPrices =
ImmutableMap.of(
"silver",
@@ -77,7 +77,7 @@ public class PremiumListDaoTest {
}
@Test
public void saveNew_worksSuccessfully() {
void saveNew_worksSuccessfully() {
PremiumListDao.saveNew(testList);
jpaTm()
.transact(
@@ -91,7 +91,7 @@ public class PremiumListDaoTest {
}
@Test
public void update_worksSuccessfully() {
void update_worksSuccessfully() {
PremiumListDao.saveNew(testList);
Optional<PremiumList> persistedList = PremiumListDao.getLatestRevision("testname");
assertThat(persistedList).isPresent();
@@ -132,7 +132,7 @@ public class PremiumListDaoTest {
}
@Test
public void saveNew_throwsWhenPremiumListAlreadyExists() {
void saveNew_throwsWhenPremiumListAlreadyExists() {
PremiumListDao.saveNew(testList);
IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> PremiumListDao.saveNew(testList));
@@ -142,7 +142,7 @@ public class PremiumListDaoTest {
// TODO(b/147246613): Un-ignore this.
@Test
@Disabled
public void update_throwsWhenListDoesntExist() {
void update_throwsWhenListDoesntExist() {
IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> PremiumListDao.update(testList));
assertThat(thrown)
@@ -151,19 +151,19 @@ public class PremiumListDaoTest {
}
@Test
public void checkExists_worksSuccessfully() {
void checkExists_worksSuccessfully() {
assertThat(PremiumListDao.checkExists("testname")).isFalse();
PremiumListDao.saveNew(testList);
assertThat(PremiumListDao.checkExists("testname")).isTrue();
}
@Test
public void getLatestRevision_returnsEmptyForNonexistentList() {
void getLatestRevision_returnsEmptyForNonexistentList() {
assertThat(PremiumListDao.getLatestRevision("nonexistentlist")).isEmpty();
}
@Test
public void getLatestRevision_worksSuccessfully() {
void getLatestRevision_worksSuccessfully() {
PremiumListDao.saveNew(
new PremiumList.Builder()
.setName("list1")
@@ -191,13 +191,13 @@ public class PremiumListDaoTest {
}
@Test
public void getPremiumPrice_returnsNoneWhenNoPremiumListConfigured() {
void getPremiumPrice_returnsNoneWhenNoPremiumListConfigured() {
persistResource(newRegistry("foobar", "FOOBAR").asBuilder().setPremiumList(null).build());
assertThat(PremiumListDao.getPremiumPrice("rich", Registry.get("foobar"))).isEmpty();
}
@Test
public void getPremiumPrice_worksSuccessfully() {
void getPremiumPrice_worksSuccessfully() {
persistResource(
newRegistry("foobar", "FOOBAR")
.asBuilder()
@@ -222,7 +222,7 @@ public class PremiumListDaoTest {
}
@Test
public void testGetPremiumPrice_throwsWhenPremiumListCantBeLoaded() {
void testGetPremiumPrice_throwsWhenPremiumListCantBeLoaded() {
createTld("tld");
IllegalStateException thrown =
assertThrows(
@@ -232,7 +232,7 @@ public class PremiumListDaoTest {
}
@Test
public void testGetPremiumPrice_worksForJPY() {
void testGetPremiumPrice_worksForJPY() {
persistResource(
newRegistry("foobar", "FOOBAR")
.asBuilder()
@@ -27,10 +27,10 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link PremiumList}. */
public class PremiumListTest {
class PremiumListTest {
@RegisterExtension
public DatastoreEntityExtension datastoreEntityExtension = new DatastoreEntityExtension();
DatastoreEntityExtension datastoreEntityExtension = new DatastoreEntityExtension();
private static final ImmutableMap<String, BigDecimal> TEST_PRICES =
ImmutableMap.of(
@@ -42,7 +42,7 @@ public class PremiumListTest {
BigDecimal.valueOf(1552.78));
@Test
public void bloomFilter_worksCorrectly() {
void bloomFilter_worksCorrectly() {
BloomFilter<String> bloomFilter =
new PremiumList.Builder()
.setName("testname")
@@ -31,15 +31,15 @@ public class ClaimsListDaoTest {
private final FakeClock fakeClock = new FakeClock();
@RegisterExtension
public final JpaIntegrationWithCoverageExtension jpa =
final JpaIntegrationWithCoverageExtension jpa =
new JpaTestRules.Builder().withClock(fakeClock).buildIntegrationWithCoverageExtension();
@RegisterExtension
@Order(value = 1)
public final DatastoreEntityExtension datastoreEntityExtension = new DatastoreEntityExtension();
final DatastoreEntityExtension datastoreEntityExtension = new DatastoreEntityExtension();
@Test
public void trySave_insertsClaimsListSuccessfully() {
void trySave_insertsClaimsListSuccessfully() {
ClaimsList claimsList =
ClaimsList.create(fakeClock.nowUtc(), ImmutableMap.of("label1", "key1", "label2", "key2"));
ClaimsListDao.trySave(claimsList);
@@ -49,7 +49,7 @@ public class ClaimsListDaoTest {
}
@Test
public void trySave_noExceptionThrownWhenSaveFail() {
void trySave_noExceptionThrownWhenSaveFail() {
ClaimsList claimsList =
ClaimsList.create(fakeClock.nowUtc(), ImmutableMap.of("label1", "key1", "label2", "key2"));
ClaimsListDao.trySave(claimsList);
@@ -60,7 +60,7 @@ public class ClaimsListDaoTest {
}
@Test
public void trySave_claimsListWithNoEntries() {
void trySave_claimsListWithNoEntries() {
ClaimsList claimsList = ClaimsList.create(fakeClock.nowUtc(), ImmutableMap.of());
ClaimsListDao.trySave(claimsList);
ClaimsList insertedClaimsList = ClaimsListDao.getLatestRevision().get();
@@ -69,12 +69,12 @@ public class ClaimsListDaoTest {
}
@Test
public void getCurrent_returnsEmptyListIfTableIsEmpty() {
void getCurrent_returnsEmptyListIfTableIsEmpty() {
assertThat(ClaimsListDao.getLatestRevision().isPresent()).isFalse();
}
@Test
public void getCurrent_returnsLatestClaims() {
void getCurrent_returnsLatestClaims() {
ClaimsList oldClaimsList =
ClaimsList.create(fakeClock.nowUtc(), ImmutableMap.of("label1", "key1", "label2", "key2"));
ClaimsList newClaimsList =
@@ -17,6 +17,7 @@ package google.registry.testing;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.truth.Fact.fact;
import static com.google.common.truth.Fact.simpleFact;
import static com.google.common.truth.OptionalSubject.optionals;
import static google.registry.model.EppResourceUtils.isActive;
import static google.registry.testing.DatastoreHelper.getHistoryEntriesOfType;
import static google.registry.testing.HistoryEntrySubject.historyEntries;
@@ -32,6 +33,7 @@ import google.registry.model.reporting.HistoryEntry;
import google.registry.testing.TruthChainer.And;
import google.registry.testing.TruthChainer.Which;
import java.util.List;
import java.util.Optional;
import javax.annotation.Nullable;
import org.joda.time.DateTime;
@@ -190,6 +192,16 @@ abstract class AbstractEppResourceSubject<
return andChainer();
}
protected <E> And<S> hasValue(E expected, Optional<E> actual, String name) {
check(name).about(optionals()).that(actual).hasValue(expected);
return andChainer();
}
protected <E> And<S> hasNoValue(Optional<E> actual, String name) {
check(name).about(optionals()).that(actual).isEmpty();
return andChainer();
}
protected <E> And<S> doesNotHaveValue(E badValue, E actual, String name) {
check(name).that(actual).isNotEqualTo(badValue);
return andChainer();
@@ -17,6 +17,7 @@ package google.registry.testing;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.truth.Fact.simpleFact;
import static com.google.common.truth.Truth.assertAbout;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import com.google.common.collect.ImmutableSet;
import com.google.common.truth.FailureMetadata;
@@ -102,6 +103,15 @@ public final class DomainBaseSubject
return hasValue(smdId, actual.getSmdId(), "getSmdId()");
}
public And<DomainBaseSubject> hasAutorenewEndTime(DateTime autorenewEndTime) {
checkArgumentNotNull(autorenewEndTime, "Use hasNoAutorenewEndTime() instead");
return hasValue(autorenewEndTime, actual.getAutorenewEndTime(), "getAutorenewEndTime()");
}
public And<DomainBaseSubject> hasNoAutorenewEndTime() {
return hasNoValue(actual.getAutorenewEndTime(), "getAutorenewEndTime()");
}
public static SimpleSubjectBuilder<DomainBaseSubject, DomainBase> assertAboutDomains() {
return assertAbout(DomainBaseSubject::new);
}
@@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import google.registry.model.registrar.Registrar;
import google.registry.model.registry.RegistryLockDao;
import google.registry.schema.domain.RegistryLock;
import java.sql.SQLException;
@@ -59,10 +60,10 @@ public class SqlHelper {
return jpaTm().transact(() -> RegistryLockDao.getByRevisionId(revisionId));
}
public static void saveRegistrar(String clientId) {
jpaTm()
.transact(
() -> jpaTm().saveNew(makeRegistrar1().asBuilder().setClientId(clientId).build()));
public static Registrar saveRegistrar(String clientId) {
Registrar registrar = makeRegistrar1().asBuilder().setClientId(clientId).build();
jpaTm().transact(() -> jpaTm().saveNew(registrar));
return jpaTm().transact(() -> jpaTm().load(registrar.createVKey()));
}
public static void assertThrowForeignKeyViolation(Executable executable) {
@@ -19,6 +19,7 @@ import static com.google.common.collect.Iterables.toArray;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.joda.time.DateTimeZone.UTC;
import com.beust.jcommander.JCommander;
import com.google.common.base.Joiner;
@@ -41,6 +42,7 @@ import java.io.PrintStream;
import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;
import org.joda.time.DateTime;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -66,7 +68,7 @@ public abstract class CommandTestCase<C extends Command> {
protected C command;
public final FakeClock fakeClock = new FakeClock();
protected final FakeClock fakeClock = new FakeClock(DateTime.now(UTC));
@RegisterExtension
public final AppEngineExtension appEngine =
@@ -17,12 +17,9 @@ package google.registry.tools;
import static google.registry.testing.DatastoreHelper.createTlds;
import static google.registry.testing.DatastoreHelper.persistActiveDomain;
import static google.registry.testing.DatastoreHelper.persistDeletedDomain;
import static org.joda.time.DateTimeZone.UTC;
import google.registry.model.ofy.Ofy;
import google.registry.testing.FakeClock;
import google.registry.testing.InjectExtension;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -30,14 +27,12 @@ import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link CountDomainsCommand}. */
public class CountDomainsCommandTest extends CommandTestCase<CountDomainsCommand> {
protected FakeClock clock = new FakeClock(DateTime.now(UTC));
@RegisterExtension public final InjectExtension inject = new InjectExtension();
@BeforeEach
final void beforeEach() {
inject.setStaticField(Ofy.class, "clock", clock);
command.clock = clock;
inject.setStaticField(Ofy.class, "clock", fakeClock);
command.clock = fakeClock;
createTlds("foo", "bar", "baz", "qux");
}
@@ -55,13 +50,12 @@ public class CountDomainsCommandTest extends CommandTestCase<CountDomainsCommand
@Test
void testSuccess_multipleTlds() throws Exception {
command.clock = clock;
for (int i = 0; i < 29; i++) {
persistActiveDomain(String.format("test-%d.foo", i));
}
for (int j = 0; j < 17; j++) {
persistActiveDomain(String.format("test-%d.baz", j));
persistDeletedDomain(String.format("del-%d.foo", j), clock.nowUtc().minusYears(1));
persistDeletedDomain(String.format("del-%d.foo", j), fakeClock.nowUtc().minusYears(1));
}
persistActiveDomain("not-counted.qux");
runCommand("--tlds=foo,bar,baz");
@@ -18,13 +18,16 @@ import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTlds;
import static google.registry.testing.DatastoreHelper.persistActiveDomain;
import static google.registry.testing.DatastoreHelper.persistResource;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.googlecode.objectify.Key;
import google.registry.model.domain.DomainBase;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.domain.token.AllocationToken.TokenType;
import google.registry.model.reporting.HistoryEntry;
import google.registry.persistence.VKey;
import java.util.Collection;
import javax.annotation.Nullable;
import org.junit.jupiter.api.BeforeEach;
@@ -167,12 +170,15 @@ class DeleteAllocationTokensCommandTest extends CommandTestCase<DeleteAllocation
.setTokenType(SINGLE_USE)
.setDomainName(domainName);
if (redeemed) {
builder.setRedemptionHistoryEntry(Key.create(HistoryEntry.class, 1051L));
String domainToPersist = domainName != null ? domainName : "example.foo";
DomainBase domain = persistActiveDomain(domainToPersist);
Key<HistoryEntry> historyEntryKey = Key.create(Key.create(domain), HistoryEntry.class, 1051L);
builder.setRedemptionHistoryEntry(VKey.create(HistoryEntry.class, 1051L, historyEntryKey));
}
return persistResource(builder.build());
}
private static Collection<AllocationToken> reloadTokens(AllocationToken ... tokens) {
private static Collection<AllocationToken> reloadTokens(AllocationToken... tokens) {
return ofy().load().entities(tokens).values();
}
}
@@ -37,10 +37,10 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.Iterables;
import com.google.common.io.Files;
import com.googlecode.objectify.Key;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.domain.token.AllocationToken.TokenStatus;
import google.registry.model.reporting.HistoryEntry;
import google.registry.persistence.VKey;
import google.registry.testing.DeterministicStringGenerator;
import google.registry.testing.DeterministicStringGenerator.Rule;
import google.registry.testing.FakeClock;
@@ -168,7 +168,7 @@ class GenerateAllocationTokensCommandTest extends CommandTestCase<GenerateAlloca
new AllocationToken.Builder()
.setToken("promo123456789ABCDEFG")
.setTokenType(UNLIMITED_USE)
.setAllowedClientIds(ImmutableSet.of("TheRegistrar", "NewRegistrar"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar", "NewRegistrar"))
.setAllowedTlds(ImmutableSet.of("tld", "example"))
.setDiscountFraction(0.5)
.setDiscountPremiums(true)
@@ -314,7 +314,7 @@ class GenerateAllocationTokensCommandTest extends CommandTestCase<GenerateAlloca
private AllocationToken createToken(
String token,
@Nullable Key<HistoryEntry> redemptionHistoryEntry,
@Nullable VKey<HistoryEntry> redemptionHistoryEntry,
@Nullable String domainName) {
AllocationToken.Builder builder =
new AllocationToken.Builder().setToken(token).setTokenType(SINGLE_USE);
@@ -28,6 +28,7 @@ import com.google.common.collect.ImmutableList;
import com.googlecode.objectify.Key;
import google.registry.model.domain.DomainBase;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.reporting.HistoryEntry;
import org.joda.time.DateTime;
import org.junit.jupiter.api.Test;
@@ -83,7 +84,8 @@ class GetAllocationTokenCommandTest extends CommandTestCase<GetAllocationTokenCo
.setToken("foo")
.setTokenType(SINGLE_USE)
.setDomainName("fqqdn.tld")
.setRedemptionHistoryEntry(Key.create(createHistoryEntryForEppResource(domain)))
.setRedemptionHistoryEntry(
HistoryEntry.createVKey(Key.create(createHistoryEntryForEppResource(domain))))
.build());
runCommand("foo");
assertInStdout(
@@ -55,9 +55,9 @@ class UpdateAllocationTokensCommandTest extends CommandTestCase<UpdateAllocation
void testUpdateClientIds_setClientIds() throws Exception {
AllocationToken token =
persistResource(
builderWithPromo().setAllowedClientIds(ImmutableSet.of("toRemove")).build());
builderWithPromo().setAllowedRegistrarIds(ImmutableSet.of("toRemove")).build());
runCommandForced("--prefix", "token", "--allowed_client_ids", "clientone,clienttwo");
assertThat(reloadResource(token).getAllowedClientIds())
assertThat(reloadResource(token).getAllowedRegistrarIds())
.containsExactly("clientone", "clienttwo");
}
@@ -65,9 +65,9 @@ class UpdateAllocationTokensCommandTest extends CommandTestCase<UpdateAllocation
void testUpdateClientIds_clearClientIds() throws Exception {
AllocationToken token =
persistResource(
builderWithPromo().setAllowedClientIds(ImmutableSet.of("toRemove")).build());
builderWithPromo().setAllowedRegistrarIds(ImmutableSet.of("toRemove")).build());
runCommandForced("--prefix", "token", "--allowed_client_ids", "");
assertThat(reloadResource(token).getAllowedClientIds()).isEmpty();
assertThat(reloadResource(token).getAllowedRegistrarIds()).isEmpty();
}
@Test
@@ -175,14 +175,14 @@ class UpdateAllocationTokensCommandTest extends CommandTestCase<UpdateAllocation
AllocationToken token =
persistResource(
builderWithPromo()
.setAllowedClientIds(ImmutableSet.of("clientid"))
.setAllowedRegistrarIds(ImmutableSet.of("clientid"))
.setAllowedTlds(ImmutableSet.of("tld"))
.setDiscountFraction(0.15)
.build());
runCommandForced("--prefix", "token");
AllocationToken reloaded = reloadResource(token);
assertThat(reloaded.getAllowedTlds()).isEqualTo(token.getAllowedTlds());
assertThat(reloaded.getAllowedClientIds()).isEqualTo(token.getAllowedClientIds());
assertThat(reloaded.getAllowedRegistrarIds()).isEqualTo(token.getAllowedRegistrarIds());
assertThat(reloaded.getDiscountFraction()).isEqualTo(token.getDiscountFraction());
}
@@ -15,27 +15,52 @@
package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.domain.rgp.GracePeriodStatus.AUTO_RENEW;
import static google.registry.model.eppcommon.StatusValue.SERVER_UPDATE_PROHIBITED;
import static google.registry.testing.DatastoreHelper.createTlds;
import static google.registry.model.reporting.HistoryEntry.Type.DOMAIN_CREATE;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.newContactResource;
import static google.registry.testing.DatastoreHelper.newDomainBase;
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.util.DateTimeUtils.END_OF_TIME;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.beust.jcommander.ParameterException;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import google.registry.model.billing.BillingEvent;
import google.registry.model.billing.BillingEvent.Flag;
import google.registry.model.billing.BillingEvent.Reason;
import google.registry.model.contact.ContactResource;
import google.registry.model.domain.DesignatedContact;
import google.registry.model.domain.DomainBase;
import google.registry.model.domain.GracePeriod;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.HostResource;
import google.registry.model.ofy.Ofy;
import google.registry.model.reporting.HistoryEntry;
import google.registry.persistence.VKey;
import google.registry.testing.InjectExtension;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link UpdateDomainCommand}. */
class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand> {
private DomainBase domain;
@RegisterExtension public final InjectExtension inject = new InjectExtension();
@BeforeEach
void beforeEach() {
inject.setStaticField(Ofy.class, "clock", fakeClock);
command.clock = fakeClock;
domain = persistActiveDomain("example.tld");
}
@Test
void testSuccess_complete() throws Exception {
runCommandForced(
@@ -78,6 +103,8 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
@Test
void testSuccess_multipleDomains() throws Exception {
createTld("abc");
persistActiveDomain("example.abc");
runCommandForced(
"--client=NewRegistrar",
"--add_nameservers=ns1.zdns.google,ns2.zdns.google",
@@ -110,7 +137,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
}
private void runTest_multipleDomains_setNameservers(String nsParam) throws Exception {
createTlds("abc", "tld");
createTld("abc");
HostResource host1 = persistActiveHost("foo.bar.tld");
HostResource host2 = persistActiveHost("baz.bar.tld");
persistResource(
@@ -254,6 +281,59 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
eppVerifier.verifySent("domain_update_clear_ds_records.xml");
}
@Test
void testSuccess_enableAutorenew() throws Exception {
runCommandForced("--client=NewRegistrar", "--autorenews=true", "example.tld");
eppVerifier.verifySent(
"domain_update_set_autorenew.xml", ImmutableMap.of("AUTORENEWS", "true"));
}
@Test
void testSuccess_disableAutorenew() throws Exception {
runCommandForced("--client=NewRegistrar", "--autorenews=false", "example.tld");
eppVerifier.verifySent(
"domain_update_set_autorenew.xml", ImmutableMap.of("AUTORENEWS", "false"));
assertThat(getStderrAsString()).doesNotContain("autorenew grace period");
}
@Test
void testSuccess_disableAutorenew_inAutorenewGracePeriod() throws Exception {
HistoryEntry createHistoryEntry =
persistResource(
new HistoryEntry.Builder().setType(DOMAIN_CREATE).setParent(domain).build());
BillingEvent.Recurring autorenewBillingEvent =
persistResource(
new BillingEvent.Recurring.Builder()
.setReason(Reason.RENEW)
.setFlags(ImmutableSet.of(Flag.AUTO_RENEW))
.setTargetId("example.tld")
.setClientId("NewRegistrar")
.setEventTime(fakeClock.nowUtc().minusDays(5))
.setRecurrenceEndTime(END_OF_TIME)
.setParent(createHistoryEntry)
.build());
persistResource(
domain
.asBuilder()
.setRegistrationExpirationTime(fakeClock.nowUtc().plusDays(360))
.setAutorenewBillingEvent(autorenewBillingEvent.createVKey())
.setGracePeriods(
ImmutableSet.of(
GracePeriod.createForRecurring(
AUTO_RENEW,
domain.getRepoId(),
fakeClock.nowUtc().plusDays(40),
"NewRegistrar",
autorenewBillingEvent.createVKey())))
.build());
runCommandForced("--client=NewRegistrar", "--autorenews=false", "example.tld");
eppVerifier.verifySent(
"domain_update_set_autorenew.xml", ImmutableMap.of("AUTORENEWS", "false"));
String stdErr = getStderrAsString();
assertThat(stdErr).contains("The following domains are in autorenew grace periods.");
assertThat(stdErr).contains("example.tld");
}
@Test
void testFailure_cantUpdateRegistryLockedDomainEvenAsSuperuser() {
HostResource host = persistActiveHost("ns1.zdns.google");
@@ -15,6 +15,7 @@
package google.registry.tools.javascrap;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistActiveDomain;
import static google.registry.testing.DatastoreHelper.persistDeletedDomain;
@@ -144,15 +145,15 @@ class BackfillRegistryLocksCommandTest extends CommandTestCase<BackfillRegistryL
"--domain_roids", String.format("%s,%s", ursDomain.getRepoId(), nonUrsDomain.getRepoId()));
RegistryLock ursLock = getMostRecentVerifiedRegistryLockByRepoId(ursDomain.getRepoId()).get();
assertThat(ursLock.getLockCompletionTimestamp().get()).isEqualTo(ursTime);
assertThat(ursLock.getLockCompletionTimestamp()).hasValue(ursTime);
RegistryLock nonUrsLock =
getMostRecentVerifiedRegistryLockByRepoId(nonUrsDomain.getRepoId()).get();
assertThat(nonUrsLock.getLockCompletionTimestamp().get()).isEqualTo(fakeClock.nowUtc());
assertThat(nonUrsLock.getLockCompletionTimestamp()).hasValue(fakeClock.nowUtc());
}
@Test
void testFailure_mustProvideDomainRoids() {
assertThat(assertThrows(IllegalArgumentException.class, () -> runCommandForced()))
assertThat(assertThrows(IllegalArgumentException.class, this::runCommandForced))
.hasMessageThat()
.isEqualTo("Must provide non-empty domain_roids argument");
}
@@ -0,0 +1,17 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<update>
<domain:update
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.tld</domain:name>
<domain:chg/>
</domain:update>
</update>
<extension>
<superuser:domainUpdate xmlns:superuser="urn:google:params:xml:ns:superuser-1.0">
<superuser:autorenews>%AUTORENEWS%</superuser:autorenews>
</superuser:domainUpdate>
</extension>
<clTRID>ABC-12345</clTRID>
</command>
</epp>
@@ -99,6 +99,46 @@ class google.registry.model.contact.ContactAddress {
class google.registry.model.contact.ContactAuthInfo {
google.registry.model.eppcommon.AuthInfo$PasswordAuth pw;
}
class google.registry.model.contact.ContactBase {
@Id java.lang.String repoId;
com.google.common.collect.ImmutableSortedMap<org.joda.time.DateTime, com.googlecode.objectify.Key<google.registry.model.ofy.CommitLogManifest>> revisions;
google.registry.model.CreateAutoTimestamp creationTime;
google.registry.model.UpdateAutoTimestamp updateTimestamp;
google.registry.model.contact.ContactAuthInfo authInfo;
google.registry.model.contact.ContactPhoneNumber fax;
google.registry.model.contact.ContactPhoneNumber voice;
google.registry.model.contact.Disclose disclose;
google.registry.model.contact.PostalInfo internationalizedPostalInfo;
google.registry.model.contact.PostalInfo localizedPostalInfo;
google.registry.model.transfer.ContactTransferData transferData;
java.lang.String contactId;
java.lang.String creationClientId;
java.lang.String currentSponsorClientId;
java.lang.String email;
java.lang.String lastEppUpdateClientId;
java.lang.String searchName;
java.util.Set<google.registry.model.eppcommon.StatusValue> status;
org.joda.time.DateTime deletionTime;
org.joda.time.DateTime lastEppUpdateTime;
org.joda.time.DateTime lastTransferTime;
}
class google.registry.model.contact.ContactHistory {
@Id java.lang.Long id;
@Parent com.googlecode.objectify.Key<? extends google.registry.model.EppResource> parent;
boolean bySuperuser;
byte[] xmlBytes;
google.registry.model.contact.ContactBase contactBase;
google.registry.model.domain.Period period;
google.registry.model.eppcommon.Trid trid;
google.registry.model.reporting.HistoryEntry$Type type;
google.registry.persistence.VKey<google.registry.model.contact.ContactResource> contactRepoId;
java.lang.Boolean requestedByRegistrar;
java.lang.String clientId;
java.lang.String otherClientId;
java.lang.String reason;
java.util.Set<google.registry.model.reporting.DomainTransactionRecord> domainTransactionRecords;
org.joda.time.DateTime modificationTime;
}
class google.registry.model.contact.ContactPhoneNumber {
java.lang.String extension;
java.lang.String phoneNumber;
@@ -191,6 +231,53 @@ class google.registry.model.domain.DomainBase {
org.joda.time.DateTime lastTransferTime;
org.joda.time.DateTime registrationExpirationTime;
}
class google.registry.model.domain.DomainContent {
@Id java.lang.String repoId;
com.google.common.collect.ImmutableSortedMap<org.joda.time.DateTime, com.googlecode.objectify.Key<google.registry.model.ofy.CommitLogManifest>> revisions;
google.registry.model.CreateAutoTimestamp creationTime;
google.registry.model.UpdateAutoTimestamp updateTimestamp;
google.registry.model.domain.DomainAuthInfo authInfo;
google.registry.model.domain.launch.LaunchNotice launchNotice;
google.registry.model.transfer.DomainTransferData transferData;
google.registry.persistence.VKey<google.registry.model.billing.BillingEvent$Recurring> autorenewBillingEvent;
google.registry.persistence.VKey<google.registry.model.poll.PollMessage$Autorenew> autorenewPollMessage;
google.registry.persistence.VKey<google.registry.model.poll.PollMessage$OneTime> deletePollMessage;
java.lang.String creationClientId;
java.lang.String currentSponsorClientId;
java.lang.String fullyQualifiedDomainName;
java.lang.String idnTableName;
java.lang.String lastEppUpdateClientId;
java.lang.String smdId;
java.lang.String tld;
java.util.Set<google.registry.model.domain.DesignatedContact> allContacts;
java.util.Set<google.registry.model.domain.GracePeriod> gracePeriods;
java.util.Set<google.registry.model.domain.secdns.DelegationSignerData> dsData;
java.util.Set<google.registry.model.eppcommon.StatusValue> status;
java.util.Set<google.registry.persistence.VKey<google.registry.model.host.HostResource>> nsHosts;
java.util.Set<java.lang.String> subordinateHosts;
org.joda.time.DateTime autorenewEndTime;
org.joda.time.DateTime deletionTime;
org.joda.time.DateTime lastEppUpdateTime;
org.joda.time.DateTime lastTransferTime;
org.joda.time.DateTime registrationExpirationTime;
}
class google.registry.model.domain.DomainHistory {
@Id java.lang.Long id;
@Parent com.googlecode.objectify.Key<? extends google.registry.model.EppResource> parent;
boolean bySuperuser;
byte[] xmlBytes;
google.registry.model.domain.DomainContent domainContent;
google.registry.model.domain.Period period;
google.registry.model.eppcommon.Trid trid;
google.registry.model.reporting.HistoryEntry$Type type;
google.registry.persistence.VKey<google.registry.model.domain.DomainBase> domainRepoId;
java.lang.Boolean requestedByRegistrar;
java.lang.String clientId;
java.lang.String otherClientId;
java.lang.String reason;
java.util.Set<google.registry.model.reporting.DomainTransactionRecord> domainTransactionRecords;
org.joda.time.DateTime modificationTime;
}
class google.registry.model.domain.GracePeriod {
google.registry.model.domain.rgp.GracePeriodStatus type;
google.registry.persistence.VKey<google.registry.model.billing.BillingEvent$OneTime> billingEventOneTime;
@@ -233,12 +320,12 @@ class google.registry.model.domain.secdns.DelegationSignerData {
class google.registry.model.domain.token.AllocationToken {
@Id java.lang.String token;
boolean discountPremiums;
com.googlecode.objectify.Key<google.registry.model.reporting.HistoryEntry> redemptionHistoryEntry;
double discountFraction;
google.registry.model.CreateAutoTimestamp creationTime;
google.registry.model.UpdateAutoTimestamp updateTimestamp;
google.registry.model.common.TimedTransitionProperty<google.registry.model.domain.token.AllocationToken$TokenStatus, google.registry.model.domain.token.AllocationToken$TokenStatusTransition> tokenStatusTransitions;
google.registry.model.domain.token.AllocationToken$TokenType tokenType;
google.registry.persistence.VKey<google.registry.model.reporting.HistoryEntry> redemptionHistoryEntry;
int discountYears;
java.lang.String domainName;
java.util.Set<java.lang.String> allowedClientIds;
@@ -288,6 +375,40 @@ class google.registry.model.eppcommon.Trid {
java.lang.String clientTransactionId;
java.lang.String serverTransactionId;
}
class google.registry.model.host.HostBase {
@Id java.lang.String repoId;
com.google.common.collect.ImmutableSortedMap<org.joda.time.DateTime, com.googlecode.objectify.Key<google.registry.model.ofy.CommitLogManifest>> revisions;
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;
java.lang.String lastEppUpdateClientId;
java.util.Set<google.registry.model.eppcommon.StatusValue> status;
java.util.Set<java.net.InetAddress> inetAddresses;
org.joda.time.DateTime deletionTime;
org.joda.time.DateTime lastEppUpdateTime;
org.joda.time.DateTime lastSuperordinateChange;
org.joda.time.DateTime lastTransferTime;
}
class google.registry.model.host.HostHistory {
@Id java.lang.Long id;
@Parent com.googlecode.objectify.Key<? extends google.registry.model.EppResource> parent;
boolean bySuperuser;
byte[] xmlBytes;
google.registry.model.domain.Period period;
google.registry.model.eppcommon.Trid trid;
google.registry.model.host.HostBase hostBase;
google.registry.model.reporting.HistoryEntry$Type type;
google.registry.persistence.VKey<google.registry.model.host.HostResource> hostRepoId;
java.lang.Boolean requestedByRegistrar;
java.lang.String clientId;
java.lang.String otherClientId;
java.lang.String reason;
java.util.Set<google.registry.model.reporting.DomainTransactionRecord> domainTransactionRecords;
org.joda.time.DateTime modificationTime;
}
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;
@@ -766,4 +887,4 @@ enum google.registry.model.transfer.TransferStatus {
PENDING;
SERVER_APPROVED;
SERVER_CANCELLED;
}
}
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<update>
<domain:update
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.tld</domain:name>
</domain:update>
</update>
<extension>
<superuser:domainUpdate xmlns:superuser="urn:google:params:xml:ns:superuser-1.0">
<superuser:autorenews>%AUTORENEWS%</superuser:autorenews>
</superuser:domainUpdate>
</extension>
<clTRID>RegistryTool</clTRID>
</command>
</epp>
@@ -11,9 +11,9 @@ emailAddress: the.registrar@example.com -> thase@the.registrar
url: http://my.fake.url -> http://my.new.url
contacts:
ADDED:
{parent=Key<?>(EntityGroupRoot("cross-tld")/Registrar("TheRegistrar")), name=Extra Terrestrial, emailAddress=etphonehome@example.com, registryLockEmailAddress=null, phoneNumber=+1.2345678901, faxNumber=null, types=[ADMIN, BILLING, TECH, WHOIS], gaeUserId=null, visibleInWhoisAsAdmin=true, visibleInWhoisAsTech=false, visibleInDomainWhoisAsAbuse=false, allowedToSetRegistryLockPassword=false}
{parent=Key<?>(EntityGroupRoot("cross-tld")/Registrar("TheRegistrar")), name=Extra Terrestrial, emailAddress=etphonehome@example.com, registrarId=TheRegistrar, registryLockEmailAddress=null, phoneNumber=+1.2345678901, faxNumber=null, types=[ADMIN, BILLING, TECH, WHOIS], gaeUserId=null, visibleInWhoisAsAdmin=true, visibleInWhoisAsTech=false, visibleInDomainWhoisAsAbuse=false, allowedToSetRegistryLockPassword=false}
REMOVED:
{parent=Key<?>(EntityGroupRoot("cross-tld")/Registrar("TheRegistrar")), name=John Doe, emailAddress=johndoe@theregistrar.com, registryLockEmailAddress=null, phoneNumber=+1.1234567890, faxNumber=null, types=[ADMIN], gaeUserId=31337, visibleInWhoisAsAdmin=false, visibleInWhoisAsTech=false, visibleInDomainWhoisAsAbuse=false, allowedToSetRegistryLockPassword=false}
{parent=Key<?>(EntityGroupRoot("cross-tld")/Registrar("TheRegistrar")), name=John Doe, emailAddress=johndoe@theregistrar.com, registrarId=TheRegistrar, registryLockEmailAddress=null, phoneNumber=+1.1234567890, faxNumber=null, types=[ADMIN], gaeUserId=31337, visibleInWhoisAsAdmin=false, visibleInWhoisAsTech=false, visibleInDomainWhoisAsAbuse=false, allowedToSetRegistryLockPassword=false}
FINAL CONTENTS:
{parent=Key<?>(EntityGroupRoot("cross-tld")/Registrar("TheRegistrar")), name=Extra Terrestrial, emailAddress=etphonehome@example.com, registryLockEmailAddress=null, phoneNumber=+1.2345678901, faxNumber=null, types=[ADMIN, BILLING, TECH, WHOIS], gaeUserId=null, visibleInWhoisAsAdmin=true, visibleInWhoisAsTech=false, visibleInDomainWhoisAsAbuse=false, allowedToSetRegistryLockPassword=false},
{parent=Key<?>(EntityGroupRoot("cross-tld")/Registrar("TheRegistrar")), name=Marla Singer, emailAddress=Marla.Singer@crr.com, registryLockEmailAddress=Marla.Singer.RegistryLock@crr.com, phoneNumber=+1.2128675309, faxNumber=null, types=[TECH], gaeUserId=12345, visibleInWhoisAsAdmin=false, visibleInWhoisAsTech=false, visibleInDomainWhoisAsAbuse=false, allowedToSetRegistryLockPassword=false}
{parent=Key<?>(EntityGroupRoot("cross-tld")/Registrar("TheRegistrar")), name=Extra Terrestrial, emailAddress=etphonehome@example.com, registrarId=TheRegistrar, registryLockEmailAddress=null, phoneNumber=+1.2345678901, faxNumber=null, types=[ADMIN, BILLING, TECH, WHOIS], gaeUserId=null, visibleInWhoisAsAdmin=true, visibleInWhoisAsTech=false, visibleInDomainWhoisAsAbuse=false, allowedToSetRegistryLockPassword=false},
{parent=Key<?>(EntityGroupRoot("cross-tld")/Registrar("TheRegistrar")), name=Marla Singer, emailAddress=Marla.Singer@crr.com, registrarId=TheRegistrar, registryLockEmailAddress=Marla.Singer.RegistryLock@crr.com, phoneNumber=+1.2128675309, faxNumber=null, types=[TECH], gaeUserId=12345, visibleInWhoisAsAdmin=false, visibleInWhoisAsTech=false, visibleInDomainWhoisAsAbuse=false, allowedToSetRegistryLockPassword=false}
+13 -5
View File
@@ -47,18 +47,19 @@ Below are the steps to submit a schema change:
following the existing scripts in that folder. Note the double underscore in
the naming pattern.
4. Run `./nom_build :nom:generate_golden_file`. This is a pseudo-task
4. Run `./nom_build :nom:generate_golden_file`. This is a pseudo-task
implemented in the `nom_build` script that does the following:
- Runs the `:db:test` task from the Gradle root project. The SchemaTest
will fail because the new schema does not match the golden file.
- Copies `db/build/resources/test/testcontainer/mount/dump.txt` to the golden
file `db/src/main/resources/sql/schema/nomulus.golden.sql`.
- Copies `db/build/resources/test/testcontainer/mount/dump.txt` to the
golden file `db/src/main/resources/sql/schema/nomulus.golden.sql`.
- Re-runs the `:db:test` task. This time all tests should pass.
You'll want to have a look at the diffs in the golden schema to verify
that all changes are intentional.
You'll want to have a look at the diffs in the golden schema to verify that
all changes are intentional.
Relevant files (under db/src/main/resources/sql/schema/):
@@ -102,6 +103,13 @@ gcloud builds submit --config=release/cloudbuild-schema-deploy.yaml \
./nom_build :db:flywayInfo --dbServer=${SQL_ENV}
```
To test unsubmitted schema changes in the alpha or crash environments, use the
following command to deploy the local schema,
```shell
./nom_build :db:flywayMigrate --dbServer=[alpha|crash] --environment=[alpha|crash]
```
#### Glass Breaking
If you need to deploy a schema off-cycle, try making a release first, then
+4 -4
View File
@@ -29,8 +29,8 @@ ext {
def dbServer = findProperty(dbServerProperty).toString().toLowerCase()
def dbName = findProperty(dbNameProperty)
isCloudSql = {
return allDbEnv.contains(dbServer)
isRestricted = {
return restrictedDbEnv.contains(dbServer)
}
getAccessInfoByHostPort = { hostAndPort ->
@@ -169,8 +169,8 @@ dependencies {
flywayInfo.dependsOn('buildNeeded')
flywayValidate.dependsOn('buildNeeded')
if (ext.isCloudSql()) {
// Disable dangerous Flyway tasks. Only allow info and validate.
if (ext.isRestricted()) {
// Disable dangerous Flyway tasks in sandbox and production. Only allow info and validate.
tasks.findAll { task -> task.group.equals('Flyway')}.each {
if (it.name == 'flywayMigrate') {
it.doFirst {
@@ -0,0 +1,31 @@
-- 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.
CREATE TABLE "AllocationToken" (
token text NOT NULL,
update_timestamp timestamptz,
allowed_registrar_ids text[],
allowed_tlds text[],
creation_time timestamptz NOT NULL,
discount_fraction float8 NOT NULL,
discount_premiums boolean NOT NULL,
discount_years int4 NOT NULL,
domain_name text,
redemption_history_entry text,
token_status_transitions hstore,
token_type text,
PRIMARY KEY (token)
);
CREATE INDEX allocation_token_domain_name_idx ON "AllocationToken" (domain_name);
@@ -0,0 +1,20 @@
-- 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 "RegistrarPoc" add column registrar_id text;
alter table "RegistrarPoc" drop constraint "RegistrarPoc_pkey";
alter table "RegistrarPoc"
add constraint "RegistrarPoc_pkey" primary key (registrar_id, email_address);
@@ -13,6 +13,22 @@
-- limitations under the License.
create sequence history_id_sequence start 1 increment 1;
create table "AllocationToken" (
token text not null,
update_timestamp timestamptz,
allowed_registrar_ids text[],
allowed_tlds text[],
creation_time timestamptz not null,
discount_fraction float8 not null,
discount_premiums boolean not null,
discount_years int4 not null,
domain_name text,
redemption_history_entry text,
token_status_transitions hstore,
token_type text,
primary key (token)
);
create table "BillingCancellation" (
billing_cancellation_id bigserial not null,
registrar_id text not null,
@@ -502,6 +518,7 @@ create sequence history_id_sequence start 1 increment 1;
create table "RegistrarPoc" (
email_address text not null,
registrar_id text not null,
allowed_to_set_registry_lock_password boolean not null,
fax_number text,
gae_user_id text,
@@ -514,7 +531,7 @@ create sequence history_id_sequence start 1 increment 1;
visible_in_domain_whois_as_abuse boolean not null,
visible_in_whois_as_admin boolean not null,
visible_in_whois_as_tech boolean not null,
primary key (email_address)
primary key (email_address, registrar_id)
);
create table "RegistryLock" (
@@ -567,6 +584,7 @@ create sequence history_id_sequence start 1 increment 1;
contents bytea,
primary key (id)
);
create index allocation_token_domain_name_idx on "AllocationToken" (domain_name);
create index IDXih4b2tea127p5rb61gje6e1y2 on "BillingCancellation" (registrar_id);
create index IDX2exdfbx6oiiwnhr8j6gjpqt2j on "BillingCancellation" (event_time);
create index IDXqa3g92jc17e8dtiaviy4fet4x on "BillingCancellation" (billing_time);
@@ -34,6 +34,26 @@ SET default_tablespace = '';
SET default_with_oids = false;
--
-- Name: AllocationToken; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public."AllocationToken" (
token text NOT NULL,
update_timestamp timestamp with time zone,
allowed_registrar_ids text[],
allowed_tlds text[],
creation_time timestamp with time zone NOT NULL,
discount_fraction double precision NOT NULL,
discount_premiums boolean NOT NULL,
discount_years integer NOT NULL,
domain_name text,
redemption_history_entry text,
token_status_transitions public.hstore,
token_type text
);
--
-- Name: BillingCancellation; Type: TABLE; Schema: public; Owner: -
--
@@ -757,7 +777,8 @@ CREATE TABLE public."RegistrarPoc" (
visible_in_domain_whois_as_abuse boolean NOT NULL,
visible_in_whois_as_admin boolean NOT NULL,
visible_in_whois_as_tech boolean NOT NULL,
registry_lock_email_address text
registry_lock_email_address text,
registrar_id text NOT NULL
);
@@ -985,6 +1006,14 @@ ALTER TABLE ONLY public."Spec11ThreatMatch" ALTER COLUMN id SET DEFAULT nextval(
ALTER TABLE ONLY public."Transaction" ALTER COLUMN id SET DEFAULT nextval('public."Transaction_id_seq"'::regclass);
--
-- Name: AllocationToken AllocationToken_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public."AllocationToken"
ADD CONSTRAINT "AllocationToken_pkey" PRIMARY KEY (token);
--
-- Name: BillingCancellation BillingCancellation_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
@@ -1126,7 +1155,7 @@ ALTER TABLE ONLY public."PremiumList"
--
ALTER TABLE ONLY public."RegistrarPoc"
ADD CONSTRAINT "RegistrarPoc_pkey" PRIMARY KEY (email_address);
ADD CONSTRAINT "RegistrarPoc_pkey" PRIMARY KEY (registrar_id, email_address);
--
@@ -1185,6 +1214,13 @@ ALTER TABLE ONLY public."RegistryLock"
ADD CONSTRAINT idx_registry_lock_repo_id_revision_id UNIQUE (repo_id, revision_id);
--
-- Name: allocation_token_domain_name_idx; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX allocation_token_domain_name_idx ON public."AllocationToken" USING btree (domain_name);
--
-- Name: idx1iy7njgb7wjmj9piml4l2g0qi; Type: INDEX; Schema: public; Owner: -
--