mirror of
https://github.com/google/nomulus
synced 2026-07-11 18:42:25 +00:00
Enforce non-negative SPECIFIED prices (#3140)
This applies to both allocation tokens and billing recurrences
This commit is contained in:
@@ -191,6 +191,10 @@ public class BillingRecurrence extends BillingBase {
|
||||
^ instance.renewalPrice == null,
|
||||
"Renewal price can have a value if and only if the renewal price behavior is"
|
||||
+ " SPECIFIED");
|
||||
if (instance.renewalPrice != null) {
|
||||
checkArgument(
|
||||
instance.renewalPrice.isPositiveOrZero(), "SPECIFIED renewal price cannot be negative");
|
||||
}
|
||||
instance.recurrenceTimeOfYear = TimeOfYear.fromInstant(instance.eventTime);
|
||||
instance.recurrenceEndTime =
|
||||
Optional.ofNullable(instance.recurrenceEndTime).orElse(END_INSTANT);
|
||||
|
||||
@@ -462,6 +462,10 @@ public class AllocationToken extends UpdateAutoTimestampEntity implements Builda
|
||||
getInstance().renewalPriceBehavior.equals(RenewalPriceBehavior.SPECIFIED)
|
||||
== (getInstance().renewalPrice != null),
|
||||
"renewalPrice must be specified iff renewalPriceBehavior is SPECIFIED");
|
||||
if (getInstance().renewalPrice != null) {
|
||||
checkArgument(
|
||||
getInstance().renewalPrice.isPositiveOrZero(), "Renewal price cannot be negative");
|
||||
}
|
||||
|
||||
if (getInstance().tokenType.equals(TokenType.BULK_PRICING)) {
|
||||
checkArgument(
|
||||
|
||||
@@ -890,4 +890,23 @@ public class BillingBaseTest extends EntityTestCase {
|
||||
"Renewal price can have a value if and only if the "
|
||||
+ "renewal price behavior is SPECIFIED");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFailure_buildWithSpecifiedRenewalBehavior_negativeRenewalPrice() {
|
||||
assertThat(
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
new BillingRecurrence.Builder()
|
||||
.setDomainHistory(domainHistory)
|
||||
.setFlags(ImmutableSet.of(Flag.AUTO_RENEW))
|
||||
.setReason(Reason.RENEW)
|
||||
.setEventTime(plusYears(now, 1))
|
||||
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
|
||||
.setRenewalPrice(Money.of(USD, -100))
|
||||
.setRecurrenceEndTime(END_INSTANT)
|
||||
.build()))
|
||||
.hasMessageThat()
|
||||
.isEqualTo("SPECIFIED renewal price cannot be negative");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -612,6 +612,22 @@ public class AllocationTokenTest extends EntityTestCase {
|
||||
.isEqualTo("renewalPrice must be specified iff renewalPriceBehavior is SPECIFIED");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBuild_negativeRenewalPrice() {
|
||||
assertThat(
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
new AllocationToken.Builder()
|
||||
.setToken("abc")
|
||||
.setTokenType(SINGLE_USE)
|
||||
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
|
||||
.setRenewalPrice(Money.of(CurrencyUnit.USD, -5))
|
||||
.build()))
|
||||
.hasMessageThat()
|
||||
.isEqualTo("Renewal price cannot be negative");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBuild_registrationBehaviors() {
|
||||
createTld("tld");
|
||||
|
||||
Reference in New Issue
Block a user