diff options
Diffstat (limited to 'names/dns-update.test.js')
| -rw-r--r-- | names/dns-update.test.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/names/dns-update.test.js b/names/dns-update.test.js new file mode 100644 index 0000000..536d037 --- /dev/null +++ b/names/dns-update.test.js @@ -0,0 +1,21 @@ +import { expect, test } from 'bun:test'; +import { txtRdata, buildUpdate } from './dns-update.js'; + +test('TXT values split into 255-byte strings, in order', () => { + const v = 'x'.repeat(600); + const r = txtRdata(v); + expect([r[0], r[256], r[512]]).toEqual([255, 255, 90]); + expect(r.length).toBe(600 + 3); +}); + +test('an UPDATE is opcode 5 for the zone, with a TSIG record last', () => { + const key = { name: 'names-update', secret: Buffer.alloc(32, 1).toString('base64') }; + const { msg, id } = buildUpdate('user._bitcoin-payment.coinos.io', [{ name: 'a.user._bitcoin-payment.coinos.io', value: 'bitcoin:?ark=x' }, { name: 'b.user._bitcoin-payment.coinos.io', value: null }], 300, key, { id: 7, now: 1 }); + expect(id).toBe(7); + expect(msg.readUInt16BE(2) >> 11).toBe(5); + expect([msg.readUInt16BE(4), msg.readUInt16BE(8), msg.readUInt16BE(10)]).toEqual([1, 3, 1]); // zone, 2 deletes + 1 add, TSIG + expect(msg.includes(Buffer.from('hmac-sha256'))).toBe(true); + // same inputs, same signature + expect(buildUpdate('user._bitcoin-payment.coinos.io', [{ name: 'a.user._bitcoin-payment.coinos.io', value: 'v' }], 300, key, { id: 7, now: 1 }).msg) + .toEqual(buildUpdate('user._bitcoin-payment.coinos.io', [{ name: 'a.user._bitcoin-payment.coinos.io', value: 'v' }], 300, key, { id: 7, now: 1 }).msg); +}); |
