mirror of
https://github.com/google/nomulus.git
synced 2025-06-27 06:44:51 +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
|
@ -24,7 +24,6 @@ import static com.google.common.collect.Sets.union;
|
|||
import static google.registry.flows.domain.DomainPricingLogic.getMatchingLrpToken;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||
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.registry.Registries.findTldForName;
|
||||
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
|
||||
* of years (e.g. {@link DomainResource#MAX_REGISTRATION_YEARS}).
|
||||
* Check whether a new expiration time (via a renew) does not extend beyond a maximum number of
|
||||
* years (e.g. {@link DomainResource#MAX_REGISTRATION_YEARS}) from "now".
|
||||
*
|
||||
* @throws ExceedsMaxRegistrationYearsException if the new registration period is too long
|
||||
*/
|
||||
public static void validateRegistrationPeriod(
|
||||
DateTime now,
|
||||
DateTime oldExpirationTime,
|
||||
int years) throws EppException {
|
||||
DateTime newExpirationTime = leapSafeAddYears(oldExpirationTime, years); // uncapped
|
||||
if (extendRegistrationWithCap(now, oldExpirationTime, years).isBefore(newExpirationTime)) {
|
||||
public static void validateRegistrationPeriod(DateTime now, DateTime newExpirationTime)
|
||||
throws EppException {
|
||||
if (leapSafeAddYears(now, MAX_REGISTRATION_YEARS).isBefore(newExpirationTime)) {
|
||||
throw new ExceedsMaxRegistrationYearsException();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue