Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ private static AllocationToken loadAndValidateToken(
VKey<AllocationToken> tokenKey = VKey.create(AllocationToken.class, token);
AllocationToken tokenEntity =
AllocationToken.get(tokenKey).orElseThrow(NonexistentAllocationTokenException::new);
if (tokenEntity.getTokenType().equals(AllocationToken.TokenType.SINGLE_USE)) {
if (tokenEntity.getTokenType().isOneTimeUse()) {
// Reload the token to avoid possible cache race conditions where the token may have already
// been redeemed
tokenEntity = tm().loadByKey(tokenKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2137,6 +2137,44 @@ void testSuccess_blockedByBsa_hasRegisterBsaToken() throws Exception {
assertSuccessfulCreate("tld", ImmutableSet.of(), allocationToken);
}

@Test
void testFailure_blockedByBsa_registerBsaTokenAlreadyRedeemedInDatabaseWithStaleCache()
throws Exception {
AllocationToken.setCacheForTest(Optional.of(Duration.ofMinutes(10)));
try {
enrollTldInBsa();
AllocationToken token =
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(REGISTER_BSA)
.setDomainName("example.tld")
.build());
persistBsaLabel("example");
persistHosts();
setEppInput(
"domain_create_allocationtoken.xml",
ImmutableMap.of("DOMAIN", "example.tld", "YEARS", "2"));
runFlow();
assertSuccessfulCreate("tld", ImmutableSet.of(), token);
assertAllocationTokenWasRedeemed("abc123");
// Cache still holds the unredeemed REGISTER_BSA token within its 10-minute TTL.
assertThat(AllocationToken.get(token.createVKey()).get().isRedeemed()).isFalse();

// Delete the created domain so a second registration of example.tld can be attempted.
Instant deletionTime = Instant.parse("1999-04-03T22:01:00.000Z");
persistResource(
reloadResourceByForeignKey().asBuilder().setDeletionTime(deletionTime).build());
clock.setTo(deletionTime.plusSeconds(1));

EppException thrown =
assertThrows(AlreadyRedeemedAllocationTokenException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} finally {
AllocationToken.setCacheForTest(Optional.empty());
}
}

@Test
void testSuccess_blockedByBsa_reservedDomain_viaAllocationTokenExtension() throws Exception {
enrollTldInBsa();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static google.registry.model.domain.token.AllocationToken.TokenStatus.NOT_STARTED;
import static google.registry.model.domain.token.AllocationToken.TokenStatus.VALID;
import static google.registry.model.domain.token.AllocationToken.TokenType.DEFAULT_PROMO;
import static google.registry.model.domain.token.AllocationToken.TokenType.REGISTER_BSA;
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
import static google.registry.model.domain.token.AllocationToken.TokenType.UNLIMITED_USE;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
Expand Down Expand Up @@ -307,6 +308,29 @@ void testFailure_loadFromExtension_singleUseTokenStaleCacheReloadsFromDatabase()
assertLoadTokenFromExtensionThrowsException(AlreadyRedeemedAllocationTokenException.class);
}

@Test
void testFailure_loadFromExtension_registerBsaTokenStaleCacheReloadsFromDatabase() {
when(allocationTokenExtension.getAllocationToken()).thenReturn("tokeN");
AllocationToken token =
persistResource(
new AllocationToken.Builder()
.setToken("tokeN")
.setTokenType(REGISTER_BSA)
.setDomainName("example.tld")
.build());
assertThat(AllocationToken.get(token.createVKey())).hasValue(token);
tm().transact(
() ->
tm().put(
token
.asBuilder()
.setRedemptionHistoryId(new HistoryEntryId("repoId", 1L))
.build()));
// Cache still returns the old unredeemed REGISTER_BSA token.
assertThat(AllocationToken.get(token.createVKey()).get().isRedeemed()).isFalse();
assertLoadTokenFromExtensionThrowsException(AlreadyRedeemedAllocationTokenException.class);
}

@Test
void testFailure_tokenInvalidForRegistrar() {
persistResource(
Expand Down
Loading