From 080d3697ff530c7a2f46dc7d254f7f4d1e23635f Mon Sep 17 00:00:00 2001 From: Risto Lahtela <24460436+AuroraLS3@users.noreply.github.com> Date: Sat, 20 Mar 2021 12:55:43 +0200 Subject: [PATCH] Clear previous test's cookies during test --- .../plan/delivery/webserver/auth/ActiveCookieStore.java | 2 ++ .../delivery/webserver/auth/ActiveCookieStoreTest.java | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/auth/ActiveCookieStore.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/auth/ActiveCookieStore.java index 16018966c..a73957c72 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/auth/ActiveCookieStore.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/auth/ActiveCookieStore.java @@ -41,6 +41,7 @@ public class ActiveCookieStore implements SubSystem { private static final Map USERS_BY_COOKIE = new ConcurrentHashMap<>(); public static long cookieExpiresAfter = TimeUnit.HOURS.toMillis(2L); private static ActiveCookieStore activeCookieStore; + private final PlanConfig config; private final DBSystem dbSystem; private final RunnableFactory runnableFactory; @@ -70,6 +71,7 @@ public class ActiveCookieStore implements SubSystem { } public static void removeUserCookie(String username) { + System.out.println(USERS_BY_COOKIE); USERS_BY_COOKIE.entrySet().stream().filter(entry -> entry.getValue().getUsername().equals(username)) .findAny() .map(Map.Entry::getKey) diff --git a/Plan/common/src/test/java/com/djrapitops/plan/delivery/webserver/auth/ActiveCookieStoreTest.java b/Plan/common/src/test/java/com/djrapitops/plan/delivery/webserver/auth/ActiveCookieStoreTest.java index 0f480b333..78da9b895 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/delivery/webserver/auth/ActiveCookieStoreTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/delivery/webserver/auth/ActiveCookieStoreTest.java @@ -23,6 +23,7 @@ import com.djrapitops.plan.settings.config.PlanConfig; import com.djrapitops.plan.storage.database.DBSystem; import com.djrapitops.plan.storage.database.Database; import com.djrapitops.plan.utilities.PassEncryptUtil; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -53,6 +54,11 @@ class ActiveCookieStoreTest { user = new User(TestConstants.PLAYER_ONE_NAME, "console", null, PassEncryptUtil.createHash("testPass"), 0, WebUser.getPermissionsForLevel(0)); } + @AfterEach + void clearCookies() { + underTest.disable(); + } + @Test void cookiesAreStored() { String cookie = underTest.generateNewCookie(user); @@ -72,8 +78,8 @@ class ActiveCookieStoreTest { @Test void usersCookiesAreRemoved() { String cookie = underTest.generateNewCookie(user); - ActiveCookieStore.removeUserCookie(user.getUsername()); + ActiveCookieStore.removeUserCookie(user.getUsername()); assertFalse(underTest.checkCookie(cookie).isPresent()); }