mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 01:02:30 +01:00
set limit of 64 characters for lookup
This commit is contained in:
parent
f29bafe89a
commit
09ab1dabdf
2 changed files with 21 additions and 1 deletions
|
@ -5,7 +5,7 @@ import {Request, Response} from 'express';
|
|||
export async function getUserID(req: Request, res: Response) {
|
||||
let username = req.query.username as string;
|
||||
|
||||
if (username == undefined) {
|
||||
if (username == undefined || username.length > 64) {
|
||||
//invalid request
|
||||
res.sendStatus(400);
|
||||
return;
|
||||
|
|
|
@ -11,6 +11,7 @@ describe('getUserID', () => {
|
|||
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_03"), 'specific user 03']);
|
||||
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_04"), 'repeating']);
|
||||
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_05"), 'repeating']);
|
||||
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_06"), getHash("getuserid_user_06")]);
|
||||
});
|
||||
|
||||
it('Should be able to get a 200', (done: Done) => {
|
||||
|
@ -32,6 +33,25 @@ describe('getUserID', () => {
|
|||
.catch(err => done('couldn\'t call endpoint'));
|
||||
});
|
||||
|
||||
it('Should be able to get a 200 (username is public id)', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userID?username='+getHash("getuserid_user_06"))
|
||||
.then(async res => {
|
||||
const text = await res.text()
|
||||
if (res.status !== 200) done('non 200 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
})
|
||||
.catch(err => done('couldn\'t call endpoint'));
|
||||
});
|
||||
|
||||
it('Should be able to get a 400 (username longer than 64 chars)', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userID?username='+getHash("getuserid_user_06")+'0')
|
||||
.then(res => {
|
||||
if (res.status !== 400) done('non 400 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
})
|
||||
.catch(err => done('couldn\'t call endpoint'));
|
||||
});
|
||||
|
||||
it('Should be able to get single username', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userID?username=fuzzy+user+01')
|
||||
.then(async res => {
|
||||
|
|
Loading…
Reference in a new issue