Skip to content

Commit 456c264

Browse files
committed
tests: added 45 tests, surfacing 4 bugs
- test: bugs/defects are skipped, unskip when fix lands - change: add `node:` prefixes to builtins
1 parent 081f214 commit 456c264

20 files changed

Lines changed: 1435 additions & 682 deletions

File tree

.github/workflows/lint.js.yml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
14
name: Linting
25

3-
on:
4-
push:
5-
branches: [master, main]
6-
pull_request:
7-
types: [opened, synchronize, reopened]
6+
on: [push, pull_request]
87

98
permissions:
109
contents: read
@@ -13,9 +12,9 @@ jobs:
1312
build:
1413
runs-on: ubuntu-latest
1514
steps:
16-
- uses: actions/checkout@v6
17-
- uses: actions/setup-node@v6
18-
with:
19-
node-version: 24
20-
- run: npm ci
21-
- run: npm run lint
15+
- uses: actions/checkout@v6
16+
- uses: actions/setup-node@v6
17+
with:
18+
node-version: 24
19+
- run: npm ci
20+
- run: npm run lint

.github/workflows/node.js.yml

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,32 @@
1+
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
14
name: Node.js CI
25

36
on:
47
push:
5-
branches: [master, main]
8+
branches: [ master ]
69
pull_request:
10+
branches: [ master ]
711
types: [opened, synchronize, reopened]
812

913
permissions:
1014
contents: read
1115

1216
jobs:
1317
build:
14-
needs: [get-lts]
18+
1519
runs-on: ubuntu-latest
20+
1621
strategy:
1722
matrix:
18-
node-version: ${{ fromJson(needs.get-lts.outputs.lts) }}
23+
node-version: [22, 24]
1924

2025
steps:
21-
- uses: actions/checkout@v6
22-
- name: Use Node.js ${{ matrix.node-version }}
23-
uses: actions/setup-node@v6
24-
with:
25-
node-version: ${{ matrix.node-version }}
26-
- run: npm ci
27-
- run: npm test
28-
29-
get-lts:
30-
runs-on: ubuntu-latest
31-
permissions:
32-
contents: read
33-
steps:
34-
- id: get
35-
uses: msimerson/node-lts-versions@v1
36-
outputs:
37-
active: ${{ steps.get.outputs.active }}
38-
maintenance: ${{ steps.get.outputs.maintenance }}
39-
lts: ${{ steps.get.outputs.lts }}
40-
current: ${{ steps.get.outputs.current }}
41-
min: ${{ steps.get.outputs.min }}
26+
- uses: actions/checkout@v6
27+
- name: Use Node.js ${{ matrix.node-version }}
28+
uses: actions/setup-node@v6
29+
with:
30+
node-version: ${{ matrix.node-version }}
31+
- run: npm ci
32+
- run: npm test

.github/workflows/release.yml

Lines changed: 0 additions & 79 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
1+
# Changelog
12

2-
### 2026-05-26
3+
The format is based on [Keep a Changelog](https://keepachangelog.com/).
34

4-
- client/udp.js refactors
5-
1. Mismatched ids are dropped and the listener keeps waiting — stray packets no longer crash the process.
6-
2. Sender filtering. Reject any packet whose rinfo.port isn't the configured resolver port; additionally enforce rinfo.address when dns is an IP literal (using net.isIP).
7-
3. Defensive Packet.parse. Wrapped in try/catch so a malformed stray packet doesn't reject the promise — it's dropped with a debug log.
8-
4. Timeout. New timeout option (default 10s, set 0 to disable). On expiry the promise rejects with code: 'ETIMEDOUT'. Timer is .unref()-ed so it never holds the event loop open.
9-
5. Full 16-bit transaction IDs. query.header.id = crypto.randomInt(0x10000), 6.5× the keyspace and uses a CSPRNG.
10-
6. Proper cleanup. Single cleanup() clears the timer, removes both listeners, and closes the socket; settled guard prevents double-resolve/reject from racing message + timeout.
11-
7. Error event handled. Socket errors now reject the promise instead of going unhandled.
5+
### Unreleased
126

7+
- test: split tests into 3 files, add 45 new tests
8+
- feat(client/doh): HTTP/2 transport #89
9+
- feat(client/tcp): DNS-over-TLS support #88
10+
- feat(packet): IPv6 subnet support in `EDNS.ECS.decode`
11+
- feat(client/udp): configurable `timeout` (default 10s, `0` disables); rejects with `ETIMEDOUT`
12+
- fix(client/udp): drop mismatched-id packets instead of crashing
13+
- fix(client/udp): reject packets from non-resolver senders (port + IP literal via `net.isIP`)
14+
- fix(client/udp): defensive `Packet.parse` — malformed strays are dropped, not rejected
15+
- fix(client/udp): full 16-bit transaction ids via `crypto.randomInt`
16+
- fix(client/udp): single cleanup with settled-guard; socket `error` is handled
17+
- fix(client/tcp): empty response when server reply is async
18+
- fix(client/doh): enforce RFC 8484 `dns` query parameter, drop invalid pathname auto-completion #95
19+
- fix(server/udp): more resilient `udp4` default
20+
- fix(packet): guard against ERR_BUFFER_OUT_OF_BOUNDS on malformed requests
21+
- change(api): `resolve()` and UDP client take an options object (was `clientIp` positional) #84
22+
- dep(eslint): upgrade to v10
23+
- ci: modernize GitHub Actions workflows; add release.yml
24+
25+
### 2.1.0 - 2024-06-26
26+
27+
- feat(packet): DNSKEY record support
28+
- feat(packet): RRSIG record support (decode only)
29+
- feat(packet): `flatMap` support
30+
- fix(packet): ensure compressed IPv6 is valid #70
31+
- doc(README): correct `server.listen` options

client/doh.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const http = require('http');
2-
const https = require('https');
3-
const http2 = require('http2');
1+
const http = require('node:http');
2+
const https = require('node:https');
3+
const http2 = require('node:http2');
44
const Packet = require('../packet');
55

66
const protocols = {

client/google.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const https = require('https');
1+
const https = require('node:https');
22

33
const get = url => new Promise(resolve =>
44
https.get(url, resolve));

client/tcp.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const tls = require('tls');
2-
const tcp = require('net');
1+
const tls = require('node:tls');
2+
const tcp = require('node:net');
33
const Packet = require('../packet');
44

55
const makeQuery = ({ name, type = 'A', cls = Packet.CLASS.IN, clientIp, recursive = true }) => {

client/udp.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const udp = require('dgram');
2-
const net = require('net');
3-
const crypto = require('crypto');
1+
const udp = require('node:dgram');
2+
const net = require('node:net');
3+
const crypto = require('node:crypto');
44
const Packet = require('../packet');
5-
const { debuglog } = require('util');
5+
const { debuglog } = require('node:util');
66

77
const debug = debuglog('dns2');
88

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const {
77
createDOHServer,
88
createServer,
99
} = require('./server');
10-
const EventEmitter = require('events');
10+
const EventEmitter = require('node:events');
1111

1212
/**
1313
* [DNS description]

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"description": "A DNS Server and Client Implementation in Pure JavaScript with no dependencies.",
55
"main": "index.js",
66
"scripts": {
7-
"test": "node test",
7+
"test": "node --test",
8+
"test:coverage": "node --test --experimental-test-coverage",
9+
"test:coverage:lcov": "mkdir -p coverage && node --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info",
810
"lint": "npx eslint .",
911
"lint:fix": "npx eslint . --fix",
1012
"example-server-udp": "node example/server/udp.js",

0 commit comments

Comments
 (0)