aboutsummaryrefslogtreecommitdiffstats
path: root/names/dns-update.test.js
blob: 536d037b841460d5e5f984b20ddd444d4d4de985 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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);
});