Clear previous test's cookies during test

This commit is contained in:
Risto Lahtela 2021-03-20 12:55:43 +02:00
parent 8fa4af5a61
commit 080d3697ff
2 changed files with 9 additions and 1 deletions

View File

@ -41,6 +41,7 @@ public class ActiveCookieStore implements SubSystem {
private static final Map<String, User> 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)

View File

@ -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());
}