From 20fd944e83c1a1cb1c38f68a08b4dfb600af016f Mon Sep 17 00:00:00 2001 From: gbrodman Date: Fri, 21 Mar 2025 16:48:54 -0400 Subject: [PATCH] Remove allocation token custom logic (#2727) This was added back in early 2018 long ago to enable promotions, but since then (and for many years) we've added the ability to run promotions on the tokens themselves, rather than relying on custom Java classes. This will make the changes for b/315504612 much easier, as that will split up token validation into "is this token valid in general?" and "is this token valid for this domain/action?" --- .../registry/config/RegistryConfig.java | 6 - .../config/RegistryConfigSettings.java | 1 - .../registry/config/files/default-config.yaml | 4 - .../google/registry/flows/FlowComponent.java | 2 - .../token/AllocationTokenCustomLogic.java | 64 --------- .../token/AllocationTokenFlowUtils.java | 20 +-- .../domain/token/AllocationTokenModule.java | 33 ----- .../token/AllocationTokenFlowUtilsTest.java | 130 +----------------- 8 files changed, 5 insertions(+), 255 deletions(-) delete mode 100644 core/src/main/java/google/registry/flows/domain/token/AllocationTokenCustomLogic.java delete mode 100644 core/src/main/java/google/registry/flows/domain/token/AllocationTokenModule.java diff --git a/core/src/main/java/google/registry/config/RegistryConfig.java b/core/src/main/java/google/registry/config/RegistryConfig.java index fd8b4afbc..f5421975d 100644 --- a/core/src/main/java/google/registry/config/RegistryConfig.java +++ b/core/src/main/java/google/registry/config/RegistryConfig.java @@ -1111,12 +1111,6 @@ public final class RegistryConfig { return config.registryPolicy.whoisCommandFactoryClass; } - @Provides - @Config("allocationTokenCustomLogicClass") - public static String provideAllocationTokenCustomLogicClass(RegistryConfigSettings config) { - return config.registryPolicy.allocationTokenCustomLogicClass; - } - @Provides @Config("dnsCountQueryCoordinatorClass") public static String dnsCountQueryCoordinatorClass(RegistryConfigSettings config) { diff --git a/core/src/main/java/google/registry/config/RegistryConfigSettings.java b/core/src/main/java/google/registry/config/RegistryConfigSettings.java index bc1b3f9ea..32dd08ee8 100644 --- a/core/src/main/java/google/registry/config/RegistryConfigSettings.java +++ b/core/src/main/java/google/registry/config/RegistryConfigSettings.java @@ -91,7 +91,6 @@ public class RegistryConfigSettings { public String productName; public String customLogicFactoryClass; public String whoisCommandFactoryClass; - public String allocationTokenCustomLogicClass; public String dnsCountQueryCoordinatorClass; public int contactAutomaticTransferDays; public String greetingServerId; diff --git a/core/src/main/java/google/registry/config/files/default-config.yaml b/core/src/main/java/google/registry/config/files/default-config.yaml index b9a6c30d3..85ebbdf34 100644 --- a/core/src/main/java/google/registry/config/files/default-config.yaml +++ b/core/src/main/java/google/registry/config/files/default-config.yaml @@ -69,10 +69,6 @@ registryPolicy: # See whois/WhoisCommandFactory.java whoisCommandFactoryClass: google.registry.whois.WhoisCommandFactory - # Custom logic class for handling allocation tokens. - # See flows/domain/token/AllocationTokenCustomLogic.java - allocationTokenCustomLogicClass: google.registry.flows.domain.token.AllocationTokenCustomLogic - # Custom logic class for handling DNS query count reporting for ICANN. # See reporting/icann/DnsCountQueryCoordinator.java dnsCountQueryCoordinatorClass: google.registry.reporting.icann.DummyDnsCountQueryCoordinator diff --git a/core/src/main/java/google/registry/flows/FlowComponent.java b/core/src/main/java/google/registry/flows/FlowComponent.java index 5b3428116..f5d48bb23 100644 --- a/core/src/main/java/google/registry/flows/FlowComponent.java +++ b/core/src/main/java/google/registry/flows/FlowComponent.java @@ -43,7 +43,6 @@ import google.registry.flows.domain.DomainTransferQueryFlow; import google.registry.flows.domain.DomainTransferRejectFlow; import google.registry.flows.domain.DomainTransferRequestFlow; import google.registry.flows.domain.DomainUpdateFlow; -import google.registry.flows.domain.token.AllocationTokenModule; import google.registry.flows.host.HostCheckFlow; import google.registry.flows.host.HostCreateFlow; import google.registry.flows.host.HostDeleteFlow; @@ -59,7 +58,6 @@ import google.registry.model.eppcommon.Trid; /** Dagger component for flow classes. */ @FlowScope @Subcomponent(modules = { - AllocationTokenModule.class, BatchModule.class, CustomLogicModule.class, DnsModule.class, diff --git a/core/src/main/java/google/registry/flows/domain/token/AllocationTokenCustomLogic.java b/core/src/main/java/google/registry/flows/domain/token/AllocationTokenCustomLogic.java deleted file mode 100644 index fa928849f..000000000 --- a/core/src/main/java/google/registry/flows/domain/token/AllocationTokenCustomLogic.java +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2017 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.flows.domain.token; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; -import com.google.common.net.InternetDomainName; -import google.registry.flows.EppException; -import google.registry.model.domain.Domain; -import google.registry.model.domain.DomainCommand; -import google.registry.model.domain.token.AllocationToken; -import google.registry.model.tld.Tld; -import org.joda.time.DateTime; - -/** - * A no-op base class for allocation token custom logic. - * - *

Extend this class and override the hook(s) to perform custom logic. - */ -public class AllocationTokenCustomLogic { - - /** Performs additional custom logic for validating a token on a domain create. */ - public AllocationToken validateToken( - DomainCommand.Create command, - AllocationToken token, - Tld tld, - String registrarId, - DateTime now) - throws EppException { - // Do nothing. - return token; - } - - /** Performs additional custom logic for validating a token on an existing domain. */ - public AllocationToken validateToken( - Domain domain, AllocationToken token, Tld tld, String registrarId, DateTime now) - throws EppException { - // Do nothing. - return token; - } - - /** Performs additional custom logic for performing domain checks using a token. */ - public ImmutableMap checkDomainsWithToken( - ImmutableList domainNames, - AllocationToken token, - String registrarId, - DateTime now) { - // Do nothing. - return Maps.toMap(domainNames, k -> ""); - } -} diff --git a/core/src/main/java/google/registry/flows/domain/token/AllocationTokenFlowUtils.java b/core/src/main/java/google/registry/flows/domain/token/AllocationTokenFlowUtils.java index 01a7d20f0..f4f9f27fd 100644 --- a/core/src/main/java/google/registry/flows/domain/token/AllocationTokenFlowUtils.java +++ b/core/src/main/java/google/registry/flows/domain/token/AllocationTokenFlowUtils.java @@ -19,7 +19,6 @@ import static google.registry.persistence.transaction.TransactionManagerFactory. import static google.registry.pricing.PricingEngineProxy.isDomainPremium; import com.google.common.base.Strings; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import com.google.common.net.InternetDomainName; @@ -48,12 +47,8 @@ import org.joda.time.DateTime; /** Utility functions for dealing with {@link AllocationToken}s in domain flows. */ public class AllocationTokenFlowUtils { - private final AllocationTokenCustomLogic tokenCustomLogic; - @Inject - AllocationTokenFlowUtils(AllocationTokenCustomLogic tokenCustomLogic) { - this.tokenCustomLogic = tokenCustomLogic; - } + public AllocationTokenFlowUtils() {} /** * Checks if the allocation token applies to the given domain names, used for domain checks. @@ -75,7 +70,6 @@ public class AllocationTokenFlowUtils { // If the token is only invalid for some domain names (e.g. an invalid TLD), include those error // results for only those domain names - ImmutableList.Builder validDomainNames = new ImmutableList.Builder<>(); ImmutableMap.Builder resultsBuilder = new ImmutableMap.Builder<>(); for (InternetDomainName domainName : domainNames) { try { @@ -86,16 +80,11 @@ public class AllocationTokenFlowUtils { registrarId, isDomainPremium(domainName.toString(), now), now); - validDomainNames.add(domainName); + resultsBuilder.put(domainName, ""); } catch (EppException e) { resultsBuilder.put(domainName, e.getMessage()); } } - - // For all valid domain names, run the custom logic and include the results - resultsBuilder.putAll( - tokenCustomLogic.checkDomainsWithToken( - validDomainNames.build(), tokenEntity, registrarId, now)); return new AllocationTokenDomainCheckResults(Optional.of(tokenEntity), resultsBuilder.build()); } @@ -209,7 +198,7 @@ public class AllocationTokenFlowUtils { registrarId, isDomainPremium(command.getDomainName(), now), now); - return Optional.of(tokenCustomLogic.validateToken(command, tokenEntity, tld, registrarId, now)); + return Optional.of(tokenEntity); } /** Verifies and returns the allocation token if one is specified, otherwise does nothing. */ @@ -232,8 +221,7 @@ public class AllocationTokenFlowUtils { registrarId, isDomainPremium(existingDomain.getDomainName(), now), now); - return Optional.of( - tokenCustomLogic.validateToken(existingDomain, tokenEntity, tld, registrarId, now)); + return Optional.of(tokenEntity); } public static void verifyTokenAllowedOnDomain( diff --git a/core/src/main/java/google/registry/flows/domain/token/AllocationTokenModule.java b/core/src/main/java/google/registry/flows/domain/token/AllocationTokenModule.java deleted file mode 100644 index c980aff5c..000000000 --- a/core/src/main/java/google/registry/flows/domain/token/AllocationTokenModule.java +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2017 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.flows.domain.token; - -import static google.registry.util.TypeUtils.getClassFromString; -import static google.registry.util.TypeUtils.instantiate; - -import dagger.Module; -import dagger.Provides; -import google.registry.config.RegistryConfig.Config; - -/** Dagger module for allocation token classes. */ -@Module -public class AllocationTokenModule { - - @Provides - static AllocationTokenCustomLogic provideAllocationTokenCustomLogic( - @Config("allocationTokenCustomLogicClass") String customClass) { - return instantiate(getClassFromString(customClass, AllocationTokenCustomLogic.class)); - } -} diff --git a/core/src/test/java/google/registry/flows/domain/token/AllocationTokenFlowUtilsTest.java b/core/src/test/java/google/registry/flows/domain/token/AllocationTokenFlowUtilsTest.java index 9c3df5e72..f7a95026a 100644 --- a/core/src/test/java/google/registry/flows/domain/token/AllocationTokenFlowUtilsTest.java +++ b/core/src/test/java/google/registry/flows/domain/token/AllocationTokenFlowUtilsTest.java @@ -35,7 +35,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedMap; -import com.google.common.collect.Maps; import com.google.common.net.InternetDomainName; import google.registry.flows.EppException; import google.registry.flows.domain.token.AllocationTokenFlowUtils.AllocationTokenNotInPromotionException; @@ -63,8 +62,7 @@ import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link AllocationTokenFlowUtils}. */ class AllocationTokenFlowUtilsTest { - private final AllocationTokenFlowUtils flowUtils = - new AllocationTokenFlowUtils(new AllocationTokenCustomLogic()); + private final AllocationTokenFlowUtils flowUtils = new AllocationTokenFlowUtils(); @RegisterExtension final JpaIntegrationTestExtension jpa = @@ -185,47 +183,6 @@ class AllocationTokenFlowUtilsTest { .marshalsToXml(); } - @Test - void test_validateTokenCreate_callsCustomLogic() { - AllocationTokenFlowUtils failingFlowUtils = - new AllocationTokenFlowUtils(new FailingAllocationTokenCustomLogic()); - persistResource( - new AllocationToken.Builder().setToken("tokeN").setTokenType(SINGLE_USE).build()); - when(allocationTokenExtension.getAllocationToken()).thenReturn("tokeN"); - Exception thrown = - assertThrows( - IllegalStateException.class, - () -> - failingFlowUtils.verifyAllocationTokenCreateIfPresent( - createCommand("blah.tld"), - Tld.get("tld"), - "TheRegistrar", - DateTime.now(UTC), - Optional.of(allocationTokenExtension))); - assertThat(thrown).hasMessageThat().isEqualTo("failed for tests"); - } - - @Test - void test_validateTokenExistingDomain_callsCustomLogic() { - AllocationTokenFlowUtils failingFlowUtils = - new AllocationTokenFlowUtils(new FailingAllocationTokenCustomLogic()); - persistResource( - new AllocationToken.Builder().setToken("tokeN").setTokenType(SINGLE_USE).build()); - when(allocationTokenExtension.getAllocationToken()).thenReturn("tokeN"); - Exception thrown = - assertThrows( - IllegalStateException.class, - () -> - failingFlowUtils.verifyAllocationTokenIfPresent( - DatabaseHelper.newDomain("blah.tld"), - Tld.get("tld"), - "TheRegistrar", - DateTime.now(UTC), - CommandName.RENEW, - Optional.of(allocationTokenExtension))); - assertThat(thrown).hasMessageThat().isEqualTo("failed for tests"); - } - @Test void test_validateTokenCreate_invalidForClientId() { persistResource( @@ -383,49 +340,6 @@ class AllocationTokenFlowUtilsTest { .inOrder(); } - @Test - void test_checkDomainsWithToken_callsCustomLogic() { - persistResource( - new AllocationToken.Builder().setToken("tokeN").setTokenType(SINGLE_USE).build()); - AllocationTokenFlowUtils failingFlowUtils = - new AllocationTokenFlowUtils(new FailingAllocationTokenCustomLogic()); - Exception thrown = - assertThrows( - IllegalStateException.class, - () -> - failingFlowUtils.checkDomainsWithToken( - ImmutableList.of( - InternetDomainName.from("blah.tld"), InternetDomainName.from("blah2.tld")), - "tokeN", - "TheRegistrar", - DateTime.now(UTC))); - assertThat(thrown).hasMessageThat().isEqualTo("failed for tests"); - } - - @Test - void test_checkDomainsWithToken_resultsFromCustomLogicAreIntegrated() { - persistResource( - new AllocationToken.Builder().setToken("tokeN").setTokenType(SINGLE_USE).build()); - AllocationTokenFlowUtils customResultFlowUtils = - new AllocationTokenFlowUtils(new CustomResultAllocationTokenCustomLogic()); - assertThat( - customResultFlowUtils - .checkDomainsWithToken( - ImmutableList.of( - InternetDomainName.from("blah.tld"), InternetDomainName.from("bunny.tld")), - "tokeN", - "TheRegistrar", - DateTime.now(UTC)) - .domainCheckResults()) - .containsExactlyEntriesIn( - ImmutableMap.of( - InternetDomainName.from("blah.tld"), - "", - InternetDomainName.from("bunny.tld"), - "fufu")) - .inOrder(); - } - private void assertValidateCreateThrowsEppException(Class clazz) { assertAboutEppExceptions() .that( @@ -475,46 +389,4 @@ class AllocationTokenFlowUtilsTest { .put(promoStart.plusMonths(1), ENDED) .build()); } - - /** An {@link AllocationTokenCustomLogic} class that throws exceptions on every method. */ - private static class FailingAllocationTokenCustomLogic extends AllocationTokenCustomLogic { - - @Override - public AllocationToken validateToken( - DomainCommand.Create command, - AllocationToken token, - Tld tld, - String registrarId, - DateTime now) { - throw new IllegalStateException("failed for tests"); - } - - @Override - public AllocationToken validateToken( - Domain domain, AllocationToken token, Tld tld, String registrarId, DateTime now) { - throw new IllegalStateException("failed for tests"); - } - - @Override - public ImmutableMap checkDomainsWithToken( - ImmutableList domainNames, - AllocationToken tokenEntity, - String registrarId, - DateTime now) { - throw new IllegalStateException("failed for tests"); - } - } - - /** An {@link AllocationTokenCustomLogic} class that returns custom check results for bunnies. */ - private static class CustomResultAllocationTokenCustomLogic extends AllocationTokenCustomLogic { - - @Override - public ImmutableMap checkDomainsWithToken( - ImmutableList domainNames, - AllocationToken tokenEntity, - String registrarId, - DateTime now) { - return Maps.toMap(domainNames, domain -> domain.toString().contains("bunny") ? "fufu" : ""); - } - } }