-
-
Notifications
You must be signed in to change notification settings - Fork 1
fix/issue 222 #230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
fix/issue 222 #230
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9ccf34c
fix: strip null/empty item stacks from parcel content (#221)
Jakubk15 1ecdb8e
fix: stop using legacy ItemStack serialization for parcel content
Jakubk15 dbfde43
Update src/main/java/com/eternalcode/parcellockers/content/ParcelCont…
Jakubk15 a1ed767
test: cover null items list in ParcelContent guard
Jakubk15 9d5ca43
Merge branch 'master' into fix/issue-221-collection-gui-npe
Jakubk15 c8c0a0c
fix: guard against null parcel description in AdminParcelEditGui
Jakubk15 84b3de1
fix: restrict parcel collection to destination locker (#222)
Jakubk15 6425e97
refactor: filter collectible parcels in the query, not after paging
Jakubk15 f945b64
Merge branch 'master' into fix/issue-222
Jakubk15 be43866
fix: require a concrete locker when parcel collection is restricted
Jakubk15 1e2041e
Merge branch 'fix/issue-222' of https://github.com/EternalCodeTeam/Pa…
Jakubk15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
...est/java/com/eternalcode/parcellockers/database/ParcelFindCollectibleIntegrationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| package com.eternalcode.parcellockers.database; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import com.eternalcode.parcellockers.TestScheduler; | ||
| import com.eternalcode.parcellockers.configuration.implementation.PluginConfig; | ||
| import com.eternalcode.parcellockers.parcel.Parcel; | ||
| import com.eternalcode.parcellockers.parcel.ParcelSize; | ||
| import com.eternalcode.parcellockers.parcel.ParcelStatus; | ||
| import com.eternalcode.parcellockers.parcel.repository.ParcelRepository; | ||
| import com.eternalcode.parcellockers.parcel.repository.ParcelRepositoryOrmLite; | ||
| import com.eternalcode.parcellockers.shared.Page; | ||
| import com.eternalcode.parcellockers.shared.PageResult; | ||
| import java.nio.file.Path; | ||
| import java.sql.SQLException; | ||
| import java.util.UUID; | ||
| import java.util.logging.Logger; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.io.TempDir; | ||
| import org.testcontainers.containers.MySQLContainer; | ||
| import org.testcontainers.junit.jupiter.Container; | ||
| import org.testcontainers.junit.jupiter.Testcontainers; | ||
| import org.testcontainers.utility.DockerImageName; | ||
|
|
||
| @Testcontainers(disabledWithoutDocker = true) | ||
| class ParcelFindCollectibleIntegrationTest extends IntegrationTestSpec { | ||
|
|
||
| @Container | ||
| private static final MySQLContainer<?> mySQLContainer = new MySQLContainer<>(DockerImageName.parse("mysql:latest")); | ||
|
|
||
| @TempDir | ||
| private Path tempDir; | ||
|
|
||
| private DatabaseManager databaseManager; | ||
|
|
||
| private ParcelRepository repository() throws SQLException { | ||
| PluginConfig config = new PluginConfig(); | ||
| config.settings.databaseType = DatabaseType.MYSQL; | ||
| config.settings.host = mySQLContainer.getHost(); | ||
| config.settings.port = String.valueOf(mySQLContainer.getFirstMappedPort()); | ||
| config.settings.databaseName = mySQLContainer.getDatabaseName(); | ||
| config.settings.user = mySQLContainer.getUsername(); | ||
| config.settings.password = mySQLContainer.getPassword(); | ||
|
|
||
| DatabaseManager databaseManager = new DatabaseManager(config, Logger.getLogger("ParcelLockers"), this.tempDir.toFile()); | ||
| databaseManager.connect(); | ||
| this.databaseManager = databaseManager; | ||
|
|
||
| return new ParcelRepositoryOrmLite(databaseManager, new TestScheduler()); | ||
| } | ||
|
|
||
| private void save(ParcelRepository repository, UUID receiver, UUID destinationLocker, ParcelStatus status) { | ||
| this.await(repository.save(new Parcel( | ||
| UUID.randomUUID(), UUID.randomUUID(), "p", "d", false, | ||
| receiver, ParcelSize.SMALL, UUID.randomUUID(), destinationLocker, status))); | ||
| } | ||
|
|
||
| @Test | ||
| void findCollectibleReturnsOnlyDeliveredParcelsForTheGivenLockerAndReceiver() throws SQLException { | ||
| ParcelRepository repository = this.repository(); | ||
|
|
||
| UUID receiver = UUID.randomUUID(); | ||
| UUID locker = UUID.randomUUID(); | ||
| UUID otherLocker = UUID.randomUUID(); | ||
|
|
||
| for (int i = 0; i < 3; i++) { | ||
| this.save(repository, receiver, locker, ParcelStatus.DELIVERED); | ||
| } | ||
| this.save(repository, receiver, locker, ParcelStatus.SENT); // not yet delivered | ||
| this.save(repository, receiver, otherLocker, ParcelStatus.DELIVERED); // different locker | ||
| this.save(repository, UUID.randomUUID(), locker, ParcelStatus.DELIVERED); // different receiver | ||
|
|
||
| // Pagination must count only the 3 eligible parcels, not the raw receiver page. | ||
| PageResult<Parcel> firstPage = this.await(repository.findCollectible(receiver, locker, new Page(0, 2))); | ||
| assertEquals(2, firstPage.items().size()); | ||
| assertTrue(firstPage.hasNextPage()); | ||
|
|
||
| PageResult<Parcel> secondPage = this.await(repository.findCollectible(receiver, locker, new Page(1, 2))); | ||
| assertEquals(1, secondPage.items().size()); | ||
| assertFalse(secondPage.hasNextPage()); | ||
| } | ||
|
|
||
| @Test | ||
| void findCollectibleWithNullLockerReturnsDeliveredParcelsFromAnyLocker() throws SQLException { | ||
| ParcelRepository repository = this.repository(); | ||
|
|
||
| UUID receiver = UUID.randomUUID(); | ||
|
|
||
| this.save(repository, receiver, UUID.randomUUID(), ParcelStatus.DELIVERED); | ||
| this.save(repository, receiver, UUID.randomUUID(), ParcelStatus.DELIVERED); | ||
| this.save(repository, receiver, UUID.randomUUID(), ParcelStatus.SENT); // excluded by status | ||
| this.save(repository, UUID.randomUUID(), UUID.randomUUID(), ParcelStatus.DELIVERED); // other receiver | ||
|
|
||
| PageResult<Parcel> page = this.await(repository.findCollectible(receiver, null, new Page(0, 10))); | ||
| assertEquals(2, page.items().size()); | ||
| assertFalse(page.hasNextPage()); | ||
| assertTrue(page.items().stream().allMatch(parcel -> parcel.receiver().equals(receiver))); | ||
| assertTrue(page.items().stream().allMatch(parcel -> parcel.status() == ParcelStatus.DELIVERED)); | ||
| } | ||
|
|
||
| @AfterEach | ||
| void tearDown() { | ||
| if (this.databaseManager != null) { | ||
| this.databaseManager.disconnect(); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
allowCollectingFromAnyLockerisfalsebutcurrentLockerisnull,destinationLockerwill be set tonull. InParcelRepositoryOrmLite#findCollectible, anulldestination locker bypasses the locker restriction filter entirely, allowing the player to collect parcels from any locker. To prevent this security/logic bypass, we should ensure that a non-existent/dummy UUID is used whencurrentLockeris null and restriction is active.