From 63b218a0b8f9605834b4ecc77f12d2f2b0e9389f Mon Sep 17 00:00:00 2001 From: sarahcaseybot Date: Mon, 3 Oct 2022 14:27:10 -0400 Subject: [PATCH] Don't allow package tokens to discount premium names (#1804) --- .../registry/model/domain/token/AllocationToken.java | 3 +++ .../model/domain/token/AllocationTokenTest.java | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/core/src/main/java/google/registry/model/domain/token/AllocationToken.java b/core/src/main/java/google/registry/model/domain/token/AllocationToken.java index bc60dd0eb..abc8e6851 100644 --- a/core/src/main/java/google/registry/model/domain/token/AllocationToken.java +++ b/core/src/main/java/google/registry/model/domain/token/AllocationToken.java @@ -300,6 +300,9 @@ public class AllocationToken extends BackupGroupRoot implements Buildable { !getInstance().tokenType.equals(TokenType.PACKAGE) || getInstance().renewalPriceBehavior.equals(RenewalPriceBehavior.SPECIFIED), "Package tokens must have renewalPriceBehavior set to SPECIFIED"); + checkArgument( + !getInstance().tokenType.equals(TokenType.PACKAGE) || !getInstance().discountPremiums, + "Package tokens cannot discount premium names"); checkArgument( getInstance().domainName == null || TokenType.SINGLE_USE.equals(getInstance().tokenType), "Domain name can only be specified for SINGLE_USE tokens"); diff --git a/core/src/test/java/google/registry/model/domain/token/AllocationTokenTest.java b/core/src/test/java/google/registry/model/domain/token/AllocationTokenTest.java index d89d89a7b..b863edd33 100644 --- a/core/src/test/java/google/registry/model/domain/token/AllocationTokenTest.java +++ b/core/src/test/java/google/registry/model/domain/token/AllocationTokenTest.java @@ -228,6 +228,18 @@ public class AllocationTokenTest extends EntityTestCase { .isEqualTo("Package tokens must have renewalPriceBehavior set to SPECIFIED"); } + @Test + void testFail_packageTokenDiscountPremium() { + AllocationToken.Builder builder = + new AllocationToken.Builder() + .setToken("abc123") + .setTokenType(TokenType.PACKAGE) + .setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED) + .setDiscountPremiums(true); + IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, builder::build); + assertThat(thrown).hasMessageThat().isEqualTo("Package tokens cannot discount premium names"); + } + @Test void testBuild_DomainNameWithLessThanTwoParts() { IllegalArgumentException thrown =