-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathzone.test.js
More file actions
87 lines (68 loc) · 2.45 KB
/
Copy pathzone.test.js
File metadata and controls
87 lines (68 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const assert = require('node:assert/strict')
const { describe, it } = require('node:test')
const schema = require('./zone').v3
const testZone = require('./test/zone.json')
describe('zone', function () {
describe('zone', function () {
it(`accepts valid`, () => {
const testCase = JSON.parse(JSON.stringify(testZone))
const { error, value } = schema.validate(testCase)
assert.ifError(error)
assert.deepEqual(value, testCase)
})
it(`rejects empty`, () => {
const testCase = JSON.parse(JSON.stringify(testZone))
testCase.zone = ''
const { error, value } = schema.validate(testCase)
assert.strictEqual(error.message, '"zone" is not allowed to be empty')
assert.deepEqual(value, testCase)
})
const invalid_chars = `~\`!@$%^&*()+=[]\\/|?><"':;,#{} \n`
.split('')
.map((a) => `thisis${a}atest.com.`)
for (const char of invalid_chars) {
it.skip(`rejects invalid: ${char}`, () => {
const testCase = JSON.parse(JSON.stringify(testZone))
testCase.zone = char
const { error, value } = schema.validate(testCase)
// if (error) console.error(error.message)
assert.strictEqual(error?.message, '"zone" must contain a valid domain name')
assert.deepEqual(value, testCase)
})
}
})
describe('nt_group_id', function () {
for (const gid of [1]) {
it(`accepts valid: ${gid}`, () => {
const testCase = JSON.parse(JSON.stringify(testZone))
testCase.gid = gid
const { error, value } = schema.validate(testCase)
assert.ifError(error)
assert.deepEqual(value, testCase)
})
}
const errMsgs = [
'"gid" must be a positive number',
'"gid" must be a number',
'"gid" must be greater than or equal to 0',
]
for (const gid of ['', -1, 'abc']) {
it(`rejects invalid: ${gid}`, () => {
const testCase = JSON.parse(JSON.stringify(testZone))
testCase.gid = gid
const { error, value } = schema.validate(testCase)
assert.ok(errMsgs.includes(error.message))
assert.deepEqual(value, testCase)
})
}
})
describe('ttl', function () {
it(`rejects missing`, () => {
const testCase = JSON.parse(JSON.stringify(testZone))
delete testCase.ttl
const { error, value } = schema.validate(testCase)
assert.strictEqual(error.message, '"ttl" is required')
assert.deepEqual(value, testCase)
})
})
})