mirror of
https://github.com/google/nomulus
synced 2025-12-23 14:25:44 +00:00
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?"
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
* <p>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<InternetDomainName, String> checkDomainsWithToken(
|
||||
ImmutableList<InternetDomainName> domainNames,
|
||||
AllocationToken token,
|
||||
String registrarId,
|
||||
DateTime now) {
|
||||
// Do nothing.
|
||||
return Maps.toMap(domainNames, k -> "");
|
||||
}
|
||||
}
|
||||
@@ -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<InternetDomainName> validDomainNames = new ImmutableList.Builder<>();
|
||||
ImmutableMap.Builder<InternetDomainName, String> 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(
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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<? extends EppException> 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<InternetDomainName, String> checkDomainsWithToken(
|
||||
ImmutableList<InternetDomainName> 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<InternetDomainName, String> checkDomainsWithToken(
|
||||
ImmutableList<InternetDomainName> domainNames,
|
||||
AllocationToken tokenEntity,
|
||||
String registrarId,
|
||||
DateTime now) {
|
||||
return Maps.toMap(domainNames, domain -> domain.toString().contains("bunny") ? "fufu" : "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user