Skip to content

Commit

Permalink
test: make test server stricter about incoming requests
Browse files Browse the repository at this point in the history
  • Loading branch information
m90 committed Oct 31, 2023
1 parent 9bfc58a commit b834ed1
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions seeder/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ http.createServer(function (req, res) {
switch (req.url) {
case '/markDone':
case '/markFailed':
res.writeHead(200);
res.end('1');
return;
if (req.method !== 'POST') {
return { status: 405, body: 'Method not allowed' };
}
return { status: 200, body: '1' };
case '/getBatches':
if (req.method !== 'GET') {
return { status: 405, body: 'Method not allowed' };
}
const numEntities = 20;
const entities = [];

Expand Down Expand Up @@ -44,17 +48,21 @@ http.createServer(function (req, res) {
},

};
res.writeHead(200, {'Content-Type': 'text/json'});
res.end(JSON.stringify([responseObject]));
return;
return {
status: 200,
headers: {'Content-Type': 'text/json'},
body: JSON.stringify([responseObject])
};
default:
res.writeHead(404);
res.end('Not found');
return { status: 404, body: 'Not found' };
}
})()
.catch((err) => {
console.error('Failed handling request: %s', err.message);
res.writeHead(500);
res.end(err.message);
return { status: 500, body: err.message };
})
.then((result) => {
res.writeHead(result.status, result.headers);
res.end(result.body)
})
}).listen(3030);

0 comments on commit b834ed1

Please sign in to comment.