2018-03-24 13:48:49 +00:00
|
|
|
const cartesianProduct = require('cartesian-product');
|
|
|
|
|
2018-03-24 14:09:33 +00:00
|
|
|
(async function () {
|
|
|
|
await require('../testlib')('admin', async function (assert, req) {
|
|
|
|
//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
|
|
|
|
|
|
|
//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 14:09:33 +00:00
|
|
|
await require('../testlib')('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 14:09:33 +00:00
|
|
|
})();
|