feat: skip SRV lookup for IP addresses and localhost

Performing DNS SRV lookups for hosts that are already direct IP
addresses or special-case hostnames like 'localhost' is
unnecessary.

In addition, several related test suite improvements
have been included:

- A bug in the Bedrock mock packet creation was fixed where the magic
  GUID was being written to an incorrect buffer offset.
- The DNS mocking strategy in the Java tests has been refactored for
  better accuracy by mocking the `dns.promises.Resolver` class.
- An error test for the Bedrock pinger was corrected to properly
  handle a promise rejection instead of a synchronous throw.
This commit is contained in:
2025-06-25 01:46:53 +03:00
parent 1e6b5b3973
commit 371fb9daa7
3 changed files with 69 additions and 35 deletions

View File

@ -125,8 +125,10 @@ describe("bedrock.js", () => {
});
describe("errors", () => {
it("should throw an error if host is not provided", () => {
expect(() => pingBedrock(null)).toThrow("Host argument is required");
it("should throw an error if host is not provided", async () => {
await expect(pingBedrock(null)).rejects.toThrow(
"Host argument is required"
);
});
it("should reject on socket timeout", async () => {
@ -167,7 +169,7 @@ function createMockPongPacket(motd) {
const packet = Buffer.alloc(35 + motdBuffer.length);
packet.writeUInt8(0x1c, 0);
packet.writeBigInt64LE(BigInt(Date.now()), 1);
Buffer.from("00ffff00fefefefefdfdfdfd12345678", "hex").copy(packet, 17);
Buffer.from("00ffff00fefefefefdfdfdfd12345678", "hex").copy(packet, 9);
packet.writeUInt16BE(motdBuffer.length, 33);
motdBuffer.copy(packet, 35);
return packet;