From 63377631064c32ece868082463099d4016df8679 Mon Sep 17 00:00:00 2001 From: Mike Wacker <11431865+mikewacker@users.noreply.github.com> Date: Sat, 18 Jan 2025 22:58:27 -0700 Subject: [PATCH] fix updating verification for account (#376) --- .../module/store/demo/DemoSiteVerificationStore.java | 8 +++++--- .../module/store/demo/DemoSiteAccountStoreTest.java | 10 ++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/module/store-demo/src/main/java/org/example/age/module/store/demo/DemoSiteVerificationStore.java b/module/store-demo/src/main/java/org/example/age/module/store/demo/DemoSiteVerificationStore.java index 05196642..c34b5d09 100644 --- a/module/store-demo/src/main/java/org/example/age/module/store/demo/DemoSiteVerificationStore.java +++ b/module/store-demo/src/main/java/org/example/age/module/store/demo/DemoSiteVerificationStore.java @@ -45,9 +45,11 @@ public CompletionStage> trySave(String accountId, VerifiedUser Optional maybeConflictingAccountId = Optional.ofNullable(verifiedAccounts.get(user.getPseudonym())); if (maybeConflictingAccountId.isPresent()) { String conflictingAccountId = maybeConflictingAccountId.get(); - VerificationState conflictingState = loadAndUpdate(conflictingAccountId); - if (conflictingState.getStatus() == VerificationStatus.VERIFIED) { - return CompletableFuture.completedFuture(Optional.of(conflictingAccountId)); + if (!conflictingAccountId.equals(accountId)) { + VerificationState conflictingState = loadAndUpdate(conflictingAccountId); + if (conflictingState.getStatus() == VerificationStatus.VERIFIED) { + return CompletableFuture.completedFuture(Optional.of(conflictingAccountId)); + } } } diff --git a/module/store-demo/src/test/java/org/example/age/module/store/demo/DemoSiteAccountStoreTest.java b/module/store-demo/src/test/java/org/example/age/module/store/demo/DemoSiteAccountStoreTest.java index 6496bf0e..774dd028 100644 --- a/module/store-demo/src/test/java/org/example/age/module/store/demo/DemoSiteAccountStoreTest.java +++ b/module/store-demo/src/test/java/org/example/age/module/store/demo/DemoSiteAccountStoreTest.java @@ -39,6 +39,16 @@ public void saveThenLoad() { assertThat(state.getUser()).isEqualTo(user); } + @Test + public void saveTwiceForSameAccount() { + VerifiedUser user = TestModels.createVerifiedUser(); + Optional maybeConflictingAccountId1 = getCompleted(store.trySave("username", user, expiresIn(5))); + assertThat(maybeConflictingAccountId1).isEmpty(); + + Optional maybeConflictingAccountId2 = getCompleted(store.trySave("username", user, expiresIn(10))); + assertThat(maybeConflictingAccountId2).isEmpty(); + } + @Test public void loadUnverified() { VerificationState state = getCompleted(store.load("username"));