added server tests
This commit is contained in:
parent
6181ea6463
commit
cdf45de8e2
8 changed files with 276 additions and 13 deletions
|
@ -153,9 +153,19 @@ app.post('/delete/:id', (req, res) => {
|
|||
|
||||
app.post('/upload', (req, res, next) => {
|
||||
const newId = crypto.randomBytes(5).toString('hex');
|
||||
const meta = JSON.parse(req.header('X-File-Metadata'));
|
||||
let meta;
|
||||
|
||||
try {
|
||||
meta = JSON.parse(req.header('X-File-Metadata'));
|
||||
} catch(err) {
|
||||
res.sendStatus(400);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!validateIV(meta.id)) {
|
||||
if (!validateIV(meta.id) ||
|
||||
!meta.hasOwnProperty('aad') ||
|
||||
!meta.hasOwnProperty('id') ||
|
||||
!meta.hasOwnProperty('filename')) {
|
||||
res.sendStatus(404);
|
||||
return;
|
||||
}
|
||||
|
@ -191,7 +201,7 @@ app.get('/__version__', (req, res) => {
|
|||
res.sendFile(path.join(STATIC_PATH, 'version.json'));
|
||||
});
|
||||
|
||||
app.listen(conf.listen_port, () => {
|
||||
const server = app.listen(conf.listen_port, () => {
|
||||
log.info('startServer:', `Portal app listening on port ${conf.listen_port}!`);
|
||||
});
|
||||
|
||||
|
@ -201,4 +211,9 @@ const validateID = route_id => {
|
|||
|
||||
const validateIV = route_id => {
|
||||
return route_id.match(/^[0-9a-fA-F]{24}$/) !== null;
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
server: server,
|
||||
storage: storage
|
||||
}
|
|
@ -31,6 +31,8 @@ if (conf.s3_bucket) {
|
|||
delete: awsDelete,
|
||||
forceDelete: awsForceDelete,
|
||||
ping: awsPing,
|
||||
flushall: flushall,
|
||||
quit: quit,
|
||||
metadata
|
||||
};
|
||||
} else {
|
||||
|
@ -45,10 +47,20 @@ if (conf.s3_bucket) {
|
|||
delete: localDelete,
|
||||
forceDelete: localForceDelete,
|
||||
ping: localPing,
|
||||
flushall: flushall,
|
||||
quit: quit,
|
||||
metadata
|
||||
};
|
||||
}
|
||||
|
||||
function flushall() {
|
||||
redis_client.flushdb();
|
||||
}
|
||||
|
||||
function quit() {
|
||||
redis_client.quit();
|
||||
}
|
||||
|
||||
function metadata(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
redis_client.hgetall(id, (err, reply) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue