mirror of
https://github.com/oven-sh/bun
synced 2026-02-12 11:59:00 +00:00
Fix EINVAL when setting IPv6 multicast membership (#17478)
This commit is contained in:
53
test/js/node/dgram/node-dgram.test.js
Normal file
53
test/js/node/dgram/node-dgram.test.js
Normal file
@@ -0,0 +1,53 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import * as dgram from "node:dgram";
|
||||
import { isWindows, isMacOS, isIPv6 } from "harness";
|
||||
|
||||
describe.skipIf(!isIPv6())("node:dgram", () => {
|
||||
it("adds membership successfully (IPv6)", () => {
|
||||
const socket = makeSocket6();
|
||||
socket.bind(0, () => {
|
||||
socket.addMembership("ff01::1", getInterface());
|
||||
if (!isMacOS) {
|
||||
// macOS seems to be iffy with automatically choosing an interface.
|
||||
socket.addMembership("ff02::1");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("doesn't add membership given invalid inputs (IPv6)", () => {
|
||||
const { promise, resolve, reject } = Promise.withResolvers();
|
||||
const socket = makeSocket6();
|
||||
socket.bind(0, () => {
|
||||
expect(() => {
|
||||
// fe00:: is not a valid multicast address
|
||||
socket.addMembership("fe00::", getInterface());
|
||||
reject();
|
||||
}).toThrow();
|
||||
expect(() => {
|
||||
socket.addMembership("fe00::");
|
||||
reject();
|
||||
}).toThrow();
|
||||
resolve();
|
||||
});
|
||||
return promise;
|
||||
});
|
||||
});
|
||||
|
||||
function makeSocket6() {
|
||||
return dgram.createSocket({
|
||||
type: "udp6",
|
||||
ipv6Only: true,
|
||||
});
|
||||
}
|
||||
|
||||
function getInterface() {
|
||||
if (isWindows) {
|
||||
return "::%1";
|
||||
}
|
||||
|
||||
if (isMacOS) {
|
||||
return "::%lo0";
|
||||
}
|
||||
|
||||
return "::%lo";
|
||||
}
|
||||
Reference in New Issue
Block a user