mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 00:17:20 +02:00
Clean up flow validation of registration periods
This tidies up some logic in the flows that checks registration periods, so that in the create flows we're consistently checking that the requested number of years is <= 10 right away (DomainCreateFlow was deferring it until very late, including after custom logic ran, for no good reason I can see). It also refactors the validateRegistrationPeriod() overload used by DomainRenewFlow to take the newExpirationTime directly, and just check to ensure that it's >= to now.plusYears(10) (with leap-safety just in case). This is a much simpler check than before, which recomputed the newExpirationTime separately from the logic used by DomainRenewFlow itself (always dangerous) and did a more convoluted and unnecessary comparison involving extendRegistrationWithCap(). ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=151002960
This commit is contained in:
parent
bb4a59203a
commit
ec4ffe53f0
5 changed files with 12 additions and 16 deletions
|
@ -144,8 +144,8 @@ public class DomainAllocateFlow implements TransactionalFlow {
|
||||||
InternetDomainName domainName = validateDomainName(command.getFullyQualifiedDomainName());
|
InternetDomainName domainName = validateDomainName(command.getFullyQualifiedDomainName());
|
||||||
Registry registry = Registry.get(domainName.parent().toString());
|
Registry registry = Registry.get(domainName.parent().toString());
|
||||||
Period period = command.getPeriod();
|
Period period = command.getPeriod();
|
||||||
Integer years = period.getValue();
|
|
||||||
verifyUnitIsYears(period);
|
verifyUnitIsYears(period);
|
||||||
|
int years = period.getValue();
|
||||||
validateRegistrationPeriod(years);
|
validateRegistrationPeriod(years);
|
||||||
validateCreateCommandContactsAndNameservers(command, registry, domainName);
|
validateCreateCommandContactsAndNameservers(command, registry, domainName);
|
||||||
SecDnsCreateExtension secDnsCreate =
|
SecDnsCreateExtension secDnsCreate =
|
||||||
|
|
|
@ -208,8 +208,6 @@ public final class DomainApplicationCreateFlow implements TransactionalFlow {
|
||||||
Registry registry = Registry.get(tld);
|
Registry registry = Registry.get(tld);
|
||||||
FeesAndCredits feesAndCredits =
|
FeesAndCredits feesAndCredits =
|
||||||
pricingLogic.getCreatePrice(registry, targetId, now, command.getPeriod().getValue());
|
pricingLogic.getCreatePrice(registry, targetId, now, command.getPeriod().getValue());
|
||||||
// Superusers can create reserved domains, force creations on domains that require a claims
|
|
||||||
// notice without specifying a claims key, and override blocks on registering premium domains.
|
|
||||||
verifyUnitIsYears(command.getPeriod());
|
verifyUnitIsYears(command.getPeriod());
|
||||||
int years = command.getPeriod().getValue();
|
int years = command.getPeriod().getValue();
|
||||||
validateRegistrationPeriod(years);
|
validateRegistrationPeriod(years);
|
||||||
|
@ -220,6 +218,8 @@ public final class DomainApplicationCreateFlow implements TransactionalFlow {
|
||||||
}
|
}
|
||||||
boolean isAnchorTenant =
|
boolean isAnchorTenant =
|
||||||
matchesAnchorTenantReservation(domainName, authInfo.getPw().getValue());
|
matchesAnchorTenantReservation(domainName, authInfo.getPw().getValue());
|
||||||
|
// Superusers can create reserved domains, force creations on domains that require a claims
|
||||||
|
// notice without specifying a claims key, and override blocks on registering premium domains.
|
||||||
if (!isSuperuser) {
|
if (!isSuperuser) {
|
||||||
verifyPremiumNameIsNotBlocked(targetId, now, clientId);
|
verifyPremiumNameIsNotBlocked(targetId, now, clientId);
|
||||||
prohibitLandrushIfExactlyOneSunrise(registry, now);
|
prohibitLandrushIfExactlyOneSunrise(registry, now);
|
||||||
|
|
|
@ -190,6 +190,7 @@ public class DomainCreateFlow implements TransactionalFlow {
|
||||||
Period period = command.getPeriod();
|
Period period = command.getPeriod();
|
||||||
verifyUnitIsYears(period);
|
verifyUnitIsYears(period);
|
||||||
int years = period.getValue();
|
int years = period.getValue();
|
||||||
|
validateRegistrationPeriod(years);
|
||||||
failfastForCreate(targetId, now);
|
failfastForCreate(targetId, now);
|
||||||
verifyResourceDoesNotExist(DomainResource.class, targetId, now);
|
verifyResourceDoesNotExist(DomainResource.class, targetId, now);
|
||||||
// Validate that this is actually a legal domain name on a TLD that the registrar has access to.
|
// Validate that this is actually a legal domain name on a TLD that the registrar has access to.
|
||||||
|
@ -248,7 +249,6 @@ public class DomainCreateFlow implements TransactionalFlow {
|
||||||
validateSecDnsExtension(eppInput.getSingleExtension(SecDnsCreateExtension.class));
|
validateSecDnsExtension(eppInput.getSingleExtension(SecDnsCreateExtension.class));
|
||||||
String repoId = createDomainRepoId(ObjectifyService.allocateId(), registry.getTldStr());
|
String repoId = createDomainRepoId(ObjectifyService.allocateId(), registry.getTldStr());
|
||||||
DateTime registrationExpirationTime = leapSafeAddYears(now, years);
|
DateTime registrationExpirationTime = leapSafeAddYears(now, years);
|
||||||
validateRegistrationPeriod(years);
|
|
||||||
HistoryEntry historyEntry = buildHistory(repoId, period, now);
|
HistoryEntry historyEntry = buildHistory(repoId, period, now);
|
||||||
// Bill for the create.
|
// Bill for the create.
|
||||||
BillingEvent.OneTime createBillingEvent =
|
BillingEvent.OneTime createBillingEvent =
|
||||||
|
|
|
@ -24,7 +24,6 @@ import static com.google.common.collect.Sets.union;
|
||||||
import static google.registry.flows.domain.DomainPricingLogic.getMatchingLrpToken;
|
import static google.registry.flows.domain.DomainPricingLogic.getMatchingLrpToken;
|
||||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||||
import static google.registry.model.domain.DomainResource.MAX_REGISTRATION_YEARS;
|
import static google.registry.model.domain.DomainResource.MAX_REGISTRATION_YEARS;
|
||||||
import static google.registry.model.domain.DomainResource.extendRegistrationWithCap;
|
|
||||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||||
import static google.registry.model.registry.Registries.findTldForName;
|
import static google.registry.model.registry.Registries.findTldForName;
|
||||||
import static google.registry.model.registry.label.ReservationType.NAMESERVER_RESTRICTED;
|
import static google.registry.model.registry.label.ReservationType.NAMESERVER_RESTRICTED;
|
||||||
|
@ -668,17 +667,14 @@ public class DomainFlowUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether a new registration period (via a renew) does not extend beyond a maximum number
|
* Check whether a new expiration time (via a renew) does not extend beyond a maximum number of
|
||||||
* of years (e.g. {@link DomainResource#MAX_REGISTRATION_YEARS}).
|
* years (e.g. {@link DomainResource#MAX_REGISTRATION_YEARS}) from "now".
|
||||||
*
|
*
|
||||||
* @throws ExceedsMaxRegistrationYearsException if the new registration period is too long
|
* @throws ExceedsMaxRegistrationYearsException if the new registration period is too long
|
||||||
*/
|
*/
|
||||||
public static void validateRegistrationPeriod(
|
public static void validateRegistrationPeriod(DateTime now, DateTime newExpirationTime)
|
||||||
DateTime now,
|
throws EppException {
|
||||||
DateTime oldExpirationTime,
|
if (leapSafeAddYears(now, MAX_REGISTRATION_YEARS).isBefore(newExpirationTime)) {
|
||||||
int years) throws EppException {
|
|
||||||
DateTime newExpirationTime = leapSafeAddYears(oldExpirationTime, years); // uncapped
|
|
||||||
if (extendRegistrationWithCap(now, oldExpirationTime, years).isBefore(newExpirationTime)) {
|
|
||||||
throw new ExceedsMaxRegistrationYearsException();
|
throw new ExceedsMaxRegistrationYearsException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,6 +133,9 @@ public final class DomainRenewFlow implements TransactionalFlow {
|
||||||
DomainResource existingDomain = loadAndVerifyExistence(DomainResource.class, targetId, now);
|
DomainResource existingDomain = loadAndVerifyExistence(DomainResource.class, targetId, now);
|
||||||
verifyRenewAllowed(authInfo, existingDomain, command);
|
verifyRenewAllowed(authInfo, existingDomain, command);
|
||||||
int years = command.getPeriod().getValue();
|
int years = command.getPeriod().getValue();
|
||||||
|
DateTime newExpirationTime =
|
||||||
|
leapSafeAddYears(existingDomain.getRegistrationExpirationTime(), years); // Uncapped
|
||||||
|
validateRegistrationPeriod(now, newExpirationTime);
|
||||||
FeeRenewCommandExtension feeRenew =
|
FeeRenewCommandExtension feeRenew =
|
||||||
eppInput.getSingleExtension(FeeRenewCommandExtension.class);
|
eppInput.getSingleExtension(FeeRenewCommandExtension.class);
|
||||||
FeesAndCredits feesAndCredits =
|
FeesAndCredits feesAndCredits =
|
||||||
|
@ -150,9 +153,6 @@ public final class DomainRenewFlow implements TransactionalFlow {
|
||||||
.setModificationTime(now)
|
.setModificationTime(now)
|
||||||
.setParent(Key.create(existingDomain))
|
.setParent(Key.create(existingDomain))
|
||||||
.build();
|
.build();
|
||||||
DateTime oldExpirationTime = existingDomain.getRegistrationExpirationTime();
|
|
||||||
DateTime newExpirationTime = leapSafeAddYears(oldExpirationTime, years); // Uncapped
|
|
||||||
validateRegistrationPeriod(now, oldExpirationTime, years);
|
|
||||||
String tld = existingDomain.getTld();
|
String tld = existingDomain.getTld();
|
||||||
// Bill for this explicit renew itself.
|
// Bill for this explicit renew itself.
|
||||||
BillingEvent.OneTime explicitRenewEvent =
|
BillingEvent.OneTime explicitRenewEvent =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue