mirror of
https://github.com/google/nomulus.git
synced 2025-07-09 04:33:28 +02:00
Add unlock fields to RegistryLocks (#408)
* Add unlock fields to RegistryLocks This will make it easier to reason around inter-connected registry lock objects (like when we add dependent roids). It will make it easier to answer the question of "Have all locks associated with this host/contact roid been unlocked?", as well as the question of "Was the last lock object associated with this domain unlocked?" * Responses to CR * Make the DAO API more specific * whoops, undo rename
This commit is contained in:
parent
dd0e3b7c24
commit
c17a5c489c
8 changed files with 157 additions and 80 deletions
|
@ -22,7 +22,6 @@ import static google.registry.testing.JUnitBackports.assertThrows;
|
|||
import google.registry.model.transaction.JpaTestRules;
|
||||
import google.registry.model.transaction.JpaTestRules.JpaIntegrationTestRule;
|
||||
import google.registry.schema.domain.RegistryLock;
|
||||
import google.registry.schema.domain.RegistryLock.Action;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
@ -48,6 +47,7 @@ public final class RegistryLockDaoTest {
|
|||
RegistryLock fromDatabase = RegistryLockDao.getByVerificationCode(lock.getVerificationCode());
|
||||
assertThat(fromDatabase.getDomainName()).isEqualTo(lock.getDomainName());
|
||||
assertThat(fromDatabase.getVerificationCode()).isEqualTo(lock.getVerificationCode());
|
||||
assertThat(fromDatabase.getLastUpdateTimestamp()).isEqualTo(jpaRule.getTxnClock().nowUtc());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -71,32 +71,56 @@ public final class RegistryLockDaoTest {
|
|||
() -> {
|
||||
RegistryLock updatedLock =
|
||||
RegistryLockDao.getByVerificationCode(lock.getVerificationCode());
|
||||
updatedLock.setCompletionTimestamp(jpaRule.getTxnClock().nowUtc());
|
||||
RegistryLockDao.save(updatedLock);
|
||||
RegistryLockDao.save(
|
||||
updatedLock
|
||||
.asBuilder()
|
||||
.setLockCompletionTimestamp(jpaRule.getTxnClock().nowUtc())
|
||||
.build());
|
||||
});
|
||||
jpaTm()
|
||||
.transact(
|
||||
() -> {
|
||||
RegistryLock fromDatabase =
|
||||
RegistryLockDao.getByVerificationCode(lock.getVerificationCode());
|
||||
assertThat(fromDatabase.getCompletionTimestamp().get())
|
||||
assertThat(fromDatabase.getLockCompletionTimestamp().get())
|
||||
.isEqualTo(jpaRule.getTxnClock().nowUtc());
|
||||
assertThat(fromDatabase.getLastUpdateTimestamp())
|
||||
.isEqualTo(jpaRule.getTxnClock().nowUtc());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSave_load_withUnlock() {
|
||||
RegistryLock lock =
|
||||
RegistryLockDao.save(
|
||||
createLock()
|
||||
.asBuilder()
|
||||
.setLockCompletionTimestamp(jpaRule.getTxnClock().nowUtc())
|
||||
.setUnlockRequestTimestamp(jpaRule.getTxnClock().nowUtc())
|
||||
.setUnlockCompletionTimestamp(jpaRule.getTxnClock().nowUtc())
|
||||
.build());
|
||||
RegistryLockDao.save(lock);
|
||||
RegistryLock fromDatabase = RegistryLockDao.getByVerificationCode(lock.getVerificationCode());
|
||||
assertThat(fromDatabase.getUnlockRequestTimestamp())
|
||||
.isEqualTo(Optional.of(jpaRule.getTxnClock().nowUtc()));
|
||||
assertThat(fromDatabase.getUnlockCompletionTimestamp())
|
||||
.isEqualTo(Optional.of(jpaRule.getTxnClock().nowUtc()));
|
||||
assertThat(fromDatabase.isLocked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateLock_usingSamePrimaryKey() {
|
||||
RegistryLock lock = RegistryLockDao.save(createLock());
|
||||
jpaRule.getTxnClock().advanceOneMilli();
|
||||
RegistryLock updatedLock =
|
||||
lock.asBuilder().setCompletionTimestamp(jpaRule.getTxnClock().nowUtc()).build();
|
||||
lock.asBuilder().setLockCompletionTimestamp(jpaRule.getTxnClock().nowUtc()).build();
|
||||
jpaTm().transact(() -> RegistryLockDao.save(updatedLock));
|
||||
jpaTm()
|
||||
.transact(
|
||||
() -> {
|
||||
RegistryLock fromDatabase =
|
||||
RegistryLockDao.getByVerificationCode(lock.getVerificationCode());
|
||||
assertThat(fromDatabase.getCompletionTimestamp())
|
||||
assertThat(fromDatabase.getLockCompletionTimestamp())
|
||||
.isEqualTo(Optional.of(jpaRule.getTxnClock().nowUtc()));
|
||||
});
|
||||
}
|
||||
|
@ -107,24 +131,39 @@ public final class RegistryLockDaoTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testLoad_byRegistrarId() {
|
||||
RegistryLock lock = createLock();
|
||||
RegistryLock secondLock = createLock().asBuilder().setDomainName("otherexample.test").build();
|
||||
public void testLoad_lockedDomains_byRegistrarId() {
|
||||
RegistryLock lock =
|
||||
createLock().asBuilder().setLockCompletionTimestamp(jpaRule.getTxnClock().nowUtc()).build();
|
||||
RegistryLock secondLock =
|
||||
createLock()
|
||||
.asBuilder()
|
||||
.setDomainName("otherexample.test")
|
||||
.setLockCompletionTimestamp(jpaRule.getTxnClock().nowUtc())
|
||||
.build();
|
||||
RegistryLock unlockedLock =
|
||||
createLock()
|
||||
.asBuilder()
|
||||
.setDomainName("unlocked.test")
|
||||
.setLockCompletionTimestamp(jpaRule.getTxnClock().nowUtc())
|
||||
.setUnlockRequestTimestamp(jpaRule.getTxnClock().nowUtc())
|
||||
.setUnlockCompletionTimestamp(jpaRule.getTxnClock().nowUtc())
|
||||
.build();
|
||||
RegistryLockDao.save(lock);
|
||||
RegistryLockDao.save(secondLock);
|
||||
RegistryLockDao.save(unlockedLock);
|
||||
|
||||
assertThat(
|
||||
RegistryLockDao.getByRegistrarId("TheRegistrar").stream()
|
||||
RegistryLockDao.getLockedDomainsByRegistrarId("TheRegistrar").stream()
|
||||
.map(RegistryLock::getDomainName)
|
||||
.collect(toImmutableSet()))
|
||||
.containsExactly("example.test", "otherexample.test");
|
||||
assertThat(RegistryLockDao.getByRegistrarId("nonexistent")).isEmpty();
|
||||
assertThat(RegistryLockDao.getLockedDomainsByRegistrarId("nonexistent")).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoad_byRepoId() {
|
||||
RegistryLock completedLock =
|
||||
createLock().asBuilder().setCompletionTimestamp(jpaRule.getTxnClock().nowUtc()).build();
|
||||
createLock().asBuilder().setLockCompletionTimestamp(jpaRule.getTxnClock().nowUtc()).build();
|
||||
RegistryLockDao.save(completedLock);
|
||||
|
||||
jpaRule.getTxnClock().advanceOneMilli();
|
||||
|
@ -133,7 +172,7 @@ public final class RegistryLockDaoTest {
|
|||
|
||||
Optional<RegistryLock> mostRecent = RegistryLockDao.getMostRecentByRepoId("repoId");
|
||||
assertThat(mostRecent.isPresent()).isTrue();
|
||||
assertThat(mostRecent.get().isVerified()).isFalse();
|
||||
assertThat(mostRecent.get().isLocked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -146,7 +185,6 @@ public final class RegistryLockDaoTest {
|
|||
.setRepoId("repoId")
|
||||
.setDomainName("example.test")
|
||||
.setRegistrarId("TheRegistrar")
|
||||
.setAction(Action.LOCK)
|
||||
.setVerificationCode(UUID.randomUUID().toString())
|
||||
.isSuperuser(true)
|
||||
.build();
|
||||
|
|
|
@ -38,7 +38,6 @@ import google.registry.request.auth.AuthResult;
|
|||
import google.registry.request.auth.AuthenticatedRegistrarAccessor;
|
||||
import google.registry.request.auth.UserAuthInfo;
|
||||
import google.registry.schema.domain.RegistryLock;
|
||||
import google.registry.schema.domain.RegistryLock.Action;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import google.registry.testing.FakeResponse;
|
||||
import java.util.Map;
|
||||
|
@ -95,10 +94,9 @@ public final class RegistryLockGetActionTest {
|
|||
.setRepoId("repoId")
|
||||
.setDomainName("example.test")
|
||||
.setRegistrarId("TheRegistrar")
|
||||
.setAction(Action.LOCK)
|
||||
.setVerificationCode(UUID.randomUUID().toString())
|
||||
.setRegistrarPocId("johndoe@theregistrar.com")
|
||||
.setCompletionTimestamp(jpaRule.getTxnClock().nowUtc())
|
||||
.setLockCompletionTimestamp(jpaRule.getTxnClock().nowUtc())
|
||||
.build();
|
||||
jpaRule.getTxnClock().advanceOneMilli();
|
||||
RegistryLock adminLock =
|
||||
|
@ -106,24 +104,35 @@ public final class RegistryLockGetActionTest {
|
|||
.setRepoId("repoId")
|
||||
.setDomainName("adminexample.test")
|
||||
.setRegistrarId("TheRegistrar")
|
||||
.setAction(Action.LOCK)
|
||||
.setVerificationCode(UUID.randomUUID().toString())
|
||||
.isSuperuser(true)
|
||||
.setCompletionTimestamp(jpaRule.getTxnClock().nowUtc())
|
||||
.setLockCompletionTimestamp(jpaRule.getTxnClock().nowUtc())
|
||||
.build();
|
||||
RegistryLock incompleteLock =
|
||||
new RegistryLock.Builder()
|
||||
.setRepoId("repoId")
|
||||
.setDomainName("incomplete.test")
|
||||
.setRegistrarId("TheRegistrar")
|
||||
.setAction(Action.LOCK)
|
||||
.setVerificationCode(UUID.randomUUID().toString())
|
||||
.setRegistrarPocId("johndoe@theregistrar.com")
|
||||
.build();
|
||||
|
||||
RegistryLock unlockedLock =
|
||||
new RegistryLock.Builder()
|
||||
.setRepoId("repoId")
|
||||
.setDomainName("unlocked.test")
|
||||
.setRegistrarId("TheRegistrar")
|
||||
.setRegistrarPocId("johndoe@theregistrar.com")
|
||||
.setVerificationCode(UUID.randomUUID().toString())
|
||||
.setLockCompletionTimestamp(jpaRule.getTxnClock().nowUtc())
|
||||
.setUnlockRequestTimestamp(jpaRule.getTxnClock().nowUtc())
|
||||
.setUnlockCompletionTimestamp(jpaRule.getTxnClock().nowUtc())
|
||||
.build();
|
||||
|
||||
RegistryLockDao.save(regularLock);
|
||||
RegistryLockDao.save(adminLock);
|
||||
RegistryLockDao.save(incompleteLock);
|
||||
RegistryLockDao.save(unlockedLock);
|
||||
|
||||
action.run();
|
||||
assertThat(response.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
||||
|
@ -134,9 +143,12 @@ public final class RegistryLockGetActionTest {
|
|||
"results",
|
||||
ImmutableList.of(
|
||||
ImmutableMap.of(
|
||||
"lockEnabledForContact", true,
|
||||
"email", "Marla.Singer@crr.com",
|
||||
"clientId", "TheRegistrar",
|
||||
"lockEnabledForContact",
|
||||
true,
|
||||
"email",
|
||||
"Marla.Singer@crr.com",
|
||||
"clientId",
|
||||
"TheRegistrar",
|
||||
"locks",
|
||||
ImmutableList.of(
|
||||
ImmutableMap.of(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue