Added validation for domain type
This commit is contained in:
parent
2f41db98e9
commit
3f78bc8ea6
|
@ -60,11 +60,6 @@ class Domains
|
|||
$type = $body['type'];
|
||||
$master = isset($body['master']) ? $body['master'] : null;
|
||||
|
||||
if (!in_array($type, ['MASTER', 'NATIVE', 'SLAVE'])) {
|
||||
$this->logger->info('Invalid type for new domain', ['type' => $type]);
|
||||
return $res->withJson(['error' => 'Invalid type allowed are MASTER, NATIVE and SLAVE'], 422);
|
||||
}
|
||||
|
||||
$domains = new \Operations\Domains($this->c);
|
||||
|
||||
try {
|
||||
|
@ -75,6 +70,9 @@ class Domains
|
|||
} catch (\Exceptions\AlreadyExistentException $e) {
|
||||
$this->logger->debug('Zone with name ' . $name . ' already exists.');
|
||||
return $res->withJson(['error' => 'Zone with name ' . $name . ' already exists.'], 409);
|
||||
} catch (\Exceptions\SemanticException $e) {
|
||||
$this->logger->info('Invalid type for new domain', ['type' => $type]);
|
||||
return $res->withJson(['error' => 'Invalid type allowed are MASTER, NATIVE and SLAVE'], 400);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -122,6 +122,10 @@ class Domains
|
|||
*/
|
||||
public function addDomain(string $name, string $type, ? string $master) : array
|
||||
{
|
||||
if (!in_array($type, ['MASTER', 'SLAVE', 'NATIVE'])) {
|
||||
throw new \Exceptions\SemanticException();
|
||||
}
|
||||
|
||||
$this->db->beginTransaction();
|
||||
|
||||
$query = $this->db->prepare('SELECT id FROM domains WHERE name=:name');
|
||||
|
|
|
@ -24,6 +24,17 @@ test.run(async function () {
|
|||
|
||||
assert.equal(res.status, 422, 'Missing master field for SLAVE domain should trigger error.');
|
||||
|
||||
var res = await req({
|
||||
url: '/domains',
|
||||
method: 'post',
|
||||
data: {
|
||||
name: 'abc.de',
|
||||
type: 'FOO'
|
||||
}
|
||||
});
|
||||
|
||||
assert.equal(res.status, 400, 'Invalid domain type should trigger error.');
|
||||
|
||||
var res = await req({
|
||||
url: '/domains',
|
||||
method: 'post',
|
||||
|
|
Loading…
Reference in a new issue