Added 404 when adding credential for not existing domain
This commit is contained in:
parent
dcc0989d6d
commit
15ff44a86e
|
@ -79,6 +79,9 @@ class Credentials
|
||||||
} catch (\Exceptions\InvalidKeyException $e) {
|
} catch (\Exceptions\InvalidKeyException $e) {
|
||||||
$this->logger->debug('User tries to add invalid credential key.');
|
$this->logger->debug('User tries to add invalid credential key.');
|
||||||
return $res->withJson(['error' => 'The provided key is invalid.'], 400);
|
return $res->withJson(['error' => 'The provided key is invalid.'], 400);
|
||||||
|
} catch (\Exceptions\NotFoundException $e) {
|
||||||
|
$this->logger->debug('User tries to add credential for not existing record.');
|
||||||
|
return $res->withJson(['error' => 'The provided record does not exist.'], 404);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,6 +98,14 @@ class Credentials
|
||||||
|
|
||||||
$this->db->beginTransaction();
|
$this->db->beginTransaction();
|
||||||
|
|
||||||
|
$query = $this->db->prepare('SELECT id FROM records WHERE id=:recordId');
|
||||||
|
$query->bindValue(':recordId', $record, \PDO::PARAM_INT);
|
||||||
|
$query->execute();
|
||||||
|
if ($query->fetch() === false) {
|
||||||
|
$this->db->rollBack();
|
||||||
|
throw new \Exceptions\NotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
$query = $this->db->prepare('INSERT INTO remote (record, description, type, security) VALUES (:record, :description, :type, :security)');
|
$query = $this->db->prepare('INSERT INTO remote (record, description, type, security) VALUES (:record, :description, :type, :security)');
|
||||||
$query->bindValue(':record', $record, \PDO::PARAM_INT);
|
$query->bindValue(':record', $record, \PDO::PARAM_INT);
|
||||||
$query->bindValue(':description', $description, \PDO::PARAM_STR);
|
$query->bindValue(':description', $description, \PDO::PARAM_STR);
|
||||||
|
|
|
@ -62,6 +62,19 @@ test.run(async function () {
|
||||||
|
|
||||||
assert.equal(res.status, 400);
|
assert.equal(res.status, 400);
|
||||||
|
|
||||||
|
//Test invalid record
|
||||||
|
var res = await req({
|
||||||
|
url: '/records/100/credentials',
|
||||||
|
method: 'post',
|
||||||
|
data: {
|
||||||
|
description: 'Test',
|
||||||
|
type: 'password',
|
||||||
|
password: 'foo'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(res.status, 404, 'Not existent record should trigger error.');
|
||||||
|
|
||||||
//Add key (key is intensionally very short but valid) and get it
|
//Add key (key is intensionally very short but valid) and get it
|
||||||
var res = await req({
|
var res = await req({
|
||||||
url: '/records/1/credentials',
|
url: '/records/1/credentials',
|
||||||
|
|
Loading…
Reference in a new issue