diff --git a/core/src/main/java/google/registry/tools/RegistryTool.java b/core/src/main/java/google/registry/tools/RegistryTool.java index 7c0154602..c7d886390 100644 --- a/core/src/main/java/google/registry/tools/RegistryTool.java +++ b/core/src/main/java/google/registry/tools/RegistryTool.java @@ -15,7 +15,6 @@ package google.registry.tools; import com.google.common.collect.ImmutableMap; -import google.registry.tools.javascrap.CompareEscrowDepositsCommand; import google.registry.tools.javascrap.CreateCancellationsForOneTimesCommand; /** Container class to create and run remote commands against a Datastore instance. */ @@ -33,7 +32,6 @@ public final class RegistryTool { .put("canonicalize_labels", CanonicalizeLabelsCommand.class) .put("check_domain", CheckDomainCommand.class) .put("check_domain_claims", CheckDomainClaimsCommand.class) - .put("compare_escrow_deposits", CompareEscrowDepositsCommand.class) .put("convert_idn", ConvertIdnCommand.class) .put("count_domains", CountDomainsCommand.class) .put("create_anchor_tenant", CreateAnchorTenantCommand.class) diff --git a/core/src/main/java/google/registry/tools/RegistryToolComponent.java b/core/src/main/java/google/registry/tools/RegistryToolComponent.java index b4d3bc55b..b32d6b5a7 100644 --- a/core/src/main/java/google/registry/tools/RegistryToolComponent.java +++ b/core/src/main/java/google/registry/tools/RegistryToolComponent.java @@ -40,7 +40,6 @@ import google.registry.request.Modules.UrlConnectionServiceModule; import google.registry.request.Modules.UrlFetchServiceModule; import google.registry.request.Modules.UserServiceModule; import google.registry.tools.AuthModule.LocalCredentialModule; -import google.registry.tools.javascrap.CompareEscrowDepositsCommand; import google.registry.tools.javascrap.CreateCancellationsForOneTimesCommand; import google.registry.util.UtilsModule; import google.registry.whois.NonCachingWhoisModule; @@ -89,8 +88,6 @@ interface RegistryToolComponent { void inject(CheckDomainCommand command); - void inject(CompareEscrowDepositsCommand command); - void inject(CountDomainsCommand command); void inject(CreateAnchorTenantCommand command); diff --git a/core/src/main/java/google/registry/tools/javascrap/CompareEscrowDepositsCommand.java b/core/src/main/java/google/registry/tools/javascrap/CompareEscrowDepositsCommand.java deleted file mode 100644 index 5fac88bdf..000000000 --- a/core/src/main/java/google/registry/tools/javascrap/CompareEscrowDepositsCommand.java +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright 2022 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.tools.javascrap; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Sets.difference; - -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableList; -import google.registry.keyring.api.Keyring; -import google.registry.model.annotations.DeleteAfterMigration; -import google.registry.rde.Ghostryde; -import google.registry.tools.Command; -import google.registry.tools.params.PathParameter; -import google.registry.xjc.XjcXmlTransformer; -import google.registry.xjc.rde.XjcRdeDeposit; -import google.registry.xjc.rdedomain.XjcRdeDomain; -import google.registry.xjc.rderegistrar.XjcRdeRegistrar; -import google.registry.xml.XmlException; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import javax.inject.Inject; -import javax.inject.Provider; -import javax.xml.bind.JAXBElement; - -/** - * Command to view and schema validate an XML RDE escrow deposit. - * - *

Note that this command only makes sure that both deposits contain the same registrars and - * domains, regardless of the order. To verify that they are indeed equivalent one still needs to - * verify internal consistency within each deposit (i.e. to check that all hosts and contacts - * referenced by domains are included in the deposit) by calling {@code - * google.registry.tools.ValidateEscrowDepositCommand}. - */ -@DeleteAfterMigration -@Parameters(separators = " =", commandDescription = "Compare two XML escrow deposits.") -public final class CompareEscrowDepositsCommand implements Command { - - @Parameter( - description = - "Two XML escrow deposit files. Each may be a plain XML or an XML GhostRyDE file.", - validateWith = PathParameter.InputFile.class) - private List inputs; - - @Inject Provider keyring; - - private XjcRdeDeposit getDeposit(Path input) throws IOException, XmlException { - InputStream fileStream = Files.newInputStream(input); - InputStream inputStream = fileStream; - if (input.toString().endsWith(".ghostryde")) { - inputStream = Ghostryde.decoder(fileStream, keyring.get().getRdeStagingDecryptionKey()); - } - return XjcXmlTransformer.unmarshal(XjcRdeDeposit.class, inputStream); - } - - @Override - public void run() throws Exception { - checkArgument( - inputs.size() == 2, - "Must supply 2 files to compare, but %s was/were supplied.", - inputs.size()); - XjcRdeDeposit deposit1 = getDeposit(inputs.get(0)); - XjcRdeDeposit deposit2 = getDeposit(inputs.get(1)); - compareXmlDeposits(deposit1, deposit2); - } - - private static void process(XjcRdeDeposit deposit, Set domains, Set registrars) { - for (JAXBElement item : deposit.getContents().getContents()) { - if (XjcRdeDomain.class.isAssignableFrom(item.getDeclaredType())) { - XjcRdeDomain domain = (XjcRdeDomain) item.getValue(); - domains.add(checkNotNull(domain.getName())); - } else if (XjcRdeRegistrar.class.isAssignableFrom(item.getDeclaredType())) { - XjcRdeRegistrar registrar = (XjcRdeRegistrar) item.getValue(); - registrars.add(checkNotNull(registrar.getId())); - } - } - } - - private static boolean printUniqueElements( - Set set1, Set set2, String element, String deposit) { - ImmutableList uniqueElements = ImmutableList.copyOf(difference(set1, set2)); - if (!uniqueElements.isEmpty()) { - System.out.printf( - "%s only in %s:\n%s\n", element, deposit, Joiner.on("\n").join(uniqueElements)); - return false; - } - return true; - } - - private static void compareXmlDeposits(XjcRdeDeposit deposit1, XjcRdeDeposit deposit2) { - Set domains1 = new HashSet<>(); - Set domains2 = new HashSet<>(); - Set registrars1 = new HashSet<>(); - Set registrars2 = new HashSet<>(); - process(deposit1, domains1, registrars1); - process(deposit2, domains2, registrars2); - boolean good = true; - good &= printUniqueElements(domains1, domains2, "domains", "deposit1"); - good &= printUniqueElements(domains2, domains1, "domains", "deposit2"); - good &= printUniqueElements(registrars1, registrars2, "registrars", "deposit1"); - good &= printUniqueElements(registrars2, registrars1, "registrars", "deposit2"); - if (good) { - System.out.println( - "The two deposits contain the same domains and registrars. " - + "You still need to run validate_escrow_deposit to check reference consistency."); - } else { - System.out.println("The two deposits differ."); - } - } -} diff --git a/core/src/test/java/google/registry/tools/javascrap/CompareEscrowDepositsCommandTest.java b/core/src/test/java/google/registry/tools/javascrap/CompareEscrowDepositsCommandTest.java deleted file mode 100644 index b1706453a..000000000 --- a/core/src/test/java/google/registry/tools/javascrap/CompareEscrowDepositsCommandTest.java +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2021 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.tools.javascrap; - -import static com.google.common.truth.Truth.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import google.registry.rde.RdeTestData; -import google.registry.tools.CommandTestCase; -import java.nio.charset.StandardCharsets; -import org.junit.jupiter.api.Test; - -/** Unit tests for {@link CompareEscrowDepositsCommand}. */ -class CompareEscrowDepositsCommandTest extends CommandTestCase { - - @Test - void testFailure_wrongNumberOfFiles() throws Exception { - String file1 = writeToNamedTmpFile("file1", "foo".getBytes(StandardCharsets.UTF_8)); - String file2 = writeToNamedTmpFile("file2", "bar".getBytes(StandardCharsets.UTF_8)); - String file3 = writeToNamedTmpFile("file3", "baz".getBytes(StandardCharsets.UTF_8)); - assertThrows(IllegalArgumentException.class, () -> runCommand(file1)); - assertThrows(IllegalArgumentException.class, () -> runCommand(file1, file2, file3)); - } - - @Test - void testSuccess_sameContentDifferentOrder() throws Exception { - String file1 = writeToNamedTmpFile("file1", RdeTestData.loadBytes("deposit_full.xml").read()); - String file2 = - writeToNamedTmpFile("file2", RdeTestData.loadBytes("deposit_full_out_of_order.xml").read()); - runCommand(file1, file2); - assertThat(getStdoutAsString()) - .contains("The two deposits contain the same domains and registrars."); - } - - @Test - void testSuccess_differentContent() throws Exception { - String file1 = writeToNamedTmpFile("file1", RdeTestData.loadBytes("deposit_full.xml").read()); - String file2 = - writeToNamedTmpFile("file2", RdeTestData.loadBytes("deposit_full_different.xml").read()); - runCommand(file1, file2); - assertThat(getStdoutAsString()) - .isEqualTo( - "domains only in deposit1:\n" - + "example2.test\n" - + "domains only in deposit2:\n" - + "example3.test\n" - + "registrars only in deposit2:\n" - + "RegistrarY\n" - + "The two deposits differ.\n"); - } -}