2018-03-24 15:37:35 +00:00
|
|
|
const test = require('../testlib');
|
2018-03-24 13:48:49 +00:00
|
|
|
|
2018-03-24 15:37:35 +00:00
|
|
|
test.run(async function () {
|
|
|
|
await test('admin', async function (assert, req) {
|
2018-03-24 14:09:33 +00:00
|
|
|
//Test missing fields
|
|
|
|
var res = await req({
|
|
|
|
url: '/domains',
|
|
|
|
method: 'post',
|
|
|
|
data: {
|
|
|
|
name: 'abc.de'
|
|
|
|
}
|
|
|
|
});
|
2018-03-24 13:48:49 +00:00
|
|
|
|
2018-03-24 14:09:33 +00:00
|
|
|
assert.equal(res.status, 422, 'Missing type filed should trigger error.');
|
2018-03-24 13:48:49 +00:00
|
|
|
|
2018-03-24 14:09:33 +00:00
|
|
|
var res = await req({
|
|
|
|
url: '/domains',
|
|
|
|
method: 'post',
|
|
|
|
data: {
|
|
|
|
name: 'abc.de',
|
|
|
|
type: 'SLAVE'
|
|
|
|
}
|
|
|
|
});
|
2018-03-24 13:48:49 +00:00
|
|
|
|
2018-03-24 14:09:33 +00:00
|
|
|
assert.equal(res.status, 422, 'Missing master field for SLAVE domain should trigger error.');
|
2018-03-24 13:48:49 +00:00
|
|
|
|
2018-03-24 14:09:33 +00:00
|
|
|
var res = await req({
|
|
|
|
url: '/domains',
|
|
|
|
method: 'post',
|
|
|
|
data: {
|
|
|
|
name: 'foo.de',
|
|
|
|
type: 'MASTER'
|
|
|
|
}
|
|
|
|
});
|
2018-03-24 13:48:49 +00:00
|
|
|
|
2018-03-24 14:09:33 +00:00
|
|
|
assert.equal(res.status, 409, 'Existing domain should trigger error.');
|
2018-03-24 13:48:49 +00:00
|
|
|
|
2018-03-24 14:09:33 +00:00
|
|
|
//Test creation of master zone
|
|
|
|
var res = await req({
|
|
|
|
url: '/domains',
|
|
|
|
method: 'post',
|
|
|
|
data: {
|
|
|
|
name: 'master.de',
|
|
|
|
type: 'MASTER'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(res.status, 201, 'Creation should be successfull');
|
|
|
|
assert.equal(res.data, {
|
|
|
|
id: 6,
|
2018-03-24 13:48:49 +00:00
|
|
|
name: 'master.de',
|
|
|
|
type: 'MASTER'
|
2018-03-24 14:09:33 +00:00
|
|
|
}, 'Creation result fail.')
|
2018-03-24 13:48:49 +00:00
|
|
|
|
2018-03-24 14:09:33 +00:00
|
|
|
//Test creation of native zone
|
|
|
|
var res = await req({
|
|
|
|
url: '/domains',
|
|
|
|
method: 'post',
|
|
|
|
data: {
|
|
|
|
name: 'native.de',
|
|
|
|
type: 'NATIVE'
|
|
|
|
}
|
|
|
|
});
|
2018-03-24 13:48:49 +00:00
|
|
|
|
2018-03-24 14:09:33 +00:00
|
|
|
assert.equal(res.status, 201, 'Creation should be successfull');
|
|
|
|
assert.equal(res.data, {
|
|
|
|
id: 7,
|
2018-03-24 13:48:49 +00:00
|
|
|
name: 'native.de',
|
|
|
|
type: 'NATIVE'
|
2018-03-24 14:09:33 +00:00
|
|
|
}, 'Creation result fail.')
|
2018-03-24 13:48:49 +00:00
|
|
|
|
2018-03-24 14:09:33 +00:00
|
|
|
//Test creation of slave zone
|
|
|
|
var res = await req({
|
|
|
|
url: '/domains',
|
|
|
|
method: 'post',
|
|
|
|
data: {
|
|
|
|
name: 'slave.de',
|
|
|
|
type: 'SLAVE',
|
|
|
|
master: '1.2.3.4'
|
|
|
|
}
|
|
|
|
});
|
2018-03-24 13:48:49 +00:00
|
|
|
|
2018-03-24 14:09:33 +00:00
|
|
|
assert.equal(res.status, 201, 'Creation should be successfull');
|
|
|
|
assert.equal(res.data, {
|
|
|
|
id: 8,
|
2018-03-24 13:48:49 +00:00
|
|
|
name: 'slave.de',
|
2018-03-24 14:09:33 +00:00
|
|
|
type: 'SLAVE',
|
|
|
|
master: '1.2.3.4'
|
|
|
|
}, 'Creation result fail.')
|
2018-03-24 14:42:11 +00:00
|
|
|
|
2018-03-24 15:37:35 +00:00
|
|
|
//Get master domain
|
|
|
|
var res = await req({
|
|
|
|
url: '/domains/6',
|
|
|
|
method: 'get'
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(res.status, 200, 'Domain access for master domain should be OK.');
|
|
|
|
assert.equal(res.data, {
|
|
|
|
id: 6,
|
|
|
|
name: 'master.de',
|
|
|
|
type: 'MASTER',
|
|
|
|
records: 0
|
|
|
|
}, 'Master domain data mismatch');
|
|
|
|
|
|
|
|
//Get native domain
|
|
|
|
var res = await req({
|
|
|
|
url: '/domains/7',
|
|
|
|
method: 'get'
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(res.status, 200, 'Domain access for native domain should be OK.');
|
|
|
|
assert.equal(res.data, {
|
|
|
|
id: 7,
|
|
|
|
name: 'native.de',
|
|
|
|
type: 'NATIVE',
|
|
|
|
records: 0
|
|
|
|
}, 'Native domain data mismatch');
|
|
|
|
|
|
|
|
//Get slave domain
|
|
|
|
var res = await req({
|
|
|
|
url: '/domains/8',
|
|
|
|
method: 'get'
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(res.status, 200, 'Domain access for slave domain should be OK.');
|
|
|
|
assert.equal(res.data, {
|
|
|
|
id: 8,
|
|
|
|
name: 'slave.de',
|
|
|
|
type: 'SLAVE',
|
|
|
|
records: 0,
|
|
|
|
master: '1.2.3.4'
|
|
|
|
}, 'Slave domain data mismatch');
|
|
|
|
|
2018-03-24 20:05:38 +00:00
|
|
|
//Update slave domain
|
|
|
|
var res = await req({
|
|
|
|
url: '/domains/8',
|
|
|
|
method: 'put',
|
|
|
|
data: {
|
|
|
|
master: '9.8.7.6'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(res.status, 204, 'Slave update should return no content');
|
|
|
|
|
|
|
|
//Check if update succeded
|
|
|
|
var res = await req({
|
|
|
|
url: '/domains/8',
|
|
|
|
method: 'get'
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(res.status, 200, 'Slave domain should be accessible after update.');
|
|
|
|
assert.equal(res.data.master, '9.8.7.6', 'Slave update had no effect');
|
|
|
|
|
|
|
|
//Check if update fails for non existing domain
|
|
|
|
var res = await req({
|
|
|
|
url: '/domains/100',
|
|
|
|
method: 'put',
|
|
|
|
data: {
|
|
|
|
master: '9.8.7.6'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(res.status, 404, 'Update on not existing domain should fail.');
|
|
|
|
|
|
|
|
//Check if update fails for master zone
|
|
|
|
var res = await req({
|
|
|
|
url: '/domains/1',
|
|
|
|
method: 'put',
|
|
|
|
data: {
|
|
|
|
master: '9.8.7.6'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(res.status, 405, 'Update on master zone should fail.');
|
|
|
|
|
|
|
|
//Check if update fails for missing field
|
|
|
|
var res = await req({
|
|
|
|
url: '/domains/100',
|
|
|
|
method: 'put',
|
|
|
|
data: {
|
|
|
|
foo: 'bar'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(res.status, 422, 'Update with missing master field should fail.');
|
|
|
|
|
2018-03-24 14:42:11 +00:00
|
|
|
//Delete not existing domain
|
|
|
|
var res = await req({
|
|
|
|
url: '/domains/100',
|
|
|
|
method: 'delete'
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(res.status, 404, 'Non existing domain deletion should be 404.');
|
|
|
|
|
|
|
|
//Delete existing domain
|
|
|
|
var res = await req({
|
|
|
|
url: '/domains/1',
|
|
|
|
method: 'delete'
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(res.status, 204, 'Deletion of domain 1 should be successfull.');
|
2018-03-24 13:48:49 +00:00
|
|
|
});
|
|
|
|
|
2018-03-24 15:37:35 +00:00
|
|
|
await test('user', async function (assert, req) {
|
2018-03-24 14:42:11 +00:00
|
|
|
//Test insufficient privileges for add
|
2018-03-24 14:09:33 +00:00
|
|
|
var res = await req({
|
|
|
|
url: '/domains',
|
|
|
|
method: 'post',
|
|
|
|
data: {
|
|
|
|
name: 'foo.de'
|
|
|
|
}
|
|
|
|
});
|
2018-03-24 13:48:49 +00:00
|
|
|
|
2018-03-24 14:09:33 +00:00
|
|
|
assert.equal(res.status, 403, 'Domain creation should be forbidden for users.')
|
2018-03-24 14:42:11 +00:00
|
|
|
|
|
|
|
//Test insufficient privileges for delete
|
|
|
|
var res = await req({
|
|
|
|
url: '/domains/1',
|
|
|
|
method: 'delete'
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(res.status, 403, 'Domain deletion should be forbidden for users.');
|
2018-03-24 13:48:49 +00:00
|
|
|
|
2018-03-24 20:05:38 +00:00
|
|
|
//Test insufficient permissions
|
|
|
|
var res = await req({
|
|
|
|
url: '/domains/2',
|
|
|
|
method: 'put',
|
|
|
|
data: {
|
|
|
|
master: '9.8.7.6'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(res.status, 403, 'Update of slave zone should be forbidden for non admins.');
|
|
|
|
|
2018-03-24 15:37:35 +00:00
|
|
|
//Test insufficient privileges for get
|
|
|
|
var res = await req({
|
|
|
|
url: '/domains/3',
|
|
|
|
method: 'get'
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(res.status, 403, 'Domain get for domain 3 should be forbidden.');
|
|
|
|
|
|
|
|
//Test privileges for get
|
|
|
|
var res = await req({
|
|
|
|
url: '/domains/1',
|
|
|
|
method: 'get'
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(res.status, 200, 'Domain access for domain 1 should be OK.');
|
|
|
|
assert.equal(res.data, {
|
|
|
|
id: 1,
|
|
|
|
name: 'example.com',
|
|
|
|
type: 'MASTER',
|
2018-03-30 08:02:25 +00:00
|
|
|
records: 3
|
2018-03-24 15:37:35 +00:00
|
|
|
}, 'Domain 3 data mismatch');
|
|
|
|
});
|
|
|
|
});
|