Skip to content

Commit

Permalink
Bugfixes to build 1951 (#2607)
Browse files Browse the repository at this point in the history
* Remove SecuredRedirectHandler from Jetty

* Fixed extension values not updating on PLAYER_LEAVE

* Fix Join Address data-truncation errors

Affects issues:
- Fixed #2606

* Tests for join address truncation
  • Loading branch information
AuroraLS3 authored Sep 13, 2022
1 parent 8b32ced commit b68e41b
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory;
import org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory;
import org.eclipse.jetty.server.*;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.SecuredRedirectHandler;
import org.eclipse.jetty.util.ssl.SslContextFactory;

import javax.inject.Inject;
Expand Down Expand Up @@ -125,11 +123,7 @@ public void enable() {
connector.setHost(internalIP);
webserver.addConnector(connector);

if (usingHttps) {
webserver.setHandler(new HandlerList(new SecuredRedirectHandler(), jettyRequestHandler));
} else {
webserver.setHandler(jettyRequestHandler);
}
webserver.setHandler(jettyRequestHandler);

String startFailure = "Failed to start Jetty webserver: ";
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public void register() {

public void registerExtensions() {
try {
enabled.set(true);
extensionRegister.registerBuiltInExtensions(config.getExtensionSettings().getDisabled());
} catch (IllegalStateException failedToRegisterOne) {
ErrorContext.Builder context = ErrorContext.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
package com.djrapitops.plan.gathering.domain.event;

import com.djrapitops.plan.storage.database.sql.tables.JoinAddressTable;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;
import java.util.function.Supplier;

Expand All @@ -31,7 +34,7 @@ public JoinAddress(Supplier<String> address) {
}

public String getAddress() {
return address.get();
return StringUtils.truncate(address.get(), JoinAddressTable.JOIN_ADDRESS_MAX_LENGTH);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private void storeBanStatus(PlayerLeave leave) {

private void updatePlayerDataExtensionValues(PlayerLeave leave) {
processing.submitNonCritical(() -> extensionService.updatePlayerValues(
leave.getPlayerUUID(), leave.getPlayerName(), CallEvents.PLAYER_JOIN)
leave.getPlayerUUID(), leave.getPlayerName(), CallEvents.PLAYER_LEAVE)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ public void prepare(PreparedStatement statement) {
.filter(Optional::isPresent)
.map(Optional::get)
.map(JoinAddress::getAddress)
.map(joinAddress -> StringUtils.truncate(joinAddress, JoinAddressTable.JOIN_ADDRESS_MAX_LENGTH))
.distinct()
.filter(address -> !existingJoinAddresses.contains(address))
.forEach(address -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
import com.djrapitops.plan.storage.database.queries.objects.JoinAddressQueries;
import com.djrapitops.plan.storage.database.sql.tables.JoinAddressTable;
import com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction;
import com.djrapitops.plan.storage.database.transactions.events.PlayerRegisterTransaction;
import com.djrapitops.plan.storage.database.transactions.events.StoreJoinAddressTransaction;
import com.djrapitops.plan.storage.database.transactions.events.StoreSessionTransaction;
import com.djrapitops.plan.storage.database.transactions.events.StoreWorldNameTransaction;
import com.djrapitops.plan.storage.database.transactions.events.*;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
import utilities.RandomData;
import utilities.TestConstants;
Expand Down Expand Up @@ -118,6 +116,54 @@ default void joinAddressPreservesCase() {
}
}

@Test
default void joinAddressIsTruncated() {
db().executeTransaction(new StoreWorldNameTransaction(serverUUID(), worlds[0]));
db().executeTransaction(new StoreWorldNameTransaction(serverUUID(), worlds[1]));
db().executeTransaction(new PlayerRegisterTransaction(playerUUID, System::currentTimeMillis, TestConstants.PLAYER_ONE_NAME));

FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID);
String joinAddress = RandomData.randomString(JoinAddressTable.JOIN_ADDRESS_MAX_LENGTH + RandomData.randomInt(0, 100));
session.getExtraData().put(JoinAddress.class, new JoinAddress(joinAddress));
db().executeTransaction(new StoreSessionTransaction(session));

String expectedJoinAddress = StringUtils.truncate(joinAddress, JoinAddressTable.JOIN_ADDRESS_MAX_LENGTH);

Set<Integer> expected = Set.of(db().query(BaseUserQueries.fetchUserId(playerUUID)).orElseThrow(AssertionError::new));
Set<Integer> result = db().query(JoinAddressQueries.userIdsOfPlayersWithJoinAddresses(List.of(expectedJoinAddress)));

assertEquals(expected, result);

Map<String, Integer> expectedAddressCounts = Map.of(expectedJoinAddress, 1);
Map<String, Integer> resultAddressCounts = db().query(JoinAddressQueries.latestJoinAddresses());

assertEquals(expectedAddressCounts, resultAddressCounts);
}

@Test
default void joinAddressIsTruncatedWhenStoringSessionsAfterRestart() {
db().executeTransaction(new StoreWorldNameTransaction(serverUUID(), worlds[0]));
db().executeTransaction(new StoreWorldNameTransaction(serverUUID(), worlds[1]));
db().executeTransaction(new PlayerRegisterTransaction(playerUUID, System::currentTimeMillis, TestConstants.PLAYER_ONE_NAME));

FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID);
String joinAddress = RandomData.randomString(JoinAddressTable.JOIN_ADDRESS_MAX_LENGTH + RandomData.randomInt(0, 100));
session.getExtraData().put(JoinAddress.class, new JoinAddress(joinAddress));
db().executeTransaction(new ShutdownDataPreservationTransaction(List.of(session)));

String expectedJoinAddress = StringUtils.truncate(joinAddress, JoinAddressTable.JOIN_ADDRESS_MAX_LENGTH);

Set<Integer> expected = Set.of(db().query(BaseUserQueries.fetchUserId(playerUUID)).orElseThrow(AssertionError::new));
Set<Integer> result = db().query(JoinAddressQueries.userIdsOfPlayersWithJoinAddresses(List.of(expectedJoinAddress)));

assertEquals(expected, result);

Map<String, Integer> expectedAddressCounts = Map.of(expectedJoinAddress, 1);
Map<String, Integer> resultAddressCounts = db().query(JoinAddressQueries.latestJoinAddresses());

assertEquals(expectedAddressCounts, resultAddressCounts);
}

@Test
default void joinAddressUpdateIsUniquePerServer() {
joinAddressCanBeUnknown();
Expand Down

0 comments on commit b68e41b

Please sign in to comment.