Skip to content

Commit

Permalink
Release v0.7.3 (#10)
Browse files Browse the repository at this point in the history
- feat: permission updates, related to NicTool/api#20
- feat: add shared.int32 and shared.uint32
- feat: improvements to zone and zone_record formats, progress on NicTool/api#16 and NicTool/api#17
  • Loading branch information
msimerson authored Feb 29, 2024
1 parent bb092f6 commit a2849fd
Show file tree
Hide file tree
Showing 22 changed files with 121 additions and 93 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

### Unreleased

### [0.7.3] - 2024-02-28

- feat: permission updates
- feat: add shared.int32 and shared.uint32
- feat: improvements to zone and zone_record formats

### [0.7.2] - 2024-02-27

- group: GET returns parent_gid
Expand Down Expand Up @@ -34,3 +40,4 @@
[0.7.0]: https://github.com/NicTool/validate/releases/tag/0.7.0
[0.7.1]: https://github.com/NicTool/validate/releases/tag/0.7.1
[0.7.2]: https://github.com/NicTool/validate/releases/tag/0.7.2
[0.7.3]: https://github.com/NicTool/validate/releases/tag/0.7.3
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
for (const l of [
'group',
'user',
'session',
'nameserver',
'permission',
'session',
'user',
'zone',
'zone_record',
]) {
Expand Down
12 changes: 6 additions & 6 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ const { describe, it } = require('node:test')
const schema = require('./index')

describe('index', function () {
const testGroup = require('./test/fixtures/v2/group.json')
const testUser = require('./test/fixtures/v2/user.json')
const testNs = require('./test/fixtures/v2/nameserver.json')
const testGroup = require('./lib/test/group.json')
const testUser = require('./lib/test/user.json')
const testNs = require('./lib/test/nameserver.json')

it('exports user', () => {
const testCase = JSON.parse(JSON.stringify(testUser))
const { error, value } = schema.user.v2.validate(testCase)
const { error, value } = schema.user.v3.validate(testCase)
assert.ifError(error)
assert.deepEqual(testCase, value)
})

it('exports group', () => {
const testCase = JSON.parse(JSON.stringify(testGroup))
const { error, value } = schema.group.v2.validate(testCase)
const { error, value } = schema.group.v3.validate(testCase)
assert.ifError(error)
assert.deepEqual(testCase, value)
})

it('exports nameserver', () => {
const testCase = JSON.parse(JSON.stringify(testNs))
const { error } = schema.nameserver.nameserver.validate(testCase)
const { error } = schema.nameserver.v3.validate(testCase)
assert.ifError(error)
})
})
9 changes: 6 additions & 3 deletions lib/group.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const Joi = require('joi')

const shared = require('./shared')
const permission = require('./permission')

exports.id = Joi.number().integer().min(1).max(4294967295)

exports.pid = Joi.number().integer().min(0).max(4294967295)
exports.pid = shared.uint32

exports.name = Joi.string()
.min(3)
Expand All @@ -18,7 +19,7 @@ exports.v3 = Joi.object({
name: exports.name.required(),
deleted: Joi.boolean(),
has_children: Joi.boolean(),
permission: shared.permission,
permission: permission.v3,
})

// legacy group format
Expand All @@ -28,14 +29,15 @@ exports.v2 = Joi.object({
name: exports.name.required(),
deleted: Joi.boolean(),
has_children: Joi.boolean(),
permission: shared.permission,
permission: permission.v3,
})

exports.GET = Joi.object({
group: Joi.object({
id: exports.pid,
parent_gid: exports.pid,
name: exports.name,
permission: permission.v3,
}),
meta: shared.meta,
})
Expand All @@ -44,4 +46,5 @@ exports.POST = Joi.object({
id: exports.id,
name: exports.name,
parent_gid: exports.pid,
permission: permission.v3,
})
11 changes: 4 additions & 7 deletions lib/group.test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
const assert = require('node:assert/strict')
const { describe, it } = require('node:test')

const schema = require('./group').v2
const testGroup = require('../test/fixtures/v2/group.json')
const schema = require('./group').v3
const testGroup = require('./test/group.json')

describe('group', function () {
describe('name', function () {
it('accepts valid', () => {
const testCase = JSON.parse(JSON.stringify(testGroup))

const { error, value } = schema.validate(testCase)

const { error, value } = schema.validate(testGroup)
assert.ifError(error)
assert.deepEqual(value, testCase)
assert.deepEqual(value, testGroup)
})

it('rejects missing name', () => {
Expand Down
6 changes: 3 additions & 3 deletions lib/nameserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ const Joi = require('joi')

const shared = require('./shared')

exports.nameserver = Joi.object({
nt_nameserver_id: Joi.number().integer().greater(-1),
exports.v3 = Joi.object({
id: Joi.number().integer().greater(-1),

nt_group_id: Joi.number().integer().greater(0).required(),
gid: Joi.number().integer().greater(0).required(),

name: Joi.string()
.min(2)
Expand Down
16 changes: 8 additions & 8 deletions lib/nameserver.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const assert = require('node:assert/strict')
const { describe, it } = require('node:test')

const schema = require('./nameserver').nameserver
const testNS = require('../test/fixtures/v2/nameserver.json')
const schema = require('./nameserver').v3
const testNS = require('./test/nameserver.json')

describe('nameserver', function () {
describe('name', function () {
Expand Down Expand Up @@ -122,7 +122,7 @@ describe('nameserver', function () {
}
})

describe('nt_group_id', function () {
describe('gid', function () {
it(`accepts valid`, () => {
const testCase = JSON.parse(JSON.stringify(testNS))

Expand All @@ -134,18 +134,18 @@ describe('nameserver', function () {

it(`rejects missing`, () => {
const testCase = JSON.parse(JSON.stringify(testNS))
delete testCase.nt_group_id
delete testCase.gid

const { error, value } = schema.validate(testCase)

assert.strictEqual(error.message, '"nt_group_id" is required')
assert.strictEqual(error.message, '"gid" is required')
assert.deepEqual(value, testCase)
})

for (const gid of [1]) {
it(`accepts valid: ${gid}`, () => {
const testCase = JSON.parse(JSON.stringify(testNS))
testCase.nt_group_id = gid
testCase.gid = gid

const { error, value } = schema.validate(testCase)

Expand All @@ -157,11 +157,11 @@ describe('nameserver', function () {
for (const gid of ['abc']) {
it(`rejects invalid: ${gid}`, () => {
const testCase = JSON.parse(JSON.stringify(testNS))
testCase.nt_group_id = gid
testCase.gid = gid

const { error, value } = schema.validate(testCase)

assert.strictEqual(error.message, '"nt_group_id" must be a number')
assert.strictEqual(error.message, '"gid" must be a number')
assert.deepEqual(value, testCase)
})
}
Expand Down
38 changes: 38 additions & 0 deletions lib/permission.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const Joi = require('joi')

exports.id = Joi.number().integer().min(1).max(4294967295)

exports.v3 = Joi.object({
name: Joi.string(),
self_write: Joi.boolean(),
group: Joi.object({
id: exports.id,
write: Joi.boolean(),
create: Joi.boolean(),
delete: Joi.boolean(),
}),
user: Joi.object({
id: exports.id,
write: Joi.boolean(),
create: Joi.boolean(),
delete: Joi.boolean(),
}),
nameserver: Joi.object({
usable: Joi.array().items(Joi.number().integer().positive()),
write: Joi.boolean(),
create: Joi.boolean(),
delete: Joi.boolean(),
}),
zone: Joi.object({
write: Joi.boolean(),
create: Joi.boolean(),
delete: Joi.boolean(),
delegate: Joi.boolean(),
}),
zone_record: Joi.object({
write: Joi.boolean(),
create: Joi.boolean(),
delete: Joi.boolean(),
delegate: Joi.boolean(),
}),
})
36 changes: 4 additions & 32 deletions lib/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,10 @@ exports.meta = Joi.object({
}).unknown(),
}).unknown()

exports.permission = Joi.object({
group: Joi.object({
write: Joi.boolean(),
create: Joi.boolean(),
delete: Joi.boolean(),
}),
user: Joi.object({
self_write: Joi.boolean(),
write: Joi.boolean(),
create: Joi.boolean(),
delete: Joi.boolean(),
}),
nameserver: Joi.object({
write: Joi.boolean(),
create: Joi.boolean(),
delete: Joi.boolean(),
}),
usable_ns: Joi.array().items(Joi.number().integer().positive()),
zone: Joi.object({
write: Joi.boolean(),
create: Joi.boolean(),
delete: Joi.boolean(),
delegate: Joi.boolean(),
}),
zone_record: Joi.object({
write: Joi.boolean(),
create: Joi.boolean(),
delete: Joi.boolean(),
delegate: Joi.boolean(),
}),
})
exports.int32 = Joi.number().integer().min(0).max(2147483647)

exports.uint32 = Joi.number().integer().min(0).max(4294967295)

// Clarifications to the DNS specification: http://tools.ietf.org/html/rfc2181
// valid TTL is unsigned number from 0 to 2147483647
exports.ttl = Joi.number().integer().greater(-1).max(2147483647)
exports.ttl = exports.int32
1 change: 1 addition & 0 deletions lib/shared.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('shared', function () {

const validErrs = [
'"value" must be greater than -1',
'"value" must be greater than or equal to 0',
'"value" must be a number',
'"value" must be less than or equal to 2147483647',
]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions test/fixtures/v3/zone.json → lib/test/zone.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": 1,
"gid": 1,
"zone": "example.com",
"ttl": 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": 1,
"zid": 1,
"name": "a",
"ttl": 86400,
Expand Down
6 changes: 4 additions & 2 deletions lib/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const JoiPassword = Joi.extend(joiPasswordExtendCore)

const shared = require('./shared')
const group = require('./group')
const permission = require('./permission')

exports.id = Joi.number().integer().min(1).max(4294967295)

Expand Down Expand Up @@ -33,13 +34,15 @@ exports.v3 = Joi.object({
password: exports.password,
is_admin: Joi.boolean(),
deleted: Joi.boolean(),
permission: permission.v3,
})

exports.GET = Joi.object({
user: exports.v3,
group: Joi.object({
id: group.id,
name: group.name,
permission: permission.v3,
}),
meta: shared.meta,
})
Expand All @@ -53,6 +56,7 @@ exports.POST = Joi.object({
email: exports.email,
password: exports.password,
is_admin: Joi.boolean(),
permission: permission.v3,
})

exports.v2 = Joi.object({
Expand All @@ -70,6 +74,4 @@ exports.v2 = Joi.object({

// nt_user_session: Joi.string(),
// last_access: Joi.string(),

// permission: shared.permission,
})
2 changes: 1 addition & 1 deletion lib/user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { describe, it } = require('node:test')
const schema = require('./user')

const userV2 = require('../test/fixtures/v2/user.json')
const userV3 = require('./test/user.json')

describe('user', function () {
describe('v2', function () {
Expand All @@ -16,7 +17,6 @@ describe('user', function () {
})

describe('v3', function () {
const userV3 = require('../test/fixtures/v3/user.json')
it('accepts valid', () => {
const testCase = JSON.parse(JSON.stringify(userV3))
const { error, value } = schema.v3.validate(testCase)
Expand Down
16 changes: 9 additions & 7 deletions lib/zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ const Joi = require('joi')

const shared = require('./shared')

exports.zone = Joi.object({
nt_group_id: Joi.number().integer().positive().required(),
exports.v3 = Joi.object({
id: shared.uint32,

gid: shared.uint32.required(),

zone: Joi.string()
.min(3)
Expand All @@ -15,17 +17,17 @@ exports.zone = Joi.object({

mailaddr: Joi.string().empty(''),

minimum: Joi.number().integer().greater(-1).max(2147483647).required(),
minimum: shared.int32.required(),

nameservers: Joi.array().items(Joi.string()),

refresh: Joi.number().integer().greater(-1).max(2147483647).required(),
refresh: shared.int32.required(),

retry: Joi.number().integer().greater(-1).max(2147483647).required(),
retry: shared.int32.required(),

expire: Joi.number().integer().greater(-1).max(2147483647).required(),
expire: shared.int32.required(),

serial: Joi.number().integer().greater(-1).max(2147483647).required(),
serial: shared.int32.required(),

ttl: shared.ttl.required(),

Expand Down
Loading

0 comments on commit a2849fd

Please sign in to comment.