Add ServerControllerTests#ensureUnknownPort
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m18s

This commit is contained in:
Braydon 2024-04-10 04:27:39 -04:00
parent 66e84b9c08
commit 931e6c2de1
3 changed files with 17 additions and 2 deletions

@ -65,7 +65,7 @@ public final class ServerController {
* @param hostname the hostname of the server * @param hostname the hostname of the server
* @param port the port of the server, null for default * @param port the port of the server, null for default
* @return the server * @return the server
* @throws BadRequestException if the hostname or platform is invalid * @throws BadRequestException if the hostname, platform, or port is invalid
* @throws ResourceNotFoundException if the server isn't found * @throws ResourceNotFoundException if the server isn't found
*/ */
@GetMapping("/{platform}/{hostname}") @GetMapping("/{platform}/{hostname}")

@ -347,7 +347,7 @@ public final class MojangService {
* @param hostname the hostname of the server * @param hostname the hostname of the server
* @param portString the port of the server, null for default * @param portString the port of the server, null for default
* @return the resolved Minecraft server * @return the resolved Minecraft server
* @throws BadRequestException if the hostname or platform is invalid * @throws BadRequestException if the hostname, platform, or port is invalid
* @throws ResourceNotFoundException if the server isn't found * @throws ResourceNotFoundException if the server isn't found
*/ */
@NonNull @NonNull

@ -120,6 +120,21 @@ public final class ServerControllerTests {
.andReturn(); .andReturn();
} }
/**
* Run a test to ensure looking up
* an invalid port results in a 400.
*
* @throws Exception if the test fails
*/
@Test
void ensureUnknownPort() throws Exception {
mockMvc.perform(get("/server/java/hypixel.net?port=A")
.accept(MediaType.APPLICATION_JSON) // Accept JSON
.contentType(MediaType.APPLICATION_JSON) // Content type is JSON
).andExpect(status().isBadRequest()) // Expect 400 (Bad Request)
.andReturn();
}
/** /**
* Run a test to ensure checking if * Run a test to ensure checking if
* a server is banned is successful. * a server is banned is successful.