mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-21 05:50:18 +08:00
Clear previous test's cookies during test
This commit is contained in:
parent
8fa4af5a61
commit
080d3697ff
@ -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)
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user