Skip to content

Commit 5203d48

Browse files
committed
fix: increase default spoofPacket expiration to 30s from 10s, added expires argument
1 parent 254baa7 commit 5203d48

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
* [`tangerine.reverse(ip[, abortController, purgeCache])`](#tangerinereverseip-abortcontroller-purgecache)
5757
* [`tangerine.setDefaultResultOrder(order)`](#tangerinesetdefaultresultorderorder)
5858
* [`tangerine.setServers(servers)`](#tangerinesetserversservers)
59-
* [`tangerine.spoofPacket(hostname, rrtype, answers[, json])`](#tangerinespoofpackethostname-rrtype-answers-json)
59+
* [`tangerine.spoofPacket(hostname, rrtype, answers[, json, expires = 30000])`](#tangerinespoofpackethostname-rrtype-answers-json-expires--30000)
6060
* [Options](#options)
6161
* [Cache](#cache)
6262
* [Compatibility](#compatibility)
@@ -332,14 +332,16 @@ This mirrors output from <https://github.com/rthalley/dnspython>.
332332
333333
### `tangerine.setServers(servers)`
334334
335-
### `tangerine.spoofPacket(hostname, rrtype, answers[, json])`
335+
### `tangerine.spoofPacket(hostname, rrtype, answers[, json, expires = 30000])`
336336
337337
This method is useful for writing tests to spoof DNS packets in-memory.
338338
339339
The `rrtype` must be either `"TXT"` or `"MX"`, and `answers` must be an Array of DNS resource record answers.
340340
341341
If you pass `json` as `true`, then value returned will be converted to JSON via `JSON.stringify`.
342342
343+
The last argument `expires` can either be a `Date` or `Number`. This is the value used for calculating the DNS packet expiration. If it is a `Number`, then the `expires` value will be `Date.now() + expires`. The default value is `30000`, which means it will expire in 30 seconds.
344+
343345
For example, if you want to spoof TXT and MX records:
344346
345347
```js

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,8 @@ class Tangerine extends dns.promises.Resolver {
14251425
this.options.servers = new Set(servers);
14261426
}
14271427

1428-
spoofPacket(name, rrtype, answers = [], json = false) {
1428+
// eslint-disable-next-line max-params
1429+
spoofPacket(name, rrtype, answers = [], json = false, expires = 30000) {
14291430
if (typeof name !== 'string') {
14301431
const err = new TypeError('The "name" argument must be of type string.');
14311432
err.code = 'ERR_INVALID_ARG_TYPE';
@@ -1489,7 +1490,8 @@ class Tangerine extends dns.promises.Resolver {
14891490
}
14901491
],
14911492
ttl: 300,
1492-
expires: Date.now() + 10000
1493+
expires:
1494+
expires instanceof Date ? expires.getTime() : Date.now() + expires
14931495
};
14941496

14951497
return json ? JSON.stringify(obj) : obj;

0 commit comments

Comments
 (0)