add tests for specialized exceptions

This commit is contained in:
Timo Hocker 2020-03-13 20:08:38 +01:00
parent 167e26117a
commit 0d782e91c5
2 changed files with 31 additions and 3 deletions

View File

@ -27,9 +27,12 @@ async function start_server () {
return user;
return null;
}));
}, [
/noauthreg/u,
{ method: 'POST', regex: /noauthobj/u }
]));
app.get ('/', (req, res) => {
app.use ((req, res) => {
res.status (consts.http.status_ok)
.end ('foo');
});

View File

@ -29,10 +29,35 @@ test ('login', async (t) => {
const resp = await fetch ('http://localhost:3000', { headers: { session } });
t.is (await resp.status, consts.http.status_ok);
t.is (resp.status, consts.http.status_ok);
t.is (await resp.text (), 'foo');
});
test ('allow access to excluded paths', async (t) => {
const resp = await fetch ('http://localhost:3000/noauthreg');
t.is (resp.status, consts.http.status_ok);
t.is (await resp.text (), 'foo');
});
test ('allow access to excluded paths with correct method', async (t) => {
const resp = await fetch (
'http://localhost:3000/noauthobj',
{ method: 'POST' }
);
t.is (resp.status, consts.http.status_ok);
t.is (await resp.text (), 'foo');
});
test ('reject access to excluded paths with wrong method', async (t) => {
const resp = await fetch (
'http://localhost:3000/noauthobj'
);
t.is (resp.status, consts.http.status_unauthorized);
});
test ('reject invalid user', async (t) => {
await t.throwsAsync (client.login (
'foo',