-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
203 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const Joi = require('joi') | ||
|
||
const shared = require('./shared') | ||
|
||
exports.zone = Joi.object({ | ||
nt_group_id: Joi.number().integer().positive().required(), | ||
|
||
// parent_group_id: Joi.number().integer().greater(-1), | ||
|
||
zone: Joi.string() | ||
.min(3) | ||
.max(255) | ||
.domain({ allowFullyQualified: true, tlds: false }) | ||
// .pattern(new RegExp("^[a-zA-Z0-9 _.@'-]+$")) | ||
// .pattern(new RegExp('^[a-zA-Z0-9]')) | ||
.required(), | ||
|
||
description: Joi.string().empty(''), | ||
|
||
mailaddr: Joi.string().empty(''), | ||
|
||
minimum: Joi.number().integer().greater(-1).max(2147483647).required(), | ||
|
||
nameservers: Joi.array().items(Joi.string()), | ||
|
||
refresh: Joi.number().integer().greater(-1).max(2147483647).required(), | ||
|
||
retry: Joi.number().integer().greater(-1).max(2147483647).required(), | ||
|
||
expire: Joi.number().integer().greater(-1).max(2147483647).required(), | ||
|
||
serial: Joi.number().integer().greater(-1).max(2147483647).required(), | ||
|
||
ttl: shared.ttl.required(), | ||
|
||
deleted: Joi.boolean(), | ||
|
||
// has_children: Joi.boolean(), | ||
// permission: permission.permission, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"nt_group_id": 1, | ||
"zone": "example.com", | ||
"ttl": 1, | ||
"serial": 20240404, | ||
"nameservers": ["a.ns.example.com", "b.ns.example.com"], | ||
"mailaddr": "hostmaster.example.com.", | ||
"description": "test", | ||
"refresh": 1, | ||
"retry": 2, | ||
"expire": 3, | ||
"minimum": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
const assert = require('node:assert/strict') | ||
|
||
const schema = require('../lib/zone').zone | ||
const testZone = require('./fixtures/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.deepStrictEqual(testCase, value) | ||
}) | ||
|
||
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.deepStrictEqual(testCase, value) | ||
}) | ||
|
||
const invalid_chars = `~\`!@$%^&*()+=[]\\/|?><"':;,#{} \n` | ||
.split('') | ||
.map((a) => `thisis${a}atest.com.`) | ||
|
||
for (const char of invalid_chars) { | ||
it(`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.deepStrictEqual(testCase, value) | ||
}) | ||
} | ||
}) | ||
|
||
describe('nt_group_id', function () { | ||
for (const gid of [1]) { | ||
it(`accepts valid: ${gid}`, () => { | ||
const testCase = JSON.parse(JSON.stringify(testZone)) | ||
testCase.nt_group_id = gid | ||
|
||
const { error, value } = schema.validate(testCase) | ||
|
||
assert.ifError(error) | ||
assert.deepStrictEqual(testCase, value) | ||
}) | ||
} | ||
|
||
const errMsgs = [ | ||
'"nt_group_id" must be a positive number', | ||
'"nt_group_id" must be a number', | ||
] | ||
for (const gid of ['', 0, 'abc']) { | ||
it(`rejects invalid: ${gid}`, () => { | ||
const testCase = JSON.parse(JSON.stringify(testZone)) | ||
testCase.nt_group_id = gid | ||
|
||
const { error, value } = schema.validate(testCase) | ||
|
||
assert.ok(errMsgs.includes(error.message)) | ||
assert.deepStrictEqual(testCase, value) | ||
}) | ||
} | ||
}) | ||
|
||
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.deepStrictEqual(testCase, value) | ||
}) | ||
}) | ||
}) |