mirror of
https://github.com/google/nomulus.git
synced 2025-07-27 04:58:37 +02:00
Check token type of currentPackageToken (#1825)
* Check currentPackageToken TokenType * Check TokenType of currentPackageToken * Check that token already exists
This commit is contained in:
parent
aaa311ec40
commit
0746d28e0c
3 changed files with 72 additions and 14 deletions
|
@ -55,6 +55,7 @@ import google.registry.model.domain.launch.LaunchNotice;
|
||||||
import google.registry.model.domain.rgp.GracePeriodStatus;
|
import google.registry.model.domain.rgp.GracePeriodStatus;
|
||||||
import google.registry.model.domain.secdns.DomainDsData;
|
import google.registry.model.domain.secdns.DomainDsData;
|
||||||
import google.registry.model.domain.token.AllocationToken;
|
import google.registry.model.domain.token.AllocationToken;
|
||||||
|
import google.registry.model.domain.token.AllocationToken.TokenType;
|
||||||
import google.registry.model.eppcommon.StatusValue;
|
import google.registry.model.eppcommon.StatusValue;
|
||||||
import google.registry.model.host.Host;
|
import google.registry.model.host.Host;
|
||||||
import google.registry.model.poll.PollMessage;
|
import google.registry.model.poll.PollMessage;
|
||||||
|
@ -919,6 +920,21 @@ public class DomainBase extends EppResource
|
||||||
}
|
}
|
||||||
|
|
||||||
public B setCurrentPackageToken(@Nullable VKey<AllocationToken> currentPackageToken) {
|
public B setCurrentPackageToken(@Nullable VKey<AllocationToken> currentPackageToken) {
|
||||||
|
if (currentPackageToken == null) {
|
||||||
|
getInstance().currentPackageToken = currentPackageToken;
|
||||||
|
return thisCastToDerived();
|
||||||
|
}
|
||||||
|
AllocationToken token =
|
||||||
|
tm().transact(() -> tm().loadByKeyIfPresent(currentPackageToken))
|
||||||
|
.orElseThrow(
|
||||||
|
() ->
|
||||||
|
new IllegalArgumentException(
|
||||||
|
String.format(
|
||||||
|
"The package token %s does not exist",
|
||||||
|
currentPackageToken.getSqlKey())));
|
||||||
|
checkArgument(
|
||||||
|
token.getTokenType().equals(TokenType.PACKAGE),
|
||||||
|
"The currentPackageToken must have a PACKAGE TokenType");
|
||||||
getInstance().currentPackageToken = currentPackageToken;
|
getInstance().currentPackageToken = currentPackageToken;
|
||||||
return thisCastToDerived();
|
return thisCastToDerived();
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ package google.registry.model.domain;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
|
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
|
||||||
import static google.registry.model.domain.token.AllocationToken.TokenStatus.NOT_STARTED;
|
import static google.registry.model.domain.token.AllocationToken.TokenStatus.NOT_STARTED;
|
||||||
import static google.registry.model.domain.token.AllocationToken.TokenType.UNLIMITED_USE;
|
import static google.registry.model.domain.token.AllocationToken.TokenType.PACKAGE;
|
||||||
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
|
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
|
||||||
import static google.registry.testing.DatabaseHelper.createTld;
|
import static google.registry.testing.DatabaseHelper.createTld;
|
||||||
import static google.registry.testing.DatabaseHelper.insertInDb;
|
import static google.registry.testing.DatabaseHelper.insertInDb;
|
||||||
|
@ -39,6 +39,7 @@ import com.googlecode.objectify.Key;
|
||||||
import google.registry.model.billing.BillingEvent;
|
import google.registry.model.billing.BillingEvent;
|
||||||
import google.registry.model.billing.BillingEvent.Flag;
|
import google.registry.model.billing.BillingEvent.Flag;
|
||||||
import google.registry.model.billing.BillingEvent.Reason;
|
import google.registry.model.billing.BillingEvent.Reason;
|
||||||
|
import google.registry.model.billing.BillingEvent.RenewalPriceBehavior;
|
||||||
import google.registry.model.contact.Contact;
|
import google.registry.model.contact.Contact;
|
||||||
import google.registry.model.domain.DesignatedContact.Type;
|
import google.registry.model.domain.DesignatedContact.Type;
|
||||||
import google.registry.model.domain.launch.LaunchNotice;
|
import google.registry.model.domain.launch.LaunchNotice;
|
||||||
|
@ -144,13 +145,11 @@ public class DomainSqlTest {
|
||||||
allocationToken =
|
allocationToken =
|
||||||
new AllocationToken.Builder()
|
new AllocationToken.Builder()
|
||||||
.setToken("abc123Unlimited")
|
.setToken("abc123Unlimited")
|
||||||
.setTokenType(UNLIMITED_USE)
|
.setTokenType(PACKAGE)
|
||||||
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
|
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
|
||||||
.setAllowedTlds(ImmutableSet.of("dev", "app"))
|
.setAllowedTlds(ImmutableSet.of("dev", "app"))
|
||||||
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar, NewRegistrar"))
|
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
|
||||||
.setDiscountFraction(0.5)
|
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
|
||||||
.setDiscountPremiums(true)
|
|
||||||
.setDiscountYears(3)
|
|
||||||
.setTokenStatusTransitions(
|
.setTokenStatusTransitions(
|
||||||
ImmutableSortedMap.<DateTime, TokenStatus>naturalOrder()
|
ImmutableSortedMap.<DateTime, TokenStatus>naturalOrder()
|
||||||
.put(START_OF_TIME, NOT_STARTED)
|
.put(START_OF_TIME, NOT_STARTED)
|
||||||
|
@ -168,8 +167,8 @@ public class DomainSqlTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDomainBasePersistenceWithCurrentPackageToken() {
|
void testDomainBasePersistenceWithCurrentPackageToken() {
|
||||||
domain = domain.asBuilder().setCurrentPackageToken(allocationToken.createVKey()).build();
|
|
||||||
persistResource(allocationToken);
|
persistResource(allocationToken);
|
||||||
|
domain = domain.asBuilder().setCurrentPackageToken(allocationToken.createVKey()).build();
|
||||||
persistDomain();
|
persistDomain();
|
||||||
assertEqualDomainExcept(loadByKey(domain.createVKey()));
|
assertEqualDomainExcept(loadByKey(domain.createVKey()));
|
||||||
}
|
}
|
||||||
|
@ -180,13 +179,6 @@ public class DomainSqlTest {
|
||||||
assertThrowForeignKeyViolation(() -> insertInDb(contact, contact2, domain));
|
assertThrowForeignKeyViolation(() -> insertInDb(contact, contact2, domain));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void testCurrentPackageTokenForeignKeyConstraints() {
|
|
||||||
// Persist the domain without the associated allocation token object.
|
|
||||||
domain = domain.asBuilder().setCurrentPackageToken(allocationToken.createVKey()).build();
|
|
||||||
assertThrowForeignKeyViolation(() -> persistDomain());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testContactForeignKeyConstraints() {
|
void testContactForeignKeyConstraints() {
|
||||||
// Persist the domain without the associated contact objects.
|
// Persist the domain without the associated contact objects.
|
||||||
|
|
|
@ -19,6 +19,8 @@ import static com.google.common.collect.Iterables.getOnlyElement;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static com.google.common.truth.Truth8.assertThat;
|
import static com.google.common.truth.Truth8.assertThat;
|
||||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||||
|
import static google.registry.model.domain.token.AllocationToken.TokenType.PACKAGE;
|
||||||
|
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
|
||||||
import static google.registry.testing.DatabaseHelper.cloneAndSetAutoTimestamps;
|
import static google.registry.testing.DatabaseHelper.cloneAndSetAutoTimestamps;
|
||||||
import static google.registry.testing.DatabaseHelper.createTld;
|
import static google.registry.testing.DatabaseHelper.createTld;
|
||||||
import static google.registry.testing.DatabaseHelper.insertInDb;
|
import static google.registry.testing.DatabaseHelper.insertInDb;
|
||||||
|
@ -46,11 +48,13 @@ import google.registry.model.ImmutableObjectSubject;
|
||||||
import google.registry.model.billing.BillingEvent;
|
import google.registry.model.billing.BillingEvent;
|
||||||
import google.registry.model.billing.BillingEvent.Flag;
|
import google.registry.model.billing.BillingEvent.Flag;
|
||||||
import google.registry.model.billing.BillingEvent.Reason;
|
import google.registry.model.billing.BillingEvent.Reason;
|
||||||
|
import google.registry.model.billing.BillingEvent.RenewalPriceBehavior;
|
||||||
import google.registry.model.contact.Contact;
|
import google.registry.model.contact.Contact;
|
||||||
import google.registry.model.domain.DesignatedContact.Type;
|
import google.registry.model.domain.DesignatedContact.Type;
|
||||||
import google.registry.model.domain.launch.LaunchNotice;
|
import google.registry.model.domain.launch.LaunchNotice;
|
||||||
import google.registry.model.domain.rgp.GracePeriodStatus;
|
import google.registry.model.domain.rgp.GracePeriodStatus;
|
||||||
import google.registry.model.domain.secdns.DomainDsData;
|
import google.registry.model.domain.secdns.DomainDsData;
|
||||||
|
import google.registry.model.domain.token.AllocationToken;
|
||||||
import google.registry.model.eppcommon.AuthInfo.PasswordAuth;
|
import google.registry.model.eppcommon.AuthInfo.PasswordAuth;
|
||||||
import google.registry.model.eppcommon.StatusValue;
|
import google.registry.model.eppcommon.StatusValue;
|
||||||
import google.registry.model.eppcommon.Trid;
|
import google.registry.model.eppcommon.Trid;
|
||||||
|
@ -978,4 +982,50 @@ public class DomainTest {
|
||||||
assertThat(domain.getBillingContact()).isNull();
|
assertThat(domain.getBillingContact()).isNull();
|
||||||
assertThat(domain.getTechContact()).isNull();
|
assertThat(domain.getTechContact()).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testFail_currentPackageTokenWrongPackageType() {
|
||||||
|
AllocationToken allocationToken =
|
||||||
|
persistResource(
|
||||||
|
new AllocationToken.Builder().setToken("abc123").setTokenType(SINGLE_USE).build());
|
||||||
|
IllegalArgumentException thrown =
|
||||||
|
assertThrows(
|
||||||
|
IllegalArgumentException.class,
|
||||||
|
() -> domain.asBuilder().setCurrentPackageToken(allocationToken.createVKey()).build());
|
||||||
|
assertThat(thrown)
|
||||||
|
.hasMessageThat()
|
||||||
|
.isEqualTo("The currentPackageToken must have a PACKAGE TokenType");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testFailure_packageTokenDoesNotExist() {
|
||||||
|
AllocationToken allocationToken =
|
||||||
|
new AllocationToken.Builder()
|
||||||
|
.setToken("abc123")
|
||||||
|
.setTokenType(PACKAGE)
|
||||||
|
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
|
||||||
|
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
|
||||||
|
.build();
|
||||||
|
IllegalArgumentException thrown =
|
||||||
|
assertThrows(
|
||||||
|
IllegalArgumentException.class,
|
||||||
|
() -> domain.asBuilder().setCurrentPackageToken(allocationToken.createVKey()).build());
|
||||||
|
assertThat(thrown).hasMessageThat().isEqualTo("The package token abc123 does not exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testSuccess_removeCurrentPackageToken() {
|
||||||
|
AllocationToken allocationToken =
|
||||||
|
persistResource(
|
||||||
|
new AllocationToken.Builder()
|
||||||
|
.setToken("abc123")
|
||||||
|
.setTokenType(PACKAGE)
|
||||||
|
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
|
||||||
|
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
|
||||||
|
.build());
|
||||||
|
domain = domain.asBuilder().setCurrentPackageToken(allocationToken.createVKey()).build();
|
||||||
|
assertThat(domain.getCurrentPackageToken().get()).isEqualTo(allocationToken.createVKey());
|
||||||
|
domain = domain.asBuilder().setCurrentPackageToken(null).build();
|
||||||
|
assertThat(domain.getCurrentPackageToken()).isEmpty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue