Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

### Unreleased

- fix(json, toml): zone record create checks the record, and an unchanged PUT answers false, as on mysql
- fix: zone record checks take an RRSIG with a type number or times in seconds
- fix: zone record PUT checks the record when its rdata changes
- fix(mysql): an SRV record with priority 0 reads back with its priority
Expand Down
11 changes: 9 additions & 2 deletions lib/zone_record/store/file.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { isDeepStrictEqual } from 'node:util'

import FileStore, { claimId, destroyMatch, removeRows } from '../../store/file.js'
import { idConflict } from '../../store/error.js'

import ZoneRecordBase, { checkPut, mergeChanges } from './base.js'
import ZoneRecordBase, { checkPut, checkRecord, mergeChanges } from './base.js'

const plain = (record) => JSON.parse(JSON.stringify(record))

class ZoneRecordRepoFile extends ZoneRecordBase {
constructor(args = {}) {
Expand All @@ -21,8 +25,9 @@ class ZoneRecordRepoFile extends ZoneRecordBase {
return keep(idConflict('zone record', args.id, options))
}

args.id = claimId(records, data, args.id)
if (args.ttl === undefined) args.ttl = 0
checkRecord(args)
args.id = claimId(records, data, args.id)

records.push(args)
return args.id
Expand Down Expand Up @@ -99,6 +104,8 @@ class ZoneRecordRepoFile extends ZoneRecordBase {
if (idx === -1) return false

const target = mergeChanges(records[idx], args)
// smol-toml parses tables without a prototype, so compare plain copies
if (isDeepStrictEqual(plain(target), plain(records[idx]))) return false
await checkPut(records[idx], target, args)
records[idx] = target
return true
Expand Down
18 changes: 18 additions & 0 deletions lib/zone_record/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ describe('zone_record', function () {
}
})

it('CREATE refuses a record the type cannot hold', async () => {
const base = { id: 60002, zid: 4096, owner: 'invalid.example.com.', ttl: 300 }
await ZoneRecord.destroy({ id: base.id })
for (const record of [
{ ...base, type: 'A', address: '1.2.3' },
{ ...base, type: 'MX' },
{ ...base, owner: 'invalid', type: 'A', address: '203.0.113.45' },
]) {
await assert.rejects(ZoneRecord.create(record), { code: 'STORE_INVALID' })
}
assert.deepEqual(await ZoneRecord.get({ id: base.id }), [])
})

for (const rrType of fs.readdirSync('lib/zone_record/test/rrs')) {
// if (rrType !== 'tlsa.json') continue
describe(`${path.basename(rrType, '.json').toUpperCase()}`, function () {
Expand Down Expand Up @@ -81,6 +94,11 @@ describe('zone_record', function () {
assert.ok(await ZoneRecord.put({ id: testCase.id, ttl: testCase.ttl }))
})

it('PUT answers false when nothing changes', async () => {
assert.equal(await ZoneRecord.put({ id: testCase.id, ttl: testCase.ttl }), false)
assert.equal(await ZoneRecord.put({ ...testCase }), false)
})

describe('DELETE', async () => {
it('deletes a zr', async () => {
assert.ok(await ZoneRecord.delete({ id: testCase.id }))
Expand Down
4 changes: 0 additions & 4 deletions lib/zone_record/test/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ describe('zone_record (mysql)', function () {
await assert.rejects(ZoneRecord.put({ id, ...rdata }), /can't be stored in mysql/)
})

it('refuses a create with incomplete rdata as invalid', async () => {
await assert.rejects(ZoneRecord.create({ ...record, id: id + 1, type: 'MX' }), { code: 'STORE_INVALID' })
})

it('leaves fields the new type does not map out of the update', async () => {
assert.ok(await ZoneRecord.put({ id, type: 'A', address: '203.0.113.11', port: 443 }))
const [zr] = await ZoneRecord.get({ id })
Expand Down
Loading